// JavaScript Document

stepcarousel.setup({
	galleryid: 'mygallery', //id of carousel DIV
	beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
	panelclass: 'panel', //class of panel DIVs each holding content
	autostep: {enable: true, moveby:1, pause:5000},
	panelbehavior: {speed:500, wraparound:true, persist:false},
	defaultbuttons: {enable: false, moveby: 1, leftnav: ['styles/flechegauche.png', -30, 50], rightnav: ['styles/flechedroite.png', 5, 50]},
	statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
	contenttype: ['inline'] //content setting ['inline'] or ['external', 'path_to_external_file']
});

function ajaxLoading(page)
{

	$("#ajaxLoadingProgress").remove();
	$("body").append('<div id="ajaxLoadingProgress" style="display:none;"><span></span></div>');
	$("#ajaxLoadingProgress").show();
	switch(page)
	{
		default:
		case "home":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"home",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "overview":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"overview",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "skills":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"skills",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "working":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"working",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").hide().remove();
						});
					});
				});
			break;
		case "qualities":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"qualities",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "team":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"team",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "news":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"news",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "cnje":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"cnje",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
		case "students":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"students",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
		case "portfolio":
			$("#content").slideUp("slow",function(){
				$("#content").load("index.php",{page:"portfolio",xml:1}, function(){ 
					$("#content").slideDown("slow",function(){$("#ajaxLoadingProgress").fadeOut("slow").remove();
						});
					});
				});
			break;
	}
}

function historyCallback(hash)
{
    // do stuff that loads page content based on hash variable
}

function clearText(thefield)
{
	if (thefield.defaultValue==thefield.value)
	thefield.value = "";
}

function resetText(thefield)
{
	if (thefield.value=="")
	thefield.value = thefield.defaultValue
}

$(document).ready(function() {
	
    $.history.init(historyCallback);
    $("a[@rel='history']").click(function(){
        $.history.load(this.href.replace(/^.*#/, ''));
        return false;
    });
        
	$(".panel")
	.hover(function(){
		$(this).find(".overlay").css("display","block");
	},function(){
		$(this).find(".overlay").css("display","none");
	});
	
	
	$("#login").hoverIntent({sensitivity: 3, interval: 200, over: function(){$("#login").animate({top: 0},"normal")}, timeout: 500, out: function(){$("#login").animate({top: -26},"normal");}});
	
	
	$("#menuMarketingDescript").hide();

	$("#menuHome a")
	.animate({ opacity: 0.35},{ queue:false, duration:"medium" })
	//.fancybox({ 'frameWidth':300, 'frameHeight':200, 'zoomSpeedIn': 0, 'zoomSpeedOut': 0, 'overlayShow': true })
	.click(function(){ ajaxLoading("home"); return false;})
	.hover(function(){
		$(this).animate({ opacity: 1},{ duration:"medium" });
		$("#menuMarketingDescript").html("Retourner à l'accueil...").fadeIn("normal");
	},function(){
		$(this).animate({ opacity: 0.35},{ duration:"fast" });
		$("#menuMarketingDescript").html("").hide();
	});
	
	$("#menuOffre a")
	.animate({ opacity: 0.35},{ queue:false, duration:"medium" })
	//.fancybox({ 'frameWidth':300, 'frameHeight':200, 'zoomSpeedIn': 0, 'zoomSpeedOut': 0, 'overlayShow': true })
	.hover(function(){
		$(this).animate({ opacity: 1},{ duration:"medium" });
		$("#menuMarketingDescript").html("Déposer un appel d'offre...").fadeIn("normal");
	},function(){
		$(this).animate({ opacity: 0.35},{ duration:"fast" });
		$("#menuMarketingDescript").html("").hide();
	});
	$("#menuPlaquette a")
	.animate({ opacity: 0.35},{ queue:false, duration:"medium" })
	.hover(function(){
		$(this).animate({ opacity: 1},{duration:"medium" });
		$("#menuMarketingDescript").html("Télécharger notre plaquette...").fadeIn("normal");
	},function(){
		$(this).animate({ opacity: 0.35},{duration:"fast" });
		$("#menuMarketingDescript").html("").hide();
	});
	
	$("#menuPortfolio a")
	.animate({ opacity: 0.35},{ queue:false, duration:"medium" })
	.hover(function(){
		$(this).animate({ opacity: 1},{duration:"medium" });
		$("#menuMarketingDescript").html("Voir nos réalisation...").fadeIn("normal");
	},function(){
		$(this).animate({ opacity: 0.35},{duration:"fast" });
		$("#menuMarketingDescript").html("").hide();
	});

	
   		var TmenuFadeIn=false;
		var TmenuFadeOut=false;
	$('#menuListe a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			if(TmenuFadeIn==false)
			{
				TmenuFadeOut=false;
				TmenuFadeIn=true;
				$(this).animate({backgroundPosition:"(0 -45px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -45px)"}, {duration:25});
				$(this).animate({backgroundPosition:"(0 -90px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -90px)"}, {duration:25});
				$(this).animate({backgroundPosition:"(0 -135px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -135px)"}, {duration:25});
				$(this).animate({backgroundPosition:"(0 -180px)"}, {duration:1});
			}
		})
		.mouseout(function(){
			if(TmenuFadeOut==false)
			{
				TmenuFadeIn=false;
				TmenuFadeOut=true;
				$(this).animate({backgroundPosition:"(0 -135px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -135px)"}, {duration:25});
				$(this).animate({backgroundPosition:"(0 -90px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -90px)"}, {duration:25});		
				$(this).animate({backgroundPosition:"(0 -45px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -45px)"}, {duration:25});
				$(this).animate({backgroundPosition:"(0 0px)"}, {duration:1});
			}
		});
   	
		var TmenubisFadeIn=false;
		var TmenubisFadeOut=false;
	$('#menuListeBis a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			if(TmenubisFadeIn==false)
			{
				TmenubisFadeOut=false;
				TmenubisFadeIn=true;
				$(this).animate({backgroundPosition:"(0 -23px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -23px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -46px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -46px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -69px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -69px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -92px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -92px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -115px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -115px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -138px)"}, {duration:1});
			}
		})
		.mouseout(function(){
			if(TmenubisFadeOut==false)
			{
				TmenubisFadeIn=false;
				TmenubisFadeOut=true;
				$(this).animate({backgroundPosition:"(0 -115px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -115px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -92px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -92px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -69px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -69px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -46px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -46px)"}, {duration:15});		
				$(this).animate({backgroundPosition:"(0 -23px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -23px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 0px)"}, {duration:1});
			}
		})
		
	$("#menuLogo").click(function(){ ajaxLoading("home"); return false;});
		
	$("#menuPresentation>a").click(function(){ ajaxLoading("overview"); return false;});
	$("#menuCompetences>a").click(function(){ ajaxLoading("skills"); return false;});
	$("#menuFonctionnement>a").click(function(){ ajaxLoading("working"); return false;});
	$("#menuQualites>a").click(function(){ ajaxLoading("qualities"); return false;});
	$("#menuEquipe>a").click(function(){ ajaxLoading("team"); return false;});
	$("#menuPress").click(function(){ ajaxLoading("news"); return false;});
	$("#menuCnje").click(function(){ ajaxLoading("cnje"); return false;});
	$("#menuStudent").click(function(){ ajaxLoading("students"); return false;});
	$("#slider").click(function(){ ajaxLoading("portfolio"); return false;});
	$("#menuPortfolioA").click(function(){ ajaxLoading("portfolio"); return false;});
	
   		var TofferFadeIn=false;
		var TofferFadeOut=false;
	$('#appel_offre a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			if(TofferFadeIn==false)
			{
				TofferFadeOut=false;
				TofferFadeIn=true;
				$(this).animate({backgroundPosition:"(0 -50px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -50px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -100px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -100px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -150px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -150px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -200px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -200px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -250px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -250px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -300px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -300px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -350px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -350px)"}, {duration:5});
				$(this).animate({backgroundPosition:"(0 -400px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -400px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -450px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -450px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -500px)"}, {duration:1});
				$(this).animate({backgroundPosition:"(0 -500px)"}, {duration:15});
				$(this).animate({backgroundPosition:"(0 -550px)"}, {duration:1});
			}
		})
		.mouseout(function(){
			if(TofferFadeOut==false)
			{
				TofferFadeIn=false;
				TofferFadeOut=true;
				/*$(this).animate({backgroundPosition:"(0 -700px)"}, {duration:1})
				$(this).animate({backgroundPosition:"(0 -700px)"}, {duration:30})
				$(this).animate({backgroundPosition:"(0 -630px)"}, {duration:1})
				$(this).animate({backgroundPosition:"(0 -630px)"}, {duration:30})
				$(this).animate({backgroundPosition:"(0 -560px)"}, {duration:1})
				$(this).animate({backgroundPosition:"(0 -560px)"}, {duration:30})
				$(this).animate({backgroundPosition:"(0 -490px)"}, {duration:1})
				$(this).animate({backgroundPosition:"(0 -490px)"}, {duration:30})*/
				$(this).animate({backgroundPosition:"(0 0px)"}, {duration:1});
			}
		});
});


$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	var totWidth=0;
	var positions = new Array();
	
	$('#slides .slide').each(function(i){
		
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		
		positions[i]= totWidth;
		totWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		
		
	});
	
	$('#slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#menu ul li a').click(function(e){

			/* On a thumbnail click */

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');
			
			var pos = $(this).parent().prevAll('.menuItem').length;
			
			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
			/* Start the sliding animation */
			
			e.preventDefault();
			/* Prevent the default action of the link */
	});
	
	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */
	
});

