$(function(){
	path = location.pathname;

	path = path.split('carte/');
	path = path[0];
	
	Cufon.replace('h2');
	
	$('#panier_header').bind({
		mouseenter: function(){
			$(this).showCart(1);
		},
		mouseleave: function(){
			$(this).hideCart();
		},
		touchend: function(){
			$(this).showCart(1);
		}
	});
	
	$(".iframe").colorbox({width:"80%", height:"80%", opacity:"0.5", close:"Fermer", iframe:true});
	
});

jQuery.fn.showCart = function(n) {
	return this.queue(function () {
    	$(this).stop().animate(
			{ height: 300 }, {
		    	duration: 'slow',
		        easing: 'easeInQuad'
		        });
	
		$('#panier_container').css({display: 'block'});
		return $(this).dequeue();
	});
};

jQuery.fn.hideCart = function() {
    $(this).stop().animate({height: 36}, {duration: 'slow', easing: 'easeOutExpo', complete:function(){
		$('#panier_container').css({display: 'none'});
	}}).css('height', '36px');
};

function increaseQty(element)
{
	var qty = parseInt($(element).html());
	$(element).html(qty+1);
}

function decreaseQty(element)
{
	var qty = parseInt($(element).html());
	
	if (qty > 1)
	{
		$(element).html(qty-1);
	}
}

function addToCart(element, id)
{
	//$('#panier_header').unbind('mouseenter mouseleave');
	var qty = parseInt($(element).html());
	
	$.ajax({
	  url: path+'ajax.php?action=add&id='+id+'&qty='+qty,
	  success: function(data) {
			$('#panier_content').html(data);
			$('#panier_header').showCart(1).animate({opacity: 1.0}, 2000, function(){
				$(this).hideCart();
			});
		}
	});
}

function alerte (type, msg)
{
	if (type == 'success')
	{
		$.notifyBar({
          html: msg,
	      cls: "success",
		  delay: 2000,
	      animationSpeed: "normal"
        });
	} else if (type == 'error')
	{
		$.notifyBar({
          html: msg,
	      cls: "error",
		  delay: 2000,
	      animationSpeed: "normal"
        });
	}
}
