// jQuery(window).load(function(){
// 		jQuery(function() {
// 			initZoom(".jqzoom")
// 		});
// });
// function initZoom(el){
// 	var options =
// 	{
// 		zoomWidth: 350,
// 		zoomHeight: 400,
// 		position : 'right',
// 		zoomType:'reverse',
// 		preloadText:'Chargement du zoom',
// 		yOffset :0,
// 		xOffset :10,
// 		title :false
// 	}
// 	jQuery(el).jqzoom(options);
// }
// 
// jQuery('.expand').click(function(){
// 	var href= jQuery(this).attr('href');
// 	var elclass = href.match('#([a-zA-Z]+)([0-9]+)');
// 
// 	if(elclass[1] == 'html')
// 	{
// 		jQuery('.html'+elclass[2]+'div').show();
// 		jQuery('.js'+elclass[2]+'div').hide();
// 	}else
// 	{
// 		jQuery('.html'+elclass[2]+'div').hide();
// 		jQuery('.js'+elclass[2]+'div').show();
// 	}
// 	jQuery(this).addClass('alert').siblings('a').removeClass('alert');
// 	return false;
// });

function calcul_montant_pack(){
	var prix_pack = parseFloat($('montant_total_pack').value);
	var pack_seul = prix_pack;
	$$('input[id^=option_selected_]').each(function(itm){
		var type = itm.id.replace('option_selected_','');
		var produit = $(itm).value;
		if($('prix_option_'+produit)){
			prix_pack += parseFloat($('prix_option_'+produit).value);
		}
	});
	if($('remise').value != '0.00'){
		$('montant_orig_pack').set('html',sprintf("%.2f",prix_pack));
 		prix_pack = parseFloat(prix_pack - ((prix_pack/100)*$('remise').value));
	}
	if($('montant_credit_pack')){
		$('montant_credit_pack').set('html',sprintf("%.2f",(prix_pack/3)));
	}
	$('montant_pack').set('html',sprintf("%.2f",prix_pack));
	$$('span[id^=difference_]').each(function(itm){
		var produit = itm.id.replace('difference_','');
		var prix_option = parseFloat($('prix_option_'+produit).value);
		var difference  = pack_seul+prix_option;
 		var prix_diff = (difference - ((difference/100)*$('remise').value));
		if(prix_diff > prix_pack){
			$(itm).set('html','(+ '+ sprintf("%.2f",(prix_diff-prix_pack)) + '&euro;)');
		}else if((prix_diff-prix_pack)==0){
			$(itm).set('html','');
		}else{
			$(itm).set('html','(- '+ sprintf("%.2f",(prix_pack-prix_diff)) + '&euro;)');
		}
	});
}
// function initMilkBox(){
// 	$$('a[class=jqzoom]').addEvent('click', function(e){
// 		e = new Event(e).stop();
// 		milkbox.showGallery({ gallery:'gall1' });
// 	});
// }
// function initQuickBox(){
// 	new QuickBox(); 
// }
window.addEvents({
	'domready' : function(){
		if($('subt_infos')){
			myTabs = new mootabs('subt_infos',{width:'75Opx',height:'600px'});
		}
		if($('add2pack')){
			$('add2pack').addEvent('click',function(e){
				e = new Event(e).stop();
				$$('input[id^=option_pack_]').each(function(itm){
					if(itm.checked==true){
						taille = itm.value;
						
					}
				})
				$('custom_taille').set('value',taille);
				$('configurateur').submit();
			});
		}
// 		TB_init();

		$$('a[id^=add2comp_]').each(function(lk){
			$(lk).addEvent('click', function(e){
				e = new Event(e).stop();
				var produit = lk.id.replace('add2comp_','');
				majComp(produit,'add_cmp',false);
			})
		});
		if($('add2cart')){
			$('add2cart').addEvent('click',function(e){
				e = new Event(e).stop();
				$('panier').submit();
			});
		}

		if($('options_selecta')){
			$('options_selecta').getElements('select[id^=opt]').each(function(selecta){
				$(selecta).addEvent('change',function(){
					var page_location = $('redirect_page').value;
					if(page_location.match('&'+selecta.name+'=')){
						var reg_exp= RegExp(selecta.name+'=([0-9]{1,})', "gi");
						page_location = page_location.replace (reg_exp, selecta.name+'='+selecta.value);
					}else{
						page_location += '&'+selecta.name+'='+selecta.value;
					}
					var reg_exp= RegExp('&opt([0-9]{1,})=0', "gi");
					page_location = page_location.replace (reg_exp, '');
				
					document.location = page_location;
				})
			})
		}
// 		milkbox.addEvent('xmlGalleries',function(){
// 			$('zoomer_thumb').addEvent('click', function(e){
// 				e.preventDefault();
// 				milkbox.showGallery({ gallery:'xml' });
// 			});
// 		});
		
	},
	'load': function() {
	
		
		if($('teaser_catalogue'))
			var SlideTeaser = new Teas('teaser_catalogue',teasers);
// 		$$('a[id^=view_]').each(function(itm){
// 			var params = itm.id.replace('view_','').split('_');
// 			var img = params[0]+'_'+params[1];
// 			var flag = params[2]
// 			img += '.jpg';
// 			$(itm).addEvents({
// 				'click':function(){
// 					var _zw = $('link_img').get('name');
// 					var _ttle = $('link_img').get('title');
// 					var NewLink = new Element('a',{'href':'/produits/thumb/viewer.php?product='+img+'&w='+_zw+'&h=800', 'id':'link_img' , 'class':'jqzoom','name':_zw,'rev':'smoothbox','rel':'gallery-smoothbox','title':_ttle  }).setStyles({'float':'left','margin':'0', 'padding':'0'});
// 					var NewImg = new Element('img',{'src':'/produits/thumb/viewer.php?product='+img+'&w=380&h=380', 'alt':_ttle, 'id':'img_zoom'}).setStyles({'float':'left','margin':'0', 'padding':'0', 'border':'0', 'width':'380px'});
// 					NewImg.inject(NewLink);
// 					NewLink.replaces($('link_img'));
// 					initZoom('#link_img');
// 					TB_init();
// 
// 					
// 				}
// 			})
// 		});

		if($('select2pack')){
			$('select2pack').addEvent('click',function(e){
				e = new Event(e).stop();
				var taille = 0;
				$$('input[id^=option_pack_]').each(function(itm){
					if(itm.checked==true){
						taille = itm.value;
					}
				})
				var type = $('pack_type_id').get('value');
				var produit = $('pack_produit_id').get('value');
			
				updateConfigurateur('add_cfg',type,produit,taille);
			});
		}
		

		
	}
	
});
function updateConfigurateur(act,type, id,taille){
	var req = new Request.JSON({
		url: '/jscript/configurateur.php',
		onSuccess:function(response){
			response.each(function(res){
				document.location="/packs.html?step="+res.step;
			});
		}
	}).get({'action': act,'product': id,'type': type, 'taille':taille});
}

