$(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");
	AnimateSlider();
});

$(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 */
function Slider(selected) {
	if(selected==null) selected = 0;
	//vars
	var conveyor = $(".content-conveyor", $("#sliderContent")),
	item = $(".item", $("#sliderContent"));
	if (item.length>4){
		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 nbdivs = item.length;
		var scrollwidth = (100/nbdivs);
		var decalage = itemwidth*selected;
		
		$(".content-conveyor").css("left","-"+decalage+"px");
		
		var valmax = (item.length * parseInt(item.css("width"))) - parseInt($(".viewer,#sliderContent").css("width"));
		
		var sliderOpts = {
			animate: true,
			max: valmax,
			slide: function(e,ui) {
				conveyor.css("left", "-" + ui.value + "px");
			}
		};
	
		
		$("#slider").slider(sliderOpts);
		
		switch(selected) {
			case 1: var position = 0; break;
			case nbdivs: var position = 100; break;
			default: var position = (scrollwidth*(selected-1)+(scrollwidth/2));
		}
		$(".ui-slider .ui-slider-handle").css("left",position+"%");
		
		var decalage = (visiblewidth*(position/100));
		
		$(".content-conveyor").css("left","-"+decalage+"px");
		//var totalwidth = (item.length * parseInt(item.css("width")));
		//var sliderwidth = $(".ui-slider").width();
		//var rapport = (totalwidth/valmax);
		//conveyor.css("left", "-" + (x*rapport) + "px");
		//alert((x*rapport))
	}
}

function AnimateSlider() {
	setTimeout(function(){ Slider(1); },5000);
	setTimeout(function(){ Slider(2); },10000);
	setTimeout(function(){ Slider(3); },15000);
	setTimeout(function(){ Slider(4); },20000);
	setTimeout(function(){ Slider(5); },25000);
	setTimeout(function(){ Slider(6); },30000);
	setTimeout(function(){ Slider(7); },35000);
	setTimeout(function(){ Slider(8); AnimateSlider(); },40000);
}

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