$(document).ready(function(){
	//$('#lense_1').css('opacity','0');
	$('.lenseDisplay').each(function(){
		$(this).css('opacity','0');			  
	});
	$('a.lienPetitePhoto').hover(function() {
		$(this).stopTime();									  
		$(this).oneTime(200, function() {
			$(this).parent().find('img.petitePhoto').fadeIn('fast');
		});
	}, function() {
		$(this).stopTime();
		$(this).oneTime(200, function() {
			$(this).parent().find('img.petitePhoto').fadeOut('fast');
		});
	});
	$("a#newsletterLink").fancybox({
		'hideOnContentClick': false
	});
	
});

$("a#btn-inscription-newsletter").live("click",function(){
	inscriptionNewsletter();
});

function inscriptionNewsletter(){
	
	// on initialise le msg d'erreur a vide
	$('.errorNewsletter').html("");
	
	var mail = $('#email').val();
	var firstname = $('#firstname').val();
	var name = $('#name').val();
	var country = $('#country').val();
	var centres = Array();
	
	for(var i=1; i<=5; i++){
		if($('#centre_'+i).is(":checked"))
			centres.push(i);
	}
	var centresString = centres.toString();
	
	var gender = 0;
	for(var i=1; i<=5; i++){
		if($('#gender_'+i).is(":checked"))
			gender = i;
	}
	
	$.ajax({
		type:'POST',
		url:'/www/ajax/inscriptionNL.php',
		data:{email:mail, centres:centresString, gender:gender, firstname:firstname, name:name, country:country },
		success:function(msg)
		{
			
			var tabMsg = msg.split('|');
			
			if(tabMsg[0] == 1){	
				// inscription réussie
				$('#contentInscriptionNewsletter').html("<p class='tcenter'><strong>"+tabMsg[1]+"</strong></p>");
				
			}else {
				$('.errorNewsletter').html(tabMsg[1]);
			}
				
		}
	});
	
	
}
function displayLense(idLense)
{
	var hauteurDebut = $("#ProductVariationList").height();
	$("#productVariationBox").height(hauteurDebut);
	
	$("#ProductVariationList").animate({ 
		opacity:0
	}, 300,'swing',function(){
		
		//
		$("#lense_"+idLense).css('display','block');
		var hauteurRequest = $("#lense_"+idLense).height();
		$("#productVariationBox").animate({ 
			height: hauteurRequest
		}, 300, '', function(){
			$("#ProductVariationList").css('display','none');
			
			$("#lense_"+idLense).animate( { opacity:1}, 300 );
		});
	});
	
	//return false;
}


function retourFicheProduit(idLense)
{
	$("#lense_"+idLense).animate({ 
		opacity:0
	}, 300, '', function(){
		$("#lense_"+idLense).css('display','none');
		$("#ProductVariationList").css('display','block');
		var hauteurDebut = $("#ProductVariationList").height();
		$("#productVariationBox").animate({ 
			height: hauteurDebut
		}, 300, '', function(){
			
			$("#ProductVariationList").animate( { opacity:1}, 300 );
		});
	});
}
