/*JS*/
$(document).ready(function() {		
	
	$('#header ul ul').parent('li').addClass('hasSubMenu');
	
	if($('#sliderHome').length) {
		 $('#sliderHome').jcarousel({
			auto: 5,   
			scroll : 1,	
			visible: 1,
			animation: 500,
			//easing: 'easeOutQuart',
			wrap : "last" ,
			initCallback: sliderHome_initCallback ,
			itemFirstOutCallback: {onBeforeAnimation: autoHighlight } ,
			 // This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
		});
	}


	/*only functions for IE 6*/
		if ($.browser.msie && $.browser.version <= 6 ) {
				try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {} //caching CSS images			
				navIE();
				
				if($('#wrapper.wrap_trouverAgences').length) {
					rollMap();
				}
				
			}		
	/*end IE6*/	

});


function autoHighlight(index) {
	//alert(index);
	$currentIndex = $('#sliderHome_controls li.active');
		
	if($currentIndex.next('li').length) {
		$currentIndex.removeClass('active').next('li').addClass('active');
	} else {
		$currentIndex.removeClass('active');
		$('#sliderHome_controls li').eq(0).addClass('active');
	}		
}

function sliderHome_initCallback(carousel) {
	$('#sliderHome_controls li').eq(0).addClass('active');
	
	$('#sliderHome_controls li').bind('click', function() {
		var sliderNum = $(this).attr('id').split('goTo_');
		carousel.scroll(jQuery.jcarousel.intval(sliderNum[1]));
		
		$('#sliderHome_controls li').removeClass('active');
		$(this).addClass('active');		
      });  
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
	$('#sliderHome_controls').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
	
};

jQuery.easing['easeOutQuart'] =  function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	};

function navIE() {
	$('#header > ul > li').hover(function() {
		$(this).attr('id','hoverIE');
	},function() {
		$(this).removeAttr('id','hoverIE');
	});
	
}

function rollMap() {
	$('#sidebar li, .wrap_trouverAgences li').hover(function() {
		$(this).addClass('rollMap');
	}, function() {
		$(this).removeClass('rollMap');
	});
}





