//Au chargement de la page
$(document).ready(function(){

lastcalledvue = "";

  //Initialisation des vues
  $(".photoarticle").bind("mouseenter", 
    function(){
      //Zindexation superieure
      $(this).css("z-index","70");
      
      //Affichage du calque de sortie
    	$(".calque_sortie_ae img").css({width: $(window).width(), height: $(document).height()});	
    	$(".calque_sortie_ae").show();
    	
    	//Affichage de dos
	    vuededos($(".imagecentre img",this).attr("id"));
	    lastcalledvue = $(".imagecentre img",this).attr("id");
    	
    	//Achat express
      $(".achatexpress",this).show().hover(
      			function(){
      						$("img",this).attr("src",$("img",this).attr("src").replace("off","on"));
      						//pour ie<7
      						if($.browser.msie && parseFloat($.browser.version)<7)
      						{$("img",this).attr("style",$("img",this).attr("style").replace("off","on"));}
      			}, 
      			function(){
      						$("img",this).attr("src",$("img",this).attr("src").replace("on","off"));
      						//pour ie<7
      						if($.browser.msie && parseFloat($.browser.version)<7)
      						{$("img",this).attr("style",$("img",this).attr("style").replace("on","off"));}
      			}); 	
    });

  //Initialisation calque sortie
  $(".calque_sortie_ae img").bind("mouseenter",
		function(){
		  //Affichage de face
		//  alert(lastcalledvue);
	    vuedeface(lastcalledvue);
			//Dezindexation
      $(".photoarticle").css("z-index","50");
      //Supression AE
      $(".achatexpress").hide();
      //Disparition calque sortie
      $(".calque_sortie_ae").hide();
		}
);
});

/* acces modachatexpress - liste produit*/
function modAchatExpress(produitid,rayonid,NumeroColoris)
{
	//Verification d'une occurence / Si oui suppression
	if($(".modachatexpress").hasClass("modachatexpress"))
	{
	//alert("il existe des modachatexpress");
	$(".modachatexpress").remove();
	}
	
	// Ajout div d'attente loading
	var modloadingexpress_html  = '<div class="modloadingexpress bgpng2">';
		modloadingexpress_html += '<div class="modloading"><br><b>'+TEXTE_ATTENTE_QUICK_ORDER+'</b><br><img src="/images/000-COMMUN/loading.gif" border="0"/><br><br></div>';  
		modloadingexpress_html += '</div>';		
		$("body").prepend(modloadingexpress_html);
		//Calcul pour le centre
		var top = $(window).scrollTop()+($(window).height()/2)-($(".modloadingexpress").height()/2);
		var left = ($(window).width()/2)-($(".modloadingexpress").width()/2);
		$(".modloadingexpress").css({
	    	top : top+"px",
	    	left : left+"px"
	    });
	
	//On defini le contour
	var modachatexpress_html  = '<div class="modachatexpress bgpng2">';    		 
    	modachatexpress_html += '<div class="modachatexpress_ajax"></div>';  
		//modachatexpress_html += '<div class="qo_lienficheproduit"><a href="'+'">Voir la fiche produit</a></div>';  		
		modachatexpress_html += '</div>';		
		//$("body").prepend('<div class="black_box" style="filter: alpha(opacity=40);"></div>').prepend(modachatexpress_html);
		$("body").prepend(modachatexpress_html);
		//on affiche le cache de la page	
		$('#cachepage').css({width: $(window).width(), height: $(document).height()});
		//document.getElementById("cachepage").style.display="block";
		$('#cachepage').show();
		
		$(".modachatexpress").bgiframe();
		$("#cachepage").bgiframe();
		
		//Calcul pour le centre
		var top = $(window).scrollTop()+($(window).height()/2)-($(".modachatexpress").height()/2)-250;
		var left = ($(window).width()/2)-($(".modachatexpress").width()/2);
		$(".modachatexpress").css({
	    	top : top+"px",
	    	left : left+"px"
	    });
				
		$(".modachatexpress").css({
	    	top : top+"px",
	    	left : left+"px"
	    });
		
	    // recuperation contenu externe 

		$(".modachatexpress_ajax").load('/020-Rayons/modale_ficheproduit2.asp?Produitid='+produitid+'&Rayonid='+rayonid+'&ColoriVedette='+NumeroColoris, function(){
			
			//On cree la black box, on l'insere dans le body, on fade, puis on fade la modale 
			//$('.black_box').css({width: $(window).width(), height: $(document).height()}).fadeIn("slow",function(){
			//	$(".modachatexpress").fadeIn("slow");
			//});
	    	
			//Reexecution de la transparence
			//$('img[@src$=.png]').ifixpng();
			//Affichage de la modale (masquée par défaut en css)
			$('.modachatexpress').fadeIn("fast");
			
			//Fermeture div d'attente
			$('.modloadingexpress').remove();
		
			//Association de la fermeture
			$(".modal_close").click(function(){
				//$('.modachatexpress').fadeOut("fast",function(){$(".black_box").fadeOut("fast",function(){$('.modachatexpress, .black_box').remove();});});
				//$('.modachatexpress').fadeOut("fast", function(){$('#cachepage').fadeOut("fast",function(){$('.modachatexpress, #cachepage').remove();});});
				$('.modachatexpress').fadeOut("fast");
				$('.modachatexpress').remove();
				$('#cachepage').hide();
				//$('#cachepage').remove();
			});

			//$('.black_box').css({width: $(window).width(), height: $(document).height()}).fadeIn("slow",function(){
			//	$(".modachatexpress").fadeIn("slow");
			//});
		});
}