/**** CAROUFLOW ****/
var selection_current = 2;
var offer_current = 1
timerId = 0;
move_to_right = function(taille){
	previous = selection_current - 1
	next = selection_current + 1
	newest = next + 1

	if(newest == taille+1)
		$('right_arrow').hide();
	$("left_arrow").className = 'arrow-prev';
	$("left_arrow").show();

	try {
		$('selection_' + newest).innerHTML;
	}
	catch(e){
		return;
	}
	

	$('selection_' + newest).show();
	$('selection_' + newest).className = "right";
	$('selection_' + newest + "_left").show();
	$('selection_' + newest + "_center").hide();

	$('selection_' + previous).hide();

	$('selection_' + selection_current).className = "left";
	$('selection_' + selection_current + "_left").show();
	$('selection_' + selection_current + "_center").hide();

	$('selection_' + next).className = "center";
	$('selection_' + next + "_left").hide();
	$('selection_' + next + "_center").show();
	
	$('text_selection_' + selection_current).hide();
	$('text_selection_' + previous).hide();
	$('text_selection_' + next).show();

	$('button').id = "button_" + selection_current
	$('button_' + next).id = "button"
	
	$('button_img').id = "button_img_" + selection_current
	$('button_img_' + next).id = "button_img"

	$('with-popup').id = "with-popup_" + selection_current
	$('with-popup_' + next).id = "with-popup"

	initPopup();

	selection_current = next
	if (timerId)
		clearTimeout(timerId);
	timerId = setTimeout("move_to_right()", 1500);
}

move_to_left = function(taille){
	previous = selection_current - 1
	next = selection_current + 1
	newest = previous - 1
	
	$("right_arrow").show();
	if(newest == 0)
		$("left_arrow").className = 'arrow-hide';
	
	try {
		$('selection_' + newest).innerHTML;
	}
	catch(e){
		return;
	}

	if ($('selection_' + next)) {
		$('selection_' + newest).show();		
		$('selection_' + newest).className = "left";
		$('selection_' + newest + "_left").show();
		$('selection_' + newest + "_center").hide();

		$('selection_' + next).hide();

		$('selection_' + selection_current).className = "right";
		$('selection_' + selection_current + "_left").show();
		$('selection_' + selection_current + "_center").hide();
	
		$('selection_' + previous).className = "center";
		$('selection_' + previous + "_left").hide();
		$('selection_' + previous + "_center").show();
		
		$('text_selection_' + next).hide();
		$('text_selection_' + selection_current).hide();
		$('text_selection_' + previous).show();
		
		cpt =  previous + 1
		$('button').id = "button_" + cpt
		$('button_' + previous).id = "button"
		
		$('button_img').id = "button_img_" + cpt
		$('button_img_' + previous).id = "button_img"

		$('with-popup').id = "with-popup_" + cpt
		$('with-popup_' + previous).id = "with-popup"

		initPopup();
	
		selection_current = previous
		if (timerId)
			clearTimeout(timerId);
		timerId = setTimeout("move_to_left()", 1500);
	}
}

move_stop = function(){
	clearTimeout(timerId);
}

move_to_top = function(max){
	if ((offer_current - 1) == 0)
	{
		return;
	}
	offer_previous = offer_current - 1;

	$('offer_selection_' + offer_current).hide();
	$('offer_selection_' + offer_previous).show();

	offer_current = offer_previous;
}

move_to_bottom = function(max){
	if ((offer_current + 1) > max)
		return;
	offer_next = offer_current + 1;

	$('offer_selection_' + offer_current).hide();
	$('offer_selection_' + offer_next).show();

	offer_current = offer_next;
}

sleep = function(time){
	var start = date.getTime();
	while(start+time > date.getTime()) true;
	return;
}

display_popup_comment = function(product_id){
	$('popup_comment_' + product_id).id = "popup3";
	$('popup3').style.display = '';
}

delete_cart_product = function(product_id){
	if(confirm('Êtes-vous sûr de vouloir supprimer ce produit?')){
		window.location='/cart/remove_product/' + product_id;
	}
	else{
		document.getElementById('box' + product_id).checked=false;
	}
}