
$(document).ready(function() {
	
	posSouris = 0;
	fiche_affichee = false;
	current_fiche = false;
	
	initFiche();
	
});

function initFiche(){
	$("#contentwrap")
	// Au déplacemenet de la souris, on stocke la position du curseur
	.mousemove(function(e){ posSouris = e.pageX - this.offsetLeft; })
	.bind("click", function() { cacheFiche() } ); 
	
	$(".td_image_panier a").filter(function(){  
		elm = $(this).parents("#coeurnav_produits");
		if(elm.length) {
			return false;
		}
		else {
			return true;
		}
	})
	// Au survol de la vignette produit : on affiche la fiche
	.bind("mouseenter",function() { 
		$(this).parent().parent().addClass('infiche');
		if ( fiche_affichee == false )
		{
			// En fonction de la position du curseur de la souris, on cale la fiche à gauche ou à droite 
			if ( posSouris < 580 )
				margeFiche = "-280px 0px 0px 0px";
			else
				margeFiche = "-280px 0px 0px -225px";
			
			lien = $(this);
			self.setTimeout(function(){montreFiche(lien, margeFiche)},1000);
		}
		
    })
	.bind("mouseleave", function() {
		$(this).parent().parent().removeClass('infiche');
	});
	
	
	$(".win_fiche")
	// Quand on clique sur la fiche ou quand on "sort" de la fiche produit : on cache la fiche
	.bind("mouseleave", function() { cacheFiche() });
}

function cacheFiche() {
	if ( fiche_affichee != false )
	{
		fiche_affichee.animate({opacity: "hide"}, "fast");
		fiche_affichee = false;
	}
	$('.win_fiche').animate({opacity: "hide"}, "fast");
}


function montreFiche(lien, margeFiche) {
	if(lien.parent().parent().hasClass('infiche')){
		fiche_affichee = lien.next("div.win_fiche");
		fiche_affichee.css({margin: margeFiche});
		fiche_affichee.animate({opacity: "show"}, "slow");
	} else {
		fiche_affichee = false;
	}
}
