if(typeof(js) == "undefined") {
	js = {};
}
toutou.require("toutou.html.dom", "toutou.js.ajax", "toutou.html.event", "toutou.event.manager");

js.produit = function(tabTaille, nom, reference, urlVente, prix, prixHT) 
{
	this.reference = reference;
	this.nom = nom;
	this.urlVente = urlVente;
	this.prix = prix;
	this.prixHT = prixHT;
	
	if (tt$('addPanier'))
	{
		this.lienPanier = tt$('addPanier');
		var closure 	= toutou.js.closure.bind(this, this.ajoutePanier);
		toutou.html.event.addEventListener(this.lienPanier, "click", closure);
		
		this.stock = tt$('stock');
		this.referenceProduit = tt$('reference');
		if (tabTaille)
		{
			this.tabTaille =  eval('(' + tabTaille + ')');
			this.tailles = tt$('tailles');
			var closure 	= toutou.js.closure.bind(this, this.getStock);
			toutou.html.event.addEventListener(this.tailles, "change", closure);
		}
	}
	
	
}

js.produit.prototype.getStock = function()
{
	var tailleSelect =this.tailles.selectedIndex;
	var valueTaille = this.tailles.options[tailleSelect].value;
	this.referenceProduit.value = valueTaille
  	maxStock = this.tabTaille[valueTaille];
  	if (maxStock > 5)	{ maxStock = 5; }
  	
  	if (this.stock.options.length < maxStock)
  	{
  		for(i = this.stock.options.length; i <= maxStock; i++)
  		{
  			this.stock.options[i]=new Option(i+1,i+1);
  		}
  	}
  	this.stock.options.length = maxStock; 
}

js.produit.prototype.ajoutePanier = function()
{
	if (this.tailles)
	{
		var tailleSelect =this.tailles.selectedIndex;
		var textTaille = this.tailles.options[tailleSelect].text;
		var valueTaille = this.tailles.options[tailleSelect].value;
		var valueTaille = this.tailles.options[tailleSelect].value;
	}
	else
	{
		var textTaille = 'taille unique';
		var valueTaille = this.referenceProduit.value;
	}
	
	var stockSelect =this.stock.selectedIndex;
	var textStock = this.stock.options[stockSelect].text;
	
	$url = '/php/ajax/addCart.php?reference=' + valueTaille + '&quantite=' + textStock + '&prix=' + this.prix + '&prixHT=' + this.prixHT;
	$isMembre = toutou.js.ajax.request($url);
	
	var popover = 
	'<div class="popover_ajout_produit">' +
	'	<div class="popover_titre">' +
	'		Article ajout&eacute; &agrave; mon panier' +
	'	</div>' +
	'	<div class="separate"></div>' +
	'	<p>' +
	'		' + this.nom + ' ( Ref : ' + this.reference + ' )' +
	'	</p>' +
	'	<p>' +
	'		Taille : ' + textTaille +
	'	</p>' +
	'	<p>' +
	'		Quantit&eacute; : ' + textStock +
	'	</p>' +
	'	<div class="separate"></div>' +
	'	<div class="float_left">	' +
	'		<a href="' + this.urlVente + '" class="link_fleche">continuer mon shopping</a>' +
	'	</div>' +
	'	<div class="float_right">' +
	'		<a href="/mon_panier.htm" class="link_fleche">finaliser ma commande</a>' +
	'	</div>' +
	'</div>';
	
	var html =
	'	<div tt_type="TitleBar" class="titleBar">' +
	'	</div>' +
	'	<div id="frameContentText" tt_type="ContentText" class="contentText">' +
	'			##content##' +
	'	</div>';
	this.frame = new oos.frame('panier', popover, html);
	
}