function a2fav(title, url){
if(title==undefined) title="DzDeal Community";
if(url==undefined) url="http://www.dzdeal.com";
if(window.sidebar){
	window.sidebar.addPanel(title, url,"");
}else if(window.external){
	window.external.AddFavorite( url, title); 
	}
else if(window.opera && window.print){
	return true;
	}
}
function $$$(el){return document.getElementById(el);}
function sid(){return '&'+new Date().getTime();}
function v(el){return $$$(el).value;}
function oo(el){$$$(el).style.display='block';return;}
function toggle(el){if($$$(el).style.display=='none')$$$(el).style.display='block';else $$$(el).style.display='none';}
function c(el){$$$(el).style.display='none';return;}
function lgo(){tb_show("D&eacute;connexion","http://www.dzdeal.com/inc/engine.php?loggout=1&width=400&height=150",null);}
function advanced_s(){tb_show("Recherche approfondie","http://www.dzdeal.com/search/index.php?search=1&width=400&height=380",null);}
function within(el,txt,ca,keep_overlay_closed){
	if(!el)el='working_division';
	oo(el);
	$$$(el).innerHTML=txt;
	if(!keep_overlay_closed)
	oo('overlay');
	if(ca){setTimeout("c('"+el+"');c('overlay')",ca);}
}


function nomination_det(iad, title, immo){
	if(immo==true)
	var dire='nomination_details';
	else
	var dire='details';
	popup('../'+dire+'/index.php?id='+iad, title);
}

function Exchange(i){if(i==undefined) i=0; return popup('http://www.dzdeal.com/exchange/?exchange='+i);}
function popup(url,title,w,h){
	if(title==undefined) title='&nbsp;';
	w=900;
	h=500;
	jQuery(function(){
	setTimeout(function(){tb_show(title, url+"&TB_iframe=true&width="+w+"&height="+h+"", null);}, 10);
	});
}

//BOTH
function gnl(s,ss,tt){
	var u='http://www.dzdeal.com/search_gate/index.php?advancedsearch=1&s='+s+'&ss='+ss+'&tt='+tt;
	$("#TopLeft").html('<div id="lll">Chargement en cours</div>');
	$.post(u, function(data){
			$("#TopLeft").html(data);
			return;
 	});
}
function addslashes(s){
    return(s+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}

function SS(fsf){
	var sec;
	(fsf==true) ? sec='2' : sec='';
	var d=addslashes(v('ss_keyword'+sec));
	var cat=v('qw'+sec);
	var str = "d="+d+"&s_in=*&w=*&a=*&o=*&cat="+cat+"&sub_cat=*&pa=*&pb=*&dh=*&ord_by=entry_date:desc&rpp=6&om=*";
	Searching(str, false);
}

function Searching(u,rapidos){
	if(rapidos==true){
		var u='http://www.dzdeal.com/search_gate/index.php?advancedsearch=r&'+u;
		$("#rr").html('<img src="http://www.dzdeal.com/images/loader.gif"/> Verification');
		$.post(u, function(data){
			if(data=='ERROR_STRING_INVALID'){
			$("#rr").html('<span style="color:#FF0000;">Term invalid!</span>');
			Al('designation',true);
			return;
			}
			$("#rr").html(data);
			return;
 	});
	return;
	}
	var container='TopLeft';
	$("#"+container).html('<div id="lll">Recherche en cours</div>');
	var u='http://www.dzdeal.com/search_gate/index.php?advancedsearch=1&'+u;
	$.post(u, function(data){
			$("#"+container).html(data);
			return;
 	});
}

function l5d(){
	var u='../Accueil/?l5d=1&sid='+sid();
	$$$('l5d').innerHTML='<img src="../images/ajax.gif" style="margin-left:55px;margin-top:0px;"/>';
	$.post(u, function(data){
			$$$('l5d').innerHTML=data;
			return;
 	});
}

function uo(){
	
}
function Fav(did){
	var u='http://www.dzdeal.com/inc/engine.php?fav='+did;
	var spn='favBtn'+did;
	$$$(spn).innerHTML='<img src="http://www.dzdeal.com/images/loader.gif" style="margin:0 30px;"/>';
	$.post(u, function(data){
		$$$(spn).innerHTML=data;
	});
}
function modifydeal(deal){
	location.href='../existing/?d='+deal;
}

function getdealsof(dealer){
	var u='http://www.dzdeal.com/his_ads/?d='+dealer;
	scr(100);
	var container='TopLeft';
	$("#"+container).html('<div id="lll">Chargement en cours...</div>');
	$.post(u, function(data){
			$("#"+container).html(data);
			return;
 	});
}

function getItems(sub_cat){
	var trade=v('marque');
	var u='../new/?getItems='+sub_cat+'&trade='+trade+'&sid='+sid();
	$$$("model_holder").innerHTML='<img src="../images/loader_.gif"/>';
	$.post(u, function(data){
			$$$("model_holder").innerHTML=data;
			return;
 	});
}

function wst(Y){window.scrollTo(0, Y);}

function reCaptcha(){$$$('captchaFrame').src='../inc/Captcha.php';}

function gv(region,prin,custom_id){
	if(!custom_id) custom_id='ville';
	if(region=='NONE') return;
	if(region=='ALL') return c(prin);
	var u='http://www.dzdeal.com/Accueil/index.php?gv='+region+'&custom_id='+custom_id+'&sid='+sid();
	$("#"+prin).html('<div id="lll" style="padding:0;padding-left:22px;width:150px;margin:0;">Patientez svp</div>');
	$.post(u, function(data){
		$("#"+prin).html(data);
		return;
 	});
}



function numbersonly(e,ch) {
if(ch==undefined) H='price_error'; else H=ch;
var unicode=e.charCode? e.charCode : e.keyCode;
if(unicode!=8){
	if(unicode<48 || unicode>57){
	within(H,'Uniquement des chiffres svp.',3000,true);
	return false;
	}
	else{
	c(H);
	$$$(H).innerHTML='&nbsp;';
	return true;
	
	}
}
}


function Al(i,BLNK,MSG){
	st(i).background='red';
	if(MSG==undefined)MSG='';
	if(BLNK) setTimeout("Blink('"+i+"','"+MSG+"')",150);
}

function Blink(el, m){
	if(m)alert(m);
	try{
		var C=100;
		var N_TOUT;
		var bgcol='red';
		var fcol='white';
		for(var I=1; I<8; I++){
		N_TOUT = I * C;
		if(bgcol=='red') {
			bgcol='white';
			fcol='red';
		}else{
			bgcol='red';
			fcol='white';
		}
		setTimeout("st('"+el+"').background='"+bgcol+"';st('"+el+"').color='"+fcol+"'",N_TOUT);
		if(I==7) setTimeout("st('"+el+"').color='gray'",N_TOUT+100);
		}
	}catch(e){}
}

function s_of(i,w,s){(w==true) ? w=false : w=true; $(i).disabled=w; if(w==true && !s)t_l(i); else t_l(i,s);}
function t_l(i,s){try{if(!s)$(i).options[0].selected=true; else $(i).options[s].selected=true;}catch(e){}}
function st(elem){return $$$(elem).style;}

jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

(function($) {
  $.fn.ContentSlider = function(options)
  {
    var defaults = {
      leftBtn : 'http://www.dzdeal.com/images/featured/h-3.gif',
      rightBtn : 'http://www.dzdeal.com/images/featured/h-4.gif',
      width : '500px',
      height : '250px',
      speed : 500,
      easing : 'easeOutQuad',
      textResize : false,
      IE_h2 : '26px',
      IE_p : '12px'
    }
    var defaultWidth = defaults.width;
    var o = $.extend(defaults, options);
    var w = parseInt(o.width);
    var n = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').length;
    var x = -1*w*n+w; // Minimum left value
    var p = parseInt(o.width)/parseInt(defaultWidth);
    var thisInstance = this.attr('id');
    var inuse = false; // Prevents colliding animations

    function moveSlider(d, b)
    {
      var l = parseInt(b.siblings('.cs_wrapper').children('.cs_slider').css('left'));
      if(isNaN(l)) {
        var l = 0;
      }
      var m = (d=='left') ? l-w : l+w;
      if(m<=0&&m>=x) {
        b
          .siblings('.cs_wrapper')
            .children('.cs_slider')
              .animate({ 'left':m+'px' }, o.speed, o.easing, function() {
                inuse=false;
              });

        if(b.attr('class')=='cs_leftBtn') {
          var thisBtn = $('#'+thisInstance+' .cs_leftBtn');
          var otherBtn = $('#'+thisInstance+' .cs_rightBtn');
        } else {
          var thisBtn = $('#'+thisInstance+' .cs_rightBtn');
          var otherBtn = $('#'+thisInstance+' .cs_leftBtn');
        }
        if(m==0||m==x) {
          thisBtn.animate({ 'opacity':'0' }, o.speed, o.easing, function() { thisBtn.hide(); });
        }
        if(otherBtn.css('opacity')=='0') {
          otherBtn.show().animate({ 'opacity':'1' }, { duration:o.speed, easing:o.easing });
        }
      }
    }

    function vCenterBtns(b)
    {
      // Safari and IE don't seem to like the CSS used to vertically center
      // the buttons, so we'll force it with this function
      var mid = parseInt(o.height)/2 - 10;
      b.find('.cs_leftBtn img').css({ 'top':mid+'px', 'padding':0 }).end()
       .find('.cs_rightBtn img').css({ 'top':mid+'px', 'padding':0 });
	   
	  b.find('.cs_leftBtn img').css({ 'left':'3px', 'padding':0 }).end()
       .find('.cs_rightBtn img').css({ 'left':'3px', 'padding':0 });
    }

    return this.each(function() {
      $(this)
        // Set the width and height of the div to the defined size
        .css({
          width:o.width,
          height:o.height
        })
        // Add the buttons to move left and right
        .prepend('<a href="#" class="cs_leftBtn"><img src="'+o.leftBtn+'" /></a>')
        .append('<a href="#" class="cs_rightBtn"><img src="'+o.rightBtn+'" /></a>')
        // Dig down to the article div elements
        .find('.cs_article')
          // Set the width and height of the div to the defined size
          .css({
            width:o.width,
            height:o.height
          })
          .end()
        // Animate the entrance of the buttons
        .find('.cs_leftBtn')
          .css('opacity','0')
          .hide()
          .end()
        .find('.cs_rightBtn')
          .hide()
          .animate({ 'width':'show' });

      // Resize the font to match the bounding box
      if(o.textResize===true) {
        var h2FontSize = $(this).find('h2').css('font-size');
        var pFontSize = $(this).find('p').css('font-size');
        $.each(jQuery.browser, function(i) {
          if($.browser.msie) {
             h2FontSize = o.IE_h2;
             pFontSize = o.IE_p;
          }
        });
        $(this).find('h2').css({ 'font-size' : parseFloat(h2FontSize)*p+'px', 'margin-left' : '125px' });
        $(this).find('p').css({ 'font-size' : '11px', 'margin-left' : '125px' });
        $(this).find('.readmore').css({ 'font-size' : '12px', 'margin-left' : '105px' });
      }

      // Store a copy of the button in a variable to pass to moveSlider()
      var leftBtn = $(this).children('.cs_leftBtn');
      leftBtn.bind('click', function() {
        if(inuse===false) {
          inuse = true;
          moveSlider('right', leftBtn);
        }
        return false; // Keep the link from firing
      });

      // Store a copy of the button in a variable to pass to moveSlider()
      var rightBtn = $(this).children('.cs_rightBtn');
      rightBtn.bind('click', function() {
        if(inuse===false) {
          inuse=true;
          moveSlider('left', rightBtn);
        }
        return false; // Keep the link from firing
      });

      vCenterBtns($(this)); // This is a CSS fix function.
    });
  }
})(jQuery)