$(document).ready(function() {
	start();
});

function start() {
	$(".title h2").center();
	$(".title h3").center();
	
	if ($('#slideshow').length > 0)
		$('#slideshow').serialScroll({
			items:'div',
			duration:2000,
			force:true,
			axis:'y',
			easing:'easeOutCirc',
			interval:2, // yeah! I now added auto-scrolling
			//step:2 // scroll 2 news each time
			interval:3000,
			jump:true
		});

	animatePagePrecedente();

	animatePageSuivante();
}

var afficher = false;

function animatePageSuivante() {
	if($("#all_box #droite").length > 0 && document.body.clientWidth < 1070) {
		$("#all_box #droite").animate(	{"right": "+=250px"}, 
										1500, 
										"easeInOutBack", 
										function() {
			$("#all_box #droite").animate(	{"right": "-=250px"}, 
											1500, 
											"easeInOutBack"
			);
		});
	}
}
function animatePagePrecedente() {
	if($("#all_box #gauche").length > 0 && document.body.clientWidth < 1070) {
		$("#all_box #gauche").animate(	{"left": "+=250px"}, 
										1500, 
										"easeInOutBack", 
										function() {
			$("#all_box #gauche").animate(	{"left": "-=250px"}, 
											1500, 
											"easeInOutBack"
			);
		});
	}
}

function afficherDetail (box) {
	$("#produit_nom").html($(box).find("h3").html());
	$("#produit_image").attr('src', $(box).find("img").attr('src'));
	$("#produit_detail").html($(box).find(".detail").html());
	$("#produit_lien").html($(box).find(".left").html());
	$("#produit_prix").html($(box).find(".right").html());
	
	afficher = true;
	setTimeout(function() {
		if (afficher && $("#detail_produit").css('display') == 'none')
			$("#detail_produit").slideDown(function (){$("#produit_detail").css("display","block").css("z-index","1000000");});
	}, 100);

}

function cacherDetail () {
	afficher = false;
	setTimeout(function() {
		if (!afficher) {
			$("#detail_produit").slideUp();
		}
	}, 100);

	
}

function clicDescription (produit_id) {
	//console.debug($('#' + produit_id).height());
	if ($('#' + produit_id).width() != '270') {
		//hideDescription (produit_id);
	} else {
		//showDescription (produit_id);
	}
}

function showDescription (produit_id) {
	$('#' + produit_id).css({width:'800px'});
	$('#' + produit_id + ' .hidden').attr('class', 'show');
}

function hideDescription (produit_id) {
	$('#' + produit_id).css({height:'270px'});
	$('#' + produit_id + ' .hidden').attr('class', 'hidden');
}

function popup_open(ajax) {
	$("#popup_div_mask").show();
	$('#popup_div').load(ajax);
	$("#popup_div").show();
}

function popup_close () {
	$("#popup_div_mask").hide();
	$("#popup_div").hide();
}

