/* Mini plugin de gestion de delay */
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};

jQuery(document).ready(function(){

	// Application de tooltip a tous les liens de class=change-store
	jQuery('a.change-store').mouseover(function(e) {
		//Grab the title attribute's value and assign it to a variable
		var tip = jQuery(this).attr('tip');
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		//jQuery(this).attr('title','');
		
		//Append the tooltip template and its value
		jQuery(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div></div>');		
		
		//Set the X and Y axis of the tooltip
		jQuery('#tooltip').css('top', e.pageY +15);
		jQuery('#tooltip').css('left', e.pageX -30);
		
		//Show the tooltip with faceIn effect
		jQuery('#tooltip').fadeIn('500');
		//jQuery('#tooltip').fadeTo('10',0.8);
	});
	
	jQuery('a.change-store').mousemove(function(e) {
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		jQuery('#tooltip').css('top', e.pageY +15);
		jQuery('#tooltip').css('left', e.pageX -30);
	});
	
	jQuery('a.change-store').mouseout(function() {
		//Put back the title attribute's value
		//jQuery(this).attr('title',jQuery('.tipBody').html());
		//Remove the appended tooltip template
		jQuery(this).children('div#tooltip').remove();
	});
	
	jQuery('.qty-decrease').click(function() {
		var tmp = eval(jQuery(this).parent().find(".qty").val()) - 1;
		if (tmp>=0 && jQuery(this).parent().parent().find(".td-suppr").find("div").hasClass(".trash")) 
			jQuery(this).parent().find(".qty").val(tmp);
		return false;
	});
	
	jQuery('.qty-increase').click(function() {
		var tmp = eval(jQuery(this).parent().find(".qty").val()) + 1;
		if (jQuery(this).parent().parent().find(".td-suppr").find("div").hasClass(".trash"))
			jQuery(this).parent().find(".qty").val(tmp);
		return false;
	});
	
	jQuery('.trash').live("click", function() {
		var tmp = eval(jQuery(this).parent().parent().find(".td-qty").find(".qty").val());
		var tmphidden = eval(jQuery(this).parent().parent().find(".td-qty").find(".qty-hidden").val());
		jQuery(this).parent().parent().find(".td-qty").find(".qty").val(tmphidden);
		jQuery(this).parent().parent().find(".td-qty").find(".qty-hidden").val(tmp);
		jQuery(this).parent().parent().find(".td-qty").find(".qty").attr("readonly", true); 
		jQuery(this).removeClass("trash").addClass("trash-check");
	});
	
	jQuery('.trash-check').live("click", function() {
		var tmp = eval(jQuery(this).parent().parent().find(".td-qty").find(".qty").val());
		var tmphidden = eval(jQuery(this).parent().parent().find(".td-qty").find(".qty-hidden").val());
		jQuery(this).parent().parent().find(".td-qty").find(".qty").val(tmphidden);
		jQuery(this).parent().parent().find(".td-qty").find(".qty-hidden").val(tmp);
		jQuery(this).parent().parent().find(".td-qty").find(".qty").removeAttr("readonly");
		jQuery(this).removeClass("trash-check").addClass("trash");
	});
	
	jQuery('a.lightbox').lightBox();
});