// Fonctions javascript pour la boutique
function printAddPanierMini(id,titre,theme) {
	if(id) {
		document.write("<a href='/panier/?add="+id+"' title='"+titre+"' class='shop_add_panier_mini'><img src='"+theme+"/imgshop/shop_bton_ajoutpanier_mini.png' alt='"+titre+"' /></a>");
	}
}
function printAddPanier(id,titre,theme) {
	if(id) {
		document.write("<a href='/panier/?add="+id+"' title='"+titre+"' class='shop_add_panier'><img src='"+theme+"/imgshop/shop_bton_ajoutpanier.png' alt='"+titre+"' /></a>");
	}
}
function LinkAddPanier(id) {
	if(id) {
		document.location.href = '/panier/?add='+id;
	}
}


// fonctions avec jQuery
jQuery( function($) {
	$(".shop_box_categs ul li").each( function() {
		var $$ = $(this);
		var href = $('a:first',$$).attr('href');
		$$	.hover( function() {
				$$.addClass('over');
			 }, function() {
				$$.removeClass('over');
			 })
			.click( function()  {				
				document.location.href	= href;
			});
	});
	
	//
	// RECALCULE
	//
	$('.shop_bton_recalcule').show();

	$.fn.recalculeQuantite	= function() {
		$("#shop_panier_form input[name=action]").val('recalcule');
		$("#shop_panier_form input[name=shop_step]").val('1');
	};
	
	$("#shop_panier_form input[name^='quantite']").keyup( function(e) {
			var code = e.keyCode;
			switch(code) {
				case 38: // up
					var newval	= parseInt($(this).val()) + 1;
					if(newval > 9999) newval = 9999;
					$(this).val( newval );
				break;
				case 40: // down
					var newval	= parseInt($(this).val()) - 1;
					if(newval < 1) newval = 1;
					$(this).val( newval );
				break;
			}
			//console.log(code);
		});

	$('.shop_bton_recalcule').click( function() {
		$.fn.recalculeQuantite();
		$("#shop_panier_form").submit();
	});
	$("#shop_panier_form input[name^='quantite']").change( function() {
		$.fn.recalculeQuantite();
		$("#shop_panier_form").submit();
	});
	$("#shop_panier_form").submit( function() {
		$.fn.recalculeQuantite();
	});
	
});

