
function QLPA (qte, prixMinHT, prixMinBarreHT){QL.sku.prix.addTranche(qte, prixMinHT, prixMinBarreHT);}
function QLPC (prix, prixBarre){QL.sku.prix.calc(prix, prixBarre);}
function QLI (path){QL.sku.img(path);}

var QL = {
	url: PATHRACINE + "/QuickLook",
	ajaxurl: PATHRACINE + "/AjaxSku",
	ates: null,
	
	init:{
		query: "", 
		search: null,
		marque: null
	},
	
	load: function(param){
		$.extend(this, this.init, param);
		
		//Definit le survol des produits
		var articles = $(".article_generique");
		articles.hover(
			function(){$(this).find(".achatexpress").animate({width:"show"}, 300);},
			function(){$(this).find(".achatexpress").animate({width:"hide"}, 300);}
		);
		// Definit le click sur achat express
		$(".achatexpress[rel != '']", articles).click(function(){
			QL.open($(this).attr("rel"));
			return false;
		});
	},
	
	// Charge le contenu
	open: function(id_biz){
		//Recuperation externe
		var psearch = (this.search != null && this.search != "") ? "&search=" + this.search : "";
		var pmarque = (this.marque != null && this.marque != "") ? "&marque=" + this.marque : "";

		Box.open({
			url: this.url,
			urldata: PARAMGLOBAL +"&q="+ QL.query +"&ProductID="+ id_biz + pmarque + psearch,
			show: function(){
				QL.ates = $(this.el);
				
				//Draggable
				QL.ates.draggable({cancel:".ates_close, .ates_titre, .ates_article, .ates_description, .ates_form1, .ates_form2, .prix_generique, .ates_selection, .ates_selection_deplier, .ates_panier",scroll:"true",cursor:"move"});
			   
				$('.ates_form1 select', QL.ates).change(function(){
					QL.sku.load(id_biz);
				});
				
				$("input", QL.ates).change(function(){
					QL.sku.prix.calc();
				});

				var id_sku = $("#qlSku_id", QL.ates).val();
				Cart.def(QL.ates, $("#qlLink_cart", QL.ates),  $("#qlQuantity", QL.ates), "SkuID="+ id_sku);
				WishList.load($(".ates_selection_deplier"), QL.ates, "SkusID="+ id_sku);
			}
		});
	},
	
	sku: {
		load: function(id_biz){
			if(	$('.ates_form1 select', QL.ates).length == $('.ates_form1 select', QL.ates).length){
				var param = $('.ates_form1 select', QL.ates).serialize();
				this.prix.tabPrix = new Array();
				$.getScript(QL.ajaxurl + "?display=QL&"+ PARAMGLOBAL + "&idProduct="+ id_biz +"&"+ param);
			}
		},
	
		prix:{
			tabPrix: new Array(),
			
			addTranche:function(qte, prixMinHT, prixMinBarreHT){
				this.tabPrix[qte] = new Array(prixMinHT, prixMinBarreHT);
			},
			
			calc:function(prix, prixBarre){
				var qte = $("#qlQuantity", QL.ates).val();
			
				if(parseInt(qte) && $(".ates_form1 select", QL.ates).length == $(".ates_form1 select[value != '0']", QL.ates).length)
				{
					var tprix = null;
					for(nb in this.tabPrix){
						if(parseInt(qte) >= parseInt(nb)){tprix = this.tabPrix[nb];}
					}
					if(tprix != null){
						prix = tprix[0]; prixBarre = tprix[1];
					}
				}
				
				if(prix != null && prix != "") {$('.prix>.chiffre_1', QL.ates).html(prix);}
				$('.prix>.chiffre_2', QL.ates).html(prixBarre);
			}
		},
		
		img: function (path){
			if(path != null && path != ""){
				$(".haut img", QL.ates).attr("src", PATHIMAGES +'/'+ path);
			}
		}
	}
};





