// change input value who is transmitted to cart when the user change the "select" of product children
function changeChildrenSelected(p)
{
		productParentId = (p.id).split('-');
		
		//récupère l'id du produit enfant et son prix
		tmp1 = (p.value).split('-');
		productChildId = tmp1[0];
		productChildPrice = tmp1[1];
		
		$('products[' + productParentId[1] + ']').name = 'products[' + productChildId + ']';
		changePrice(productParentId[1], productChildPrice);
		//effet sur le prix
		new Effect.Highlight('shopCategory-price' + productParentId[1], 
	{duration:1, fps:25, from:0.0, to:1.0, startcolor:'#FFD500', endcolor:'#aeb77d', restorecolor:'#FFD500'});

}

// change input value who is transmitted to cart on load of the page
function choiceDefaultOnLoad()
{
	//parcourir tous les produits
	$$('.listeProduits').each(function(p){
		pParentId = (p.id).split('-');
		pParentId = pParentId[1];
		//parcourir tous les enfants pour chaque produit	
		$$('.childOf-' +pParentId).each(function(elt){
			//récupère l'id du produit enfant et son prix
			tmp1 = (elt.value).split('-');
			productChildId = tmp1[0];
			productChildPrice = tmp1[1];						
			//change l'input qui est transmi au panier avec le productId du premier enfant
			$('products[' + pParentId + ']').name = 'products[' + productChildId + ']';
			//charge le prix du premier enfant
			changePrice(pParentId,productChildPrice);
			throw $break;
		});	
	});
}

// modifie le prix lors du changement de la liste déroulante
function changePrice(productParentId, productChildPrice)
{
	$('shopCategory-price' + productParentId).innerHTML = productChildPrice + ' &euro;';
}
function init(){
	
	//change le produit passé en paramètre au panier
	$$('.childrenProductSelect').each(function(p){			
		Event.observe($(p), 'change',function (event){changeChildrenSelected(p);},false);
	});
	
	// sélectionne un produit enfant par défaut lors du chargement de la page 
	choiceDefaultOnLoad();
}


Event.observe(window, 'load', init, false);