$(document).ready(function() {
	//AutoHeight();
	$("a.toggle-plan").click(function() {
		if($("#sitemap").css("display")=="block") {
			$("#sitemap").slideUp(500);
		} else {
			$("#sitemap").show(50,function() { $.scrollTo("#bottom",2000);});
		}
	});
	$("a.petit-logo").fadeTo(0,"0.5");
	$("a.petit-logo").mouseover(function() {
		$(this).stop().fadeTo(500,1);
	}).mouseout(function() {
		$(this).stop().fadeTo(1500,"0.5");
	});
	//$("#sitemap .col").equalHeights();
	$("#sitemap").hide();
	//Slider();
	//DD_belatedPNG.fix("#menu img");
	//DD_belatedPNG.fix(".phrase img");
	//DD_belatedPNG.fix("a.toggle-plan");
	$("marquee").marquee();
});

$(window).bind('resize', function() {
	//AutoHeight();
});

function AutoHeight() {
	var entete = $("#entete").outerHeight();
	var submenu = $("#submenu").outerHeight();
	var pied = $("#pied").outerHeight();
	$("#content").css("min-height",$(window).height()-entete-submenu-pied);
}

function SetNbArticles(nb) {
	$("#nb_articles").html(nb);
}

/* DIALOG BOX */
function DialogBox() {
	$("#dialog").dialog("open");
	if (LANG == "en"){
		$("#dialog").dialog({
			title: "My cart",
			draggable: true,
			modal: true,
			width: 400,
			minHeight: 30,
			resizable: true,
			buttons: {
				"Continue shopping" : function() { $(this).dialog("close"); },
				"Validate my cart": function() { document.location = SITEPATH+LANG+"/cart.html"; }
			}
		});
	}else{
		$("#dialog").dialog({
			title: "Mon panier",
			draggable: true,
			modal: true,
			width: 400,
			minHeight: 30,
			resizable: true,
			buttons: {
				"Continuer mon shopping" : function() { $(this).dialog("close"); },
				"Valider ma sélection": function() { document.location = SITEPATH+LANG+"/panier.html"; }
			}
		});
	}
		
	
	
}

/* SLIDER */
var NB_IMAGES = 4;
function Slider(selected) {
	//vars
	var conveyor = $(".content-conveyor", $("#sliderContent"));
	var item = $(".item", $("#sliderContent"));
	var nbdivs = item.length;
	
	if(selected==null) selected = 1;
	if (selected >= (nbdivs-NB_IMAGES)){
		selected = (nbdivs-NB_IMAGES)+1;
	}
	
	if (item.length>NB_IMAGES){
		conveyor.css("width", item.length * parseInt(item.css("width")));
		var visiblewidth = $("#sliderContent").width();
		var conveyorwidth = $(".content-conveyor").width();
		var itemwidth = parseInt(item.css("width"));
		var nbMouvements = nbdivs-NB_IMAGES;
		var sliderPas = (100/nbMouvements);
		var decalage = itemwidth*(selected-1);
		
		//Décalage des images
		var marginLeft = "-"+decalage;
		$(".content-conveyor").animate({
			marginLeft : marginLeft
		}, 500);

		//Décalage du slider
		var valmax = (nbdivs * parseInt(item.css("width"))) - parseInt($(".viewer,#sliderContent").css("width"));

		var sliderOpts = {
			animate: true,
			max: valmax, //735
			slide: function(e,ui) { //Déplacement des images lors du slide du bouton
				conveyor.css("margin-left", "-" + ui.value + "px");
			}
		};
		
	
		
		$("#slider").slider(sliderOpts);
		

		switch(selected) {
			case 1: //Premier item
				var sliderPosition = 0; //Bouton Slider à 0%
				break;
			case nbdivs: 
				var sliderPosition = 100; 
				break;
			default: 
				var sliderPosition = (sliderPas*(selected-1));
				break;
		}
		
		//Décalage bouton
		var posActu = $(".ui-slider .ui-slider-handle").css("left");

		var sliderPosition = sliderPosition+"%";
		$(".ui-slider .ui-slider-handle").animate({
			left : sliderPosition
		}, 500);
	}
}

function AnimateSlider(item) {
	if(item==null) {
		var i = 1;
	} else {
		var i = item;
	}
	var nbItems = parseInt($("#sliderContent").find(".item").length);
	var nbMouvements = (nbItems-NB_IMAGES)-(i-1);

	if(i==(nbMouvements+1) || nbMouvements<=0) { //tous les movements ont été effectués
		setTimeout(function() {
			Slider(1);
			AnimateSlider(); //On réinitialise le slider
		},5000);
	} else {
		setTimeout(function() {
			Slider(parseInt(i+1));
			AnimateSlider(parseInt(i+1)); //On fait glisser le slider
		},5000);
	}
}

function SwitchLang(str_fr,str_en){
	if (LANG == "en"){
		if (str_en!=""){
			return str_en;
		}else{
			//return str_fr;
		}
	}else {
		return str_fr;
	}
}
