
  $j(document).ready(function($j) {  

       $j(".selectrecherche").selectbox();

updateslide();
updateslidel();
       

       $j("ul.topnav li").mouseover(function() { //When trigger is clicked...		
                    //Following events are applied to the subnav itself (moving subnav up and down)
                    $j(this).find("ul.subnav").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click
                    $j(this).hover(function() {
                    }, function(){	
                            $j(this).find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
                    });
		});
                
       
        
        $j('.btn_learnMore').each(function(){   
                
                    $j(this).mouseover(function(){
                             $j(this).css('color','#000');
                             $j(this).stop().animate({backgroundPosition:"(0px -28px)"}, 1);                             
                    });
                    $j(this).mouseout(function(){	
                             $j(this).css('color','#FFF');
                             $j(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:1, complete:function(){$j(this).css({backgroundPosition: "0px 0px"})}});                             
                    });

            });    
        $j('#formboutonrecherche').mouseover(function(){
                             $j(this).css('color','#000');
                             $j(this).stop().animate({backgroundPosition:"(0px -28px)"}, 1);                             
                    });
       $j('#formboutonrecherche').mouseout(function(){	
                             $j(this).css('color','#FFF');
                             $j(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:1, complete:function(){$j(this).css({backgroundPosition: "0px 0px"})}});                             
        });
            
            
        var inc=0;    
        $j('.cc').each(function(){   
                var e= $j(this);
                inc++;
                if(inc<5){
                    $j(this).children('.boxcc_title').css('background-color','#ff7c00');                    
                    $j(this).children('.boxcc_prix').css('background-color','#ffa63d');                    
                    $j(this).children('.boxcc_showPrix').css('color','#f7be3d');  
                }else{
                    $j(this).children('.boxcc_title').css('background-color','#b50a81');           
                    $j(this).children('.boxcc_prix').css('background-color','#c146a4');
                    $j(this).children('.boxcc_showPrix').css('color','#ff8ccf'); 
                }
                
                
                 $j(this).mouseover(function(){
                             $j(this).children('.boxcc_title').stop().animate({
                                    top: "100px"                                    
                                  }, 300 );
                             $j(this).children('.boxcc_showPrix').stop().animate({
                                    top: "130px"                                    
                                  }, 300 );
                             $j(this).children('.boxcc_shadowPrix').find("img").stop().animate({
                                   height: '7px',                                
                                   width: '105px',
                                   marginLeft: '5px',
                                   marginTop: '15px',
                                   opacity:0.5
                                  }, 300,  function() {
                                        e.find(".boxcc_showPrix").animate({top: "138px"}, 150);
                                    });
                });
                
                
                $j(this).mouseout(function(){
                             $j(this).children('.boxcc_title').stop().animate({
                                    top: "120px"                                    
                                  }, 150); 
                                  
                              $j(this).children('.boxcc_showPrix').stop().animate({
                                    top: "135px"                                    
                                  }, 300 );
                             $j(this).children('.boxcc_shadowPrix').find("img").stop().animate({
                                   height: '25px',                                
                                   width: '120px',
                                   marginLeft: '0px',
                                   marginTop: '0px',
                                   opacity:0.5
                                  }, 150,  function() {
                                        e.find(".boxcc_showPrix").animate({top: "148px"}, 150);
                                    });    
                });
                   

            });        
  });


function format(x,type) {
    if (x==0) {
        return x;
     } else {
        var str = x.toString(), n = str.length;
        if (n <4) {
            return x;
        } else {
            return ((n % 3) ? str.substr(0, n % 3) + ' ' : '') + str.substr(n % 3).match(new RegExp('[0-9]{3}', 'g')).join(' ');
        }
    }
}

function updateslide(){
    var lefter= parseInt($j('#handleprix-1').css('left'));
    var righter= parseInt($j('#handleprix-2').css('left'));
    var lengther = righter-lefter+7;
     $j('#motif_slider').css('left',lefter);        
     $j('#motif_slider').css('width',lengther);        
}
function updateslidel(){    
    var lefter= parseInt($j('#handleprix-1l').css('left'));
    var righter= parseInt($j('#handleprix-2l').css('left'));
    var lengther = righter-lefter+7;
     $j('#motif_sliderl').css('left',lefter);        
     $j('#motif_sliderl').css('width',lengther); 
     
}

function swaptoloc(){   
    $j('#od_group_offredem_separe').val('2');
    $j('#idslider_location').css('display','block');        
    $j('#moteurLocation').css('display','block');        
    $j('#idslider_vente').css('display','none');        
    $j('#moteurVente').css('display','none');  
    
}
function swaptovente(){
    $j('#od_group_offredem_separe').val('0');
    $j('#idslider_location').css('display','none');     
    $j('#moteurLocation').css('display','none');
    $j('#idslider_vente').css('display','block');  
    $j('#moteurVente').css('display','block');  
}

			function addLoadEvent(func) {
				var oldonload = window.onload;
				if (typeof window.onload != 'function') {
					window.onload = func;
				} else {
					window.onload = function() {
						if (oldonload) {
							oldonload();
						}
						func();
					}
				}
			}
var idcoupscoeur = 1;
var flagCoupsCoeur = true;
var COUPSCOEUR_NB_IMAGES = 8;
var COUPSCOEUR_NB_IMAGES = 8;
var BASEHREF = 'http://www.cabinetbourgeois.fr/';

			
			
			
			function myupdaterv2(){
				a = new PeriodicalExecuter(function(){
					if(flagCoupsCoeur) {				
						if(idcoupscoeur > COUPSCOEUR_NB_IMAGES) {
							if( idcoupscoeur > COUPSCOEUR_NB_IMAGES + 1 ) {
								idcoupscoeur = 0;
							}
						} else {
							updatemyannv2(idcoupscoeur);		
						}
						idcoupscoeur++;
					}
				},1);
			}

			function updatemyannv2(id){
				flagCoupsCoeur = false;
				// récupérer le input caché (extypcc1)
				if($('annt'+id)){
					var typ = $('annt'+id).value;					
				} else {
					var typ = '*';
				}
				//on remplace par notre loader
				var exc = new Array();
				if($('annc1') != null ) exc[0] = $('annc1').value; else return true;
				var i;
				for(i=2; i<= COUPSCOEUR_NB_IMAGES; i++) {
					if($('annc'+i)) {
						exc[i-1] = $('annc'+i).value;
					}
				}

				if($("coeur"+id)) {

					var url = BASEHREF + '/xmlrpcnet.php';
					var target	= 'coeur'+id;
					var pars =	'mode=random_ann&num='+id+'&exc='+exc+'&typ='+typ;

					var myAjax	= new Ajax.Request(url, {
						method: 'get',
						parameters: pars,
						onComplete: function(t){
							flagCoupsCoeur = true;
							var len = t.responseText.length;
							if(t.responseText.substr(len - 4,4 )!= "none") {
								$(target).innerHTML = t.responseText;
								new Effect.Opacity($("coeur"+id), { from: 0.5, to: 0 });
								new Effect.Opacity($("coeur"+id), { from: 0, to: 1 });
                                                                updateCC(id);
							}
						}
					});
				} else {
					flagCoupsCoeur = true;
				}
			}
			
		

 addLoadEvent(function(){ if($('corps_coeur')){ myupdater(); }
if($('corps_coeurv2')){ myupdaterv2(); }
 });
 
 
     function updateCC(id){
          var inc=0;    
          $j('.cc').each(function(){   
            var e= $j(this);
            inc++;
            if(inc<5){
                $j(this).children('.boxcc_title').css('background-color','#ff7c00');                    
                $j(this).children('.boxcc_prix').css('background-color','#ffa63d');                    
                $j(this).children('.boxcc_showPrix').css('color','#f7be3d');  
            }else{
                $j(this).children('.boxcc_title').css('background-color','#b50a81');           
                $j(this).children('.boxcc_prix').css('background-color','#c146a4');
                $j(this).children('.boxcc_showPrix').css('color','#ff8ccf'); 
            }
        });

    }
