//********************************************************************
//
//								MENU TOP
//
//********************************************************************

function initMenuTop()
{
	//corner
	//	$('.sousMenu').corner();
	
	var config = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: move, // function = onMouseOver callback (REQUIRED)    
		//timeout: 100,//  number = milliseconds delay before onMouseOut    
		 out:onMouseOutHNav // function = onMouseOut callback (REQUIRED)    
	};

	$("li.mainMenu").hoverIntent(config);
	
	function move()
	{
		//$(this).children('.sousMenu').slideDown("fast");
		$(this).animate({"top": "15px"}, "fast", "easeOutQuad",function(){
														   
			$(this).children('.sousMenu').slideDown("normal");
													   
		});
		
		$(this).children('a').eq(0).addClass("actif");
	
	}
	
	function onMouseOutHNav()
	{
		$(this).animate({"top": "0"}, "fast","easeOutQuad",function(){
													  
			$(this).children('.sousMenu').slideUp("fast",function(){
				$(this).parent().children('a').eq(0).removeClass("actif");												  
			});	
											  
		});	
	}
}


//********************************************************************
//
//								MENU MAIN
//
//********************************************************************

function initMenuMain()
{
	$("ul.sf-menu").supersubs({ 
		minWidth:    12,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
						   // due to slight rounding differences and font-family 
	}).superfish({
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: false,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}						  
	}); 	
	
	
	// fleches
	$("ul.sf-menu li li").each(function(index, domEle){
		if($(domEle).children("ul").length==1) $(this).children("a").addClass("fleche");		
	});
	
	// delete border-bottom on last li
	$("ul.sf-menu li:last-child a").css("border","none");	
	
	//
	$("ul.sf-menu li li ul").hover(
								   
		function(){
			$(this).parent().addClass('actif');
		},
		function(){
			$(this).parent().removeClass('actif');
		}
		
	);
	
}


//********************************************************************
//
//								CARROUSEL
//
//********************************************************************

directAccess = false;


function initCarrousel()
{

	currentSlide = 0;
	// redefine Cycle's updateActivePagerLink function
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
		$(pager).find('li').removeClass('activeLI')
			.filter('li:eq('+currSlideIndex+')').addClass('activeLI');
	};



	$('#pics').cycle
	(
		{
			timeout: 5000,
			pager:  '#slideNav',
			pagerAnchorBuilder: function(idx, slide)
				{
				return '<li><a href="#"><img src="' + slide.src + '" width="113" height="74" /></a></li>';
				},
			startingSlide: 0,
			before:onBefore,
			after:onAfter,
			pagerClick:onClick,
			pause:        1,
   			pauseOnPagerHover: 1
		}
	);

	$('#pages a').click(function(){

		var idPage =  $("#pages a").index(this);
		//console.info("idPage : " + idPage);
		slideNav(idPage);
		return false;
	});

	$("#infos").hover(
		function(){$('#pics').cycle('pause');},
		function(){$('#pics').cycle('resume'); }
	);

}

function slideNav(idPage)
{
	//slide
	$('#slideNav').animate({top: -idPage*279}, 1000,"easeOutBack");

	//color
	$('#pages a').removeClass('actif');
	$('#pages a').eq(idPage).addClass("actif");
}

function onClick(index)
{
	directAccess = true;

	//console.info("onClick : " + index);

	if(index != currentSlide)
	{
		currentSlide = index;

		if(index < 3) slideNav(0);
		else if(index < 6) slideNav(1);
		else if(index < 9) slideNav(2);

		closeInfo(index);
	}
}


function onBefore(curr, next, opts) {


	if(!directAccess)
	{
		var index = opts.currSlide;
		//console.info("currSlide : " + index);

		/*if(index < 2) slideNav(0);
		else if(index < 5) slideNav(1);
		else if(index < 8) slideNav(2);
		else slideNav(0);*/

		closeInfo(index);
	}

	directAccess = false;
}

function onAfter(curr, next, opts) {
    var index = opts.currSlide;
	currentSlide = index;
	openInfo(index);
	if(index <= 2) slideNav(0);
	else if(index <= 5) slideNav(1);
	else if(index <= 8) slideNav(2);
	else slideNav(0);
}

function closeInfo(index)
{
	$('#infos').animate({bottom:-100}, 500,"easeOutQuart");
}

function openInfo(index)
{
	var content = $("#slideshow_infos .info").eq(index).html();
	//console.info("content : " + content);

	$('#infos').html(content);
	$('#infos').animate({bottom:0}, 500,"easeOutQuart");
}



//********************************************************************
//
//								ENGAGEMENTS
//
//********************************************************************
function initSlider()
{
	posX=0;
	nbActus = $(".item").length-1;
	$("#sliderPrev").hide();
		
	//btn nextWorks
	$("#sliderNext").click(function()
	{
		if(posX>(-nbActus))
		{
			posX--;
			slide(posX);
		}
		
		return false;
	});
	
	$("#sliderPrev").click(function()
	{
		if(posX<0)
		{
			posX++;
			slide(posX);
		}
		
		return false;
	});
	
}

function slide(posX)
{
		
	var itemWidth = $(".item").width()
	
	//slide
	$("#slider").animate({left: posX*itemWidth}, 1000,"easeOutQuart");
	
	//check limits
	if(posX==(-nbActus))
	{
		$("#sliderNext").hide("normal");
	}
	else if(posX==0)
	{
		$("#sliderPrev").hide("normal");
	}
	else
	{
		$("#sliderPrev").show("normal");
		$("#sliderNext").show("normal");
	}
			
}
