/*
  This javascript file is included on every page
*/


function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function'){
      window.onload = func;
  } else {
    window.onload = function(){
    oldonload();
    func();
    }
  }

}

/*
  Add the events on the campaing popups
*/
function initCampaignPopUps()
{

  if($("popupCampaign_1")) $("popupCampaign_1").onclick=campaignPopUpHandler;
  if($("popupCampaign_1_text")) $("popupCampaign_1_text").onclick=campaignPopUpHandler;

  if($("popupCampaign_2")) $("popupCampaign_2").onclick=campaignPopUpHandler;
  if($("popupCampaign_2_text")) $("popupCampaign_2_text").onclick=campaignPopUpHandler;

}

/*
  Handles the campaign popups
*/
function campaignPopUpHandler()
{
  if(typeof this.id != "undefined")
  {
    switch(this.id)
    {
      case "popupCampaign_2_text" :
      case "popupCampaign_2" :
      case "popupCampaign_1_text" :
      case "popupCampaign_1" :
      {
        popup(this.href,739,428,this.id,false);
        break;
      }


    }
  }

  return false;
}



/*
  Add the events on the Info-icons
*/
function initInfoPopUps()
{
  if($("infoFilterProducts")) $("infoFilterProducts").onclick=infoPopPupHandler;
  if($("infoShoeSegments")) $("infoShoeSegments").onclick=infoPopPupHandler;
  if($("infoApparelSegments")) $("infoApparelSegments").onclick=infoPopPupHandler;

}

/*
  Handles the Info-icons popups
*/
function infoPopPupHandler()
{
  try{
    if(typeof this.id != "undefined")
    {
      switch(this.id)
      {
        case "infoFilterProducts" :
        {
          if($("banner__normal_visual"))
          {
            getSwfID('banner__normal_visual').showText(1);
          }

          break;
        }

        case "infoShoeSegments" :
        {
          if($("banner__normal_visual"))
          {
            getSwfID('banner__normal_visual').showMenu(2);
          }

          break;
        }


        case "infoApparelSegments" :
        {
          if($("banner__normal_visual"))
          {
            getSwfID('banner__normal_visual').showMenu(3);
          }
          break;
        }


      }
    }
  } catch(e)
  {
    // something went wrong!
  }

  return false;

}

/*
  Handles the footer popups
*/
function footerPopUpHandler()
{
  if(typeof this.id != "undefined")
  {
    popup(this.href,395,491,this.id);
  }

  return false;
}


/*
  Init the sIFR
*/
function init_sIFR(color, swfUrl)
{
  if(typeof color == "undefined")
  {
    color="#385ca1";
  }

  if(typeof sIFR == "function")
  {
  /*
  old version:
  sIFR.replaceElement(named({sSelector:"H1.title", sFlashSrc:"assets/swf/helvetica_neu_45light.swf",sWmode:"transparent",sColor:color}));
  */
    sIFR.replaceElement(named({sSelector:".headerKop", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"#FFFFFF"}));
    sIFR.replaceElement(named({sSelector:"H1.title", sFlashSrc:swfUrl,sWmode:"transparent",sColor:color}));
    sIFR.replaceElement(named({sSelector:"H2.title", sFlashSrc:swfUrl,sWmode:"transparent",sColor:color}));
    sIFR.replaceElement(named({sSelector:"H2.grey", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"c3c3c3"}));
    sIFR.replaceElement(named({sSelector:"H2.white", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"FFFFFF"}));
    sIFR.replaceElement(named({sSelector:"H2.product_title", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"FFFFFF"}));
    sIFR.replaceElement(named({sSelector:"H3.product_info_title", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"FFFFFF"}));
    sIFR.replaceElement(named({sSelector:"H2.product_title_right", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"FFFFFF",sFlashVars:"textalign=right"}));
    sIFR.replaceElement(named({sSelector:"H3.product_info_title_right", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"FFFFFF",sFlashVars:"textalign=right"}));

    sIFR.replaceElement(named({sSelector:"H2.ambassador_name", sFlashSrc:swfUrl,sWmode:"transparent",sColor:"#c1c1c1"}));
  };
}


/*
  Basic function to get the ID from the SWF, wo we can communicatie with it
*/
function getSwfID( movieID )
{
  if (navigator.appName.indexOf("Microsoft") != -1)
  {
    return window[movieID];
  }else
  {
    return document[movieID];
  }
}

/*
  Create the menu
*/
function swfMenu(swfUrl, xmlUrl, mainSelectID,subSelectID)
{
  var fo = new SWFObject(swfUrl, "asicsmenu", "984", "86", "8.0.23", "#e8e4e3", true, "high" );
  fo.addParam("allowScriptAccess", "sameDomain");
  fo.addParam("menu", "false");
  fo.addVariable( "xmlURL", xmlUrl );


  if(typeof mainSelectID != "undefined") fo.addVariable( "mainSelectID", mainSelectID);
  if(typeof subSelectID != "undefined") fo.addVariable( "subSelectID", subSelectID);

  fo.write("nav");
}

/*
  Create the sitemap
*/
function placeSiteMap(targetDIV,swfUrl,xmlURL,w,h)
{
  if(typeof targetDIV != "undefined")
  {
    if(typeof w == "undefined") w=980;
    if(typeof h == "undefined") h=600;

    if(typeof xmlURL == "undefined") xmlURL="sitemap.xml";


    var fo = new SWFObject(swfUrl, targetDIV+"_id", w, h, "8.0.23", "#FFFFFF", true, "high" );
    fo.addParam("allowScriptAccess", "sameDomain");
    fo.addParam("menu", "false");
    fo.addVariable( "xmlURL", xmlURL );

    fo.write(targetDIV);
  }

}

/*
  Basic function to add a button
*/
function addBanner(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,246,123,bg_color);
}

/*
  Place a visual
*/
function placeVisual(divName,swfUrl,xmlURL,w,h,bg_color)
{
  if(typeof divName != "undefined")
  {
    if(typeof xmlURL != "undefined")
    {
      if($(divName))
      {
        if(typeof bg_color =="undefined") bg_color="#FFFFFF";

        var fo = new SWFObject(swfUrl, "banner__" + divName, w, h, "8.0.23", bg_color, true, "high" );
        fo.addParam("allowScriptAccess", "sameDomain");
        fo.addParam("menu", "false");
        fo.addVariable( "xmlURL", xmlURL);
        fo.write(divName);
      }
    }
  }
}


/*
  Place a shoe visual
*/
function addShoeVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,492,369,bg_color);
}

/*
  Place a normal visual
*/
function addNormalVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,738,246,bg_color);
}

/*
  Place a normal visual ... but bigger
*/
function addNormalFullVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,984,246,bg_color);
}

/*
  Place a small visual
*/
function addSmallVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,492,246,bg_color);
}

/*
  2007.03.19 - Add by GX:Place a small visual for product compare page (overview)
*/
function addSmallVisual2(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,246,246,bg_color);
}

/*
  2007.03.27 - Add by GX:Place a medium-small visual for technology details
*/
function addTechnologyVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL, 492, 369, bg_color);
}

/*
  Place a very big visual
*/
function addBigVisual(divName,swfUrl,xmlURL,bg_color)
{
  placeVisual(divName,swfUrl,xmlURL,738,369,bg_color);
}


/*
  These functions handles the zoom-in/zoomout on a shoe visual
*/
function visualDetailHandler()
{
  if($("banner__showImage")) getSwfID("banner__showImage").nextVisualURL(this.href);
  return false;
}

function gx_variantDetailHandler() {

	if($("banner__showImage")) getSwfID("banner__showImage").nextVisualURL(this.href);
 gx_setIcons(this.id,"txt_img_bottom_","image_details_2","imgBottom");
 gx_setIcons(this.id,"txt_img_left_","image_details_1","imgLeft");
 gx_setIcons(this.id,"txt_img_left_","image_zoom","imgZoom");
 gx_setIcons(this.id,"txt_img_bottom_","image_zoom_bottom","imgZoomBottom");
 
 gx_setText(this.id, "txt_colorcode_");
 
 return false;
}

function gx_setText(strId, strPref)
{
 var elmCell = document.getElementById("tdColorCode");
 if (elmCell)
 {
 	try
 	{
	 	if (elmCell.childNodes.length != 0)
	 	{
	 		elmCell.removeChild(elmCell.childNodes[0]);
	 	}
	 	var elmInp = document.getElementById(strPref+strId);
	 	if (elmInp)
	 	{
		 	elmCell.appendChild(document.createTextNode(elmInp.value));
	 	}
 	}
 	catch(err){}
 }
}

function gx_setIcons(strId, strPref, strIdLink, strIdBottom)
{
	var strValue;
 var elm = document.getElementById(strPref + strId);
 if (elm)
 {
 	strValue = elm.value;
 }
 var link = document.getElementById(strIdLink);
 if (link && strValue)
 {
  	link.href=strValue;
 }
 var img = document.getElementById(strIdBottom);
 
 if (img && strValue)
 {
   	if(strValue.charAt(strValue.length-1)!='/') {
 		img.style.display = '';
 		img.src=strValue;
 	}
 	else {
 		img.style.display = 'none';
 	}
 }
}

function closeUpHandler()
{
  if($("banner__showImage")) getSwfID("banner__showImage").showDetailURL(this.href);
  return false;
}
