// voir UserControl/Catalog/ShoppingCart/Cart.ascx pour example d'utilisation
/* <Config> Cart overlay */
var CartOverlayer = function(auto_open, parentId)
{
	this.delai_fermeture = 3000; // Délai de fermeture automatique en milliseconde
	this.delai_ouverture = 200; // Délai d'ouverture sur mouseover en milliseconde, évite que que le panel s'ouvre par un simple survol de la souris.
	this.auto_open = auto_open; // Valeur par défaut 
	this.anim_type = "none"; 
	this.parentId = parentId;

	// Timers
	this.wait2close = null;
	this.wait2open1 = null;
	this.wait2open2 = null;
	
	var me = this;
	if (typeof jQuery != 'undefined') 
	{
		$(document).ready(
			function()
			{
				me.IniCartOverlay();
				if(me.auto_open == "1")
				{
					me.AnimationCart(me.anim_type);
				}
			}
		);
	}
}
/* </Config> Cart overlay */


/*Initialise le cart overlay*/

CartOverlayer.prototype.IniCartOverlay = function()
{
	$("#" + this.parentId + " .cart_overlay").hide();
	$("#" + this.parentId + " .cart_overlay").css({'visibility' : 'visible'});
	$("#" + this.parentId + " .cart_overlay2").hide();
	$("#" + this.parentId + " .cart_overlay2").css({'visibility' : 'visible'});

	var me = this;
	/* Bind event */
	$("#" + this.parentId + " *[id$='lnkCart2']").bind('mouseover', function() {me.OuvrirCartOverlay();});
	$("#" + this.parentId + " *[id$='lnkCart2']").bind('mouseout', function() { me.CancelOverlayOuverture();});
	$("#" + this.parentId + " .contenu_cart_overlay_fermer").bind('click', function() { me.FermerCartOverlay();});
	$("#" + this.parentId + " .cart_overlay2_fermer").bind('click', function() {me.FermerCartOverlay();});
	$("#" + this.parentId + " .cart_overlay").bind('mouseover', function() { me.CancelOverlayFermeture();});
	$("#" + this.parentId + " .cart_overlay").bind('mouseout', function() { me.FermerCartOverlayDelai();});
}

// Affiche l'overlay
CartOverlayer.prototype.OuvrirCartOverlay = function()
{
	this.ResetOverlayTimers();
	this.OuvrirPanel(); 
	var me = this;
	this.wait2close = setTimeout(function() { me.FermerCartOverlay()}, me.delai_fermeture);
}

CartOverlayer.prototype.FermerCartOverlayDelai = function()
{
	this.ResetOverlayTimers(); 
	var me = this;
	this.wait2close = setTimeout(function() { me.FermerCartOverlay()}, me.delai_fermeture);
}
// Ferme les panels
CartOverlayer.prototype.FermerCartOverlay = function()
{
	var me = this;
	setTimeout(
		function()
		{
			$("#" + me.parentId + " .cart_overlay2").fadeOut("fast");
			$("#" + me.parentId + " .cart_overlay").slideUp("fast");
		}, 0);
	this.ResetOverlayTimers();
	setTimeout(function() { me.SwitchCartBg()}, 500);
}
// Envoie la commande d'ouverture des panels avec un délai
CartOverlayer.prototype.OuvrirPanel = function()
{
	var me = this;
	this.wait2open1 = setTimeout(function() { me.OuvreLesPanels() }, me.delai_ouverture)
}
// Ouvre les panels
CartOverlayer.prototype.OuvreLesPanels = function()
{
	var me = this;
	$("#" + this.parentId + " .cart_overlay").slideDown("fast"); 
	setTimeout(function() { $("#" + me.parentId + " .cart_overlay2").fadeIn("slow")}, 600);
	this.SwitchCartBg();
}
// Cancel la commande d'ouverture des 2 panel
CartOverlayer.prototype.CancelOverlayOuverture = function()
{
	clearTimeout(this.wait2open1);
}
	// Cancel la fermutre
CartOverlayer.prototype.CancelOverlayFermeture = function()
{
	clearTimeout(this.wait2close);
}
// Ferme tout maintenant
CartOverlayer.prototype.FermeOverlay = function()
{
	this.FermerCartOverlay();
}
// Reset les timer
CartOverlayer.prototype.ResetOverlayTimers = function()
{
	clearTimeout(this.wait2close); 
	clearTimeout(this.wait2open1); 
	clearTimeout(this.wait2open2);
}
// Switch la couleur de backgroud du cart
CartOverlayer.prototype.SwitchCartBg = function()
{
	$("#" + this.parentId + " .header_cart_container").toggleClass('cart_bg_on');
}

CartOverlayer.prototype.AnimationCart = function(animtype){
	var me = this;
	switch(animtype)
	{
		case "fade" : $("#" + this.parentId + " .cart_root_container").hide().fadeIn("slow", function(){me.OuvrirCartOverlay();});break;
		case "slide" :$("#" + this.parentId + " .cart_root_container").effect("slide","","", function(){me.OuvrirCartOverlay();});break;
		case "bounce" :$("#" + this.parentId + " .cart_root_container").effect("bounce","","", function(){me.OuvrirCartOverlay();});break;
		case "pulsate" :$("#" + this.parentId + " .cart_root_container").effect("pulsate","","", function(){me.OuvrirCartOverlay();});break;
		case "shake" :$("#" + this.parentId + " .cart_root_container").effect("shake","","", function(){me.OuvrirCartOverlay();});break;
		case "none" : this.OuvrirCartOverlay();break;
	}
} 
/*</CART OVERLAY>*/

