/** test pour contrer pb cache IE **/
var flashName = "flashvisu";
flashName+=Math.round(Math.random()*10000);

var oldcode='';

/** gestion des chargements externes **/
function getHtmlFromPrd(choice, code, from)
{
	switch(choice)
	{
		case 'category':
		   if(code.indexOf('AXEMen^')==-1)code='AXEMen^'+code;
		    if(code!=categorycode)
		    { 
		    	oldcode = prdcode;       
		         $('#zone_nav_FP').load('fp_men_nav.aspx',{categorycode:code},function(){
		         
		       /** appel coremetrics **/
			var tmpcateg = code.replace('AXEMen^','');
			tmpcateg = tmpcateg.replace('^','_');               
			biCP.pageId = "Category: "+biCP.codePays+"_"+biCP.codeLangue+"_"+tmpcateg;			
			cmCreatePageviewTag(biCP.pageId, biCP.codePays+"_"+biCP.codeLangue+"_"+tmpcateg, null);
			
		         
		            if((prdcode=='') || (code!=categorycode))prdcode=$("#nav_FP_niv3 li:first").attr('code');
		            categorycode=code;	
		            if(!document.getElementById(flashName))
                    {
                    $('#zoneProdGamme').load('fp_men_htmlrange.aspx',{categorycode:code});
                    }	   
		            getHtmlFromPrd('product', prdcode, 'categ');
		        });
		    }		   
		break;				
		case 'product':	  
	        if(prdcode!=code || from=='categ')
	        {            
			prdcode=code;
		
			$('#gestual_detail:visible').slideUp('slow').html('');
	            
		$('#zone_content_FP').fadeIn(1000).load('fp_men_content.aspx',{prdcode:prdcode},function()
		{ 
			
			/** appel coremetrics **/
			var tmpcateg = categorycode.replace('AXEMen^','');
			tmpcateg = tmpcateg.replace('^','_')
			cmCreateProductviewTag(biCP.codePays+"_"+biCP.codeLangue+"_"+prdcode, biCP.codePays+"_"+biCP.codeLangue+"_"+prdcode, biCP.codePays+"_"+biCP.codeLangue+"_"+tmpcateg);
		
                    $('#FP_blocAchat').removeClass('error');
		            $('#FP_blocAchat').load('fp_men_ecom.aspx',{prdcode:prdcode},function()
		            {
		                $('#error_FP').html('');
                        if(!document.getElementById(flashName))
                        {
                            /*** version html ***/
                            var imgSrc = '/img/_db/packshots/men/big/'+prdcode+'.png';
                            $("#visuprod").attr('src',imgSrc);
                            
                            if(oldcode)$("#visuprod").removeClass();                            
                            
       			    $("#visuprod").addClass('v_'+prdcode);
                            $("#visuprod").addClass('png');
                            
                        }
		                $("#nav_FP_niv3 li a").removeClass('current');
		                $("#navPrd_"+prdcode+" a").addClass('current');
		               });
		        });	
		        if(from=="fromhtml" || from=="categ")makeCall(prdcode);
		       }
		break;				
		default:

		break;			
	}
}

/** achat **/
function buythisRef(ean,prdcode,q)
{
    eancode=ean;
    $('#error_FP').load('add2bag.aspx',{eancode:ean,q:q,prdcode:prdcode,postback:1},function(){
    	if(document.getElementById('successAdd2Bag')){
    		gotoBag();    		
    	}
    });
}

/** product notification **/
function outofstock(){
    var lcmOOS = new virtualPopup("popup_add_product_notification.aspx?prdcode="+eancode,290,200,"redirectlayer",300,200); 
    lcmOOS.show();
}

function gotoBag(){
	window.location='/_en/_gb/checkout/step1.aspx';
}

/******** gestuelles **********/
function gestual(prdcode){

    $('#gestual_detail').slideDown('slow').load('fp_men_gestual.aspx',{prdcode:prdcode});
}

function closeGestual(){
$('#gestual_detail').slideUp('slow').html('');
}	


/*** dialogue flash - external interface ***/
function thisMovie(movieName) {

    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}

function makeCall(id,from) {
   try
    {
      if (thisMovie(flashName))
      {
	thisMovie(flashName).selectProduit(id);  
      } 
      else if(window.fakeMovies[flashName])
      {
	 window.fakeMovies[flashName].selectProduit(id);  
      }
      else
      {              
	throw id;
      }
    }
    //ex stocke erreur
    catch (ex)
    {
      //retourne l'expression indiquée
      resultat="Opération Impossible";
      //transmet l'objet d'exception au gestionnaire d'erreurs
      if(debug=='')insertFlash(prdcode,categorycode);
    }         
}   


   /** changement de produit **/
function selectProduit(id,from){
  if(!from)
  {
   getHtmlFromPrd('product',id,'fromflash');
  }else{            
   getHtmlFromPrd('product',id,from);
  }	   
}

/** changement de gamme **/
function selectGamme(id,from){        
  if(!from)
  {
     getHtmlFromPrd('category',id,'fromflash');
  }else{
    getHtmlFromPrd('category',id,from);         
  }

}

/****** Au load, on déclenche tout ******/
var url_xml;	    
$(function(){

if(document.getElementById('successAdd2Bag'))
{
	gotoBag();
}
   // Document is ready
var eim = new ExternalInterfaceManager();
eim.registerMovie(flashName);
eim.initialize();   

   /** produit **/
   if(prdcode==''){
	prdcode=$("#nav_FP_niv3 li:first").attr('code');
	
	/*** visuel gauche ***/	   	                       
   	if(debug && (debug==''))insertFlash(prdcode);
   	
	/** on charge le détail produit et on active le produit choisi **/				
	getHtmlFromPrd('product',prdcode,'categ');
   }
   else
   {
	var oldcode = prdcode;
	
	$("#navPrd_"+prdcode+" a").addClass('current');	
	
	 /*** visuel gauche si html ***/
        var imgSrc = '/img/_db/packshots/men/big/'+prdcode+'.png';
        $("#visuprod").attr('src',imgSrc);
        
        if(oldcode)$("#visuprod").removeClass();
       
	$("#visuprod").addClass("v_"+prdcode);
        $("#visuprod").addClass('png');
        
	 /*** visuel gauche si flash ***/				 
	    if(debug=='')insertFlash(prdcode);	   	           
   }	   	       	  
 });

