

$(".cotation_transport").click(function(){
	
	$.fancybox([
		{
		href :"http://dev.ducatillon.com/cotation_transport.html?popup",
		title :"Cotations transport",
		type : "iframe"
		},				
	], opts_fancybox);
	//send_ajax("post","",false);
	return false;
});


/*
gestion du choix des options
*/
$("#options_fiche_produit select").change(function(){
	data='reference='+$("#panier_reference").val();
	if ($("#options_produit_1").val()){
		data+='&options_produit_1='+$("#options_produit_1").val();
	}
	if ($("#options_produit_2").val()){
		data+='&options_produit_2='+$("#options_produit_2").val();
	}
	if ($("#options_produit_3").val()){
		data+='&options_produit_3='+$("#options_produit_3").val();
	}
	if ($("#from_page_listing").val()){
		data+='&from_page_listing='+$("#from_page_listing").val();
	}
	send_ajax("post","/library/ajax/fiche_produit_change_reference.php",data);
	
});

hash=parent.location.href;
hash=hash.replace(/^.*\.html#?/, '');
if (hash){
	send_ajax("post","/library/ajax/fiche_produit_load_reference.php",'hash='+hash);
}

/*
Gestion de la box validation produit
*/
$(".ligne_promo_validation .quantite select").change(function () {
	valid_offre=true;
	$(this).parent().parent().parent().find(".quantite select").each(function(){
		if ($(this).val()==0) valid_offre=false;
	});
	my_img=$(this).parent().parent().parent().find("h3 img");
	if (valid_offre){
		my_img.attr("src","/skins/default/img/check.png");
		my_img.attr("title","Offre validée");
		my_img.attr("alt","Valide");
	}
	else {
		my_img.attr("src","/skins/default/img/delete.png");
		my_img.attr("title","Offre non validée");
		my_img.attr("alt","non_valide");
	}
});


$(".ligne_promo_validation select").change(function(){
	if (($(this).parent().parent().find(".quantite select").val())==0 && $(this).val()!='' && $(this).val()!=0){
		$(this).parent().parent().find(".quantite select").val(1);
		
		//on rechecke les quantites
		valid_offre=true;
		$(this).parent().parent().parent().find(".quantite select").each(function(){
			if ($(this).val()==0) valid_offre=false;
		});
		
		my_img=$(this).parent().parent().parent().find("h3 img");
		if (valid_offre){
			my_img.attr("src","/skins/default/img/check.png");
			my_img.attr("title","Offre validée");
			my_img.attr("alt","Valide");
		}
		else {
			my_img.attr("src","/skins/default/img/delete.png");
			my_img.attr("title","Offre non validée");
			my_img.attr("alt","non_valide");
		}
	}
});

/*
Gestion images
*/

var image_vue="";
$("a.miniature").click(function(){
	if (image_vue=='zoom') vue_normale();
	
	var my_source=$(this);
	$("#image_principale img").fadeOut(200,function(){
		$("#image_principale img").attr('src',my_source.find("img").attr('src').replace("/miniature_produit_","/produit_"));
		$("#image_principale a").attr('href',my_source.attr('href'));
		$("#image_principale img").fadeIn(200);
	});
	
	$("a.miniature").removeClass("active");
	$(this).addClass("active");
	
	return false;
});

$("#image_principale a").live('click', function() {
	if (image_vue=='') vue_zoom();
	else vue_normale();
	return false;
});

$("#image_retour").click(function(){
	if (image_vue=='zoom') vue_normale();
	return false;
});
$("#image_zoom").click(function(){
	if (image_vue=='') vue_zoom();
	return false;
});

function vue_zoom(){
	$("#image_principale img").animate({width:1000, height:1000, left:284, top:284}, 500);
	$("#image_principale img").attr('src',$("#image_principale img").attr('src').replace("/produit_","/"));
	$("#image_principale img").draggable('enable');
	$("#image_principale img").draggable({containment: '#limite' });
	image_vue="zoom";
	$("#image_principale img").css('cursor','move');
}
function vue_normale(){
	$("#image_principale img").animate({width:432, height:432, left:568, top:568}, 500);
	$("#image_principale img").draggable('disable');
	image_vue="";
	$("#image_principale img").css('cursor','default');
}
