var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
layout = null,
resize = null;

var theWidth;
var theHeight;
var pl_lt = 0;
var pl_top = 0;
var panelwidth1;
var panelheight1;

var url = location.href;	

var yemailpanel = "";
var yemailsignuppanel = "";
var ystorelocatorpanel = "";
var yeventspanel = "";


// find inner dimensions of the window
function setDimensionsPU() {

	// Window dimensions:
	if (window.innerWidth) {
		theWidth=window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
	}
	else if (document.body) {
		theWidth=document.body.clientWidth;
	}
	if (window.innerHeight) {
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) {
		theHeight=document.body.clientHeight;
	}

	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	
	dsocleft=document.all? iebody.scrollLeft : pageXOffset
	dsoctop=document.all? iebody.scrollTop : pageYOffset

}

//center the panel
 function centerPanel(pnw, pnh) {
	pl_lt = (theWidth-pnw)/2;
	pl_top = (theHeight-pnh)/2;
	if (pl_lt < 0) pl_lt = 0;
	if (pl_top < 0) pl_top = 0;
	//YAHOO.log("Call to centerPanel - line 43", "info", "main.js"); 
}

// launch scaled or not scaled flash
function checkScreen()
{

	var flashwidth2 = flashwidth;
	var flashheight2= flashheight;
	if ((screen.width<=1280) && (screen.height<=800))
	{
		//alert(1);
		if (theHeight <= 800 || theWidth <= 1280){
			
			params.scale = "scale";
			
		}
	}
	else {
		params.scale = "noscale";	
	}
	//alert(theHeight);
	
	swfobject.embedSWF(flashfile, flashdiv, flashwidth2, flashheight2, flashversion, flashload, flashvars, params, attributes);
		
	
	
}

YAHOO.util.Event.onDOMReady(
    function() {
			setDimensionsPU();
		    panelwidth1 = theWidth*.50;
			panelheight1 = theHeight*.50;
	   try{		
			
			checkScreen();
		}
		catch(e){
			//alert(1);
			checkCookie();
			setPanel();	
		}
		//english 
		 try{	
		// country / language
		YAHOO.util.Event.addListener("cylgbutton", "click", removeCookie);
		
		// privacy
		YAHOO.util.Event.addListener("privacybutton", "click", openPopup = function(){
				popUp("privacy.html", "privacy", 600, 300);				
		});
		
		// security
		YAHOO.util.Event.addListener("securitybutton", "click", openPopup = function(){
				popUp("security.html", "security", 600, 300);				
		});
		
		// terms
		YAHOO.util.Event.addListener("termsbutton", "click", openPopup = function(){
				popUp("terms.html", "terms", 600, 300);				
		});
		
		
		// copy
		YAHOO.util.Event.addListener("copybutton", "click", openPopup = function(){
				
				popUp("copy.html", "copy", 600, 300);				
		});
		
		}
		catch(e){}
		//fr
		 try{	
		// country / language
		YAHOO.util.Event.addListener("cylgbutton", "click", removeCookie);
		
		// privacy
		YAHOO.util.Event.addListener("frprivacybutton", "click", openPopup = function(){
				popUp("privacyfr.html", "privacy", 600, 300);				
		});
		
		// security
		YAHOO.util.Event.addListener("frsecuritybutton", "click", openPopup = function(){
				popUp("securityfr.html", "security", 600, 300);				
		});
		
		// terms
		YAHOO.util.Event.addListener("frtermsbutton", "click", openPopup = function(){
				popUp("termsfr.html", "terms", 600, 300);				
		});
		
		
		// copy
		YAHOO.util.Event.addListener("frcopybutton", "click", openPopup = function(){
				
				popUp("copyfr.html", "copy", 600, 300);				
		});
		}
		catch(e){}
		//it
		 try{	
		// country / language
		YAHOO.util.Event.addListener("cylgbutton", "click", removeCookie);
		
		// privacy
		YAHOO.util.Event.addListener("itprivacybutton", "click", openPopup = function(){
				popUp("privacyit.html", "privacy", 600, 300);				
		});
		
		// security
		YAHOO.util.Event.addListener("itsecuritybutton", "click", openPopup = function(){
				popUp("securityit.html", "security", 600, 300);				
		});
		
		// terms
		YAHOO.util.Event.addListener("ittermsbutton", "click", openPopup = function(){
				popUp("termsit.html", "terms", 600, 300);				
		});
		
		
		// copy
		YAHOO.util.Event.addListener("itcopybutton", "click", openPopup = function(){
				
				popUp("copyit.html", "copy", 600, 300);				
		});
		}
		catch(e){}
	}
	
	
);

// flash functions to launch panels 
function emailfeedback() 
{
	//yemailpanel.show();
}

function feedback() 
{
	//yemailpanel.show();
	popUp("feedback.html", "Feedback", 366, 397);			
}

function frfeedback() 
{
	//yemailpanel.show();
	popUp("feedbackfr.html", "Feedback", 366, 397);			
}

function itfeedback() 
{
	//yemailpanel.show();
	popUp("feedbackit.html", "Feedback", 366, 397);			
}

function emailsignup() 
{
	//yemailsignuppanel.show();
	//window.open ("http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=700&SOURCE_2=tma","signup");
	popUp("http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=700&SOURCE_2=ek2", "Sign up", 354, 387);
	
}

function ukemailsignup() 
{
	//yemailsignuppanel.show();
	//window.open ("http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=700&SOURCE_2=tma","signup");
	popUp("http://ebm.cheetahmail.com/r/regf2?a=0&aid=1382472114&n=700&SOURCE_2=ek2", "Sign up", 354, 387);
	
}

function fremailsignup() 
{
	//yemailsignuppanel.show();
	//window.open ("http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=700&SOURCE_2=tma","signup");
	popUp("http://ebm.cheetahmail.com/r/regf2?a=0&aid=1382472114&n=701&SOURCE_2=ek2", "Sign up", 397, 397);
	//alert(1);
	
}

function itemailsignup() 
{
	//yemailsignuppanel.show();
	//window.open ("http://ebm.cheetahmail.com/r/regf2?a=0&aid=949559453&n=700&SOURCE_2=tma","signup");
	popUp("http://ebm.cheetahmail.com/r/regf2?a=0&aid=1382472114&n=702&SOURCE_2=ek2", "Sign up", 397, 397);
	
}

function storelocator()
{
	popUp("storelocator.html", "stores", 960, 550);
}

function ukstorelocator()
{
	popUp("storelocatoruk.html", "stores", 960, 550);
}

function frstorelocator()
{
	popUp("storelocatorfr.html", "stores", 990, 550);
}

function itstorelocator()
{
	popUp("storelocatorit.html", "stores", 990, 550);
}

function shoponline(url)
{
	window.open (url,"Shopping");
}

function events()
{
	//yeventspanel.show();
}

function gameLaunch(){
	//launchLyteboxLink();
	popUp("http://www.timberland.com/unexpectedobstacles/index.jsp?noNav=true", "Game", 790, 520);
}

function popUp(pageURL, title,w,h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	left = Math.round(left);
	top = Math.round(top);
	w = Math.round(w);
	h = Math.round(h);
	var params = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+w+',height='+h+',top='+top+',left='+left;
	var targetWin = window.open(pageURL,"tbl",params);
} 


function setPanel(){
	//yclpanel = "";
 	var yclpanel = new YAHOO.widget.Panel("country", {
            draggable: false,
			close: false,
			modal: true,
			fixedcenter: true,
			effect: {effect:YAHOO.widget.ContainerEffect.FADE, duration:.25},
            width: "200px",
            height:"100px",
			visible: false,
            autofillheight: "body", // default value, specified here to highlight its use in the example
            constraintoviewport:true
            //context: ["canvas", "tl", "tl"]
			//xy: [pl_lt, pl_top]
        });
	

	
	//yclpanel.onblur = closepanel;
	
	//show the panel 
	yclpanel.render();
	 
	yclpanel.show();
	
	
	
}

function setCL(lg) 
{
	switch(lg)
	{
	case "enus":
	  YAHOO.util.Cookie.set("cy", "UNITED STATES");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "9");
	  window.location="index_wms_us.html";
	  break;
	case "engb":
	  YAHOO.util.Cookie.set("cy", "UNITED KINGDOM");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "10");
	  window.location="index_wms_uk.html";
	  break;
	case "frfr":
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "FRENCH");
	  YAHOO.util.Cookie.set("ad", "11");
	  window.location="index_wms_fr.html";
	  break;
	case "itit":
	  YAHOO.util.Cookie.set("cy", "ITALY");
	  YAHOO.util.Cookie.set("lg", "ITALIAN");
	  YAHOO.util.Cookie.set("ad", "13");
	  window.location="index_wms_it.html";
	  break;
	case "ekenus":
	  YAHOO.util.Cookie.set("cy", "UNITED STATES");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "1");
	  window.location="index_ek_us.html";
	  break;
	case "ekengb":
	  YAHOO.util.Cookie.set("cy", "UNITED KINGDOM");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "2");
	  window.location="index_ek_uk.html";
	  break;
	case "ekfrfr":
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "FRENCH");
	  YAHOO.util.Cookie.set("ad", "3");
	  window.location="index_ek_fr.html";
	  break;
	default:
	  window.location="index.html";
	}	
}

function checkCookie()
{
	var ad = YAHOO.util.Cookie.get("ad");
	//alert(ad);
	switch(ad)
	{
	case "1":
	 //alert(1);
	  YAHOO.util.Cookie.set("cy", "UNITED STATES");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "1");
	  window.location="index_ek_us.html";
	  break;
	case "2":
	  YAHOO.util.Cookie.set("cy", "UNITED KINGDOM");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "2");
	  window.location="index_ek_uk.html";
	  break;
	case "3":
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "FRENCH");
	  YAHOO.util.Cookie.set("ad", "3");
	  window.location="index_ek_fr.html";
	  break;
	case "4":
	 //alert(1);
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "4");
	  window.location="index_ek_fr.html";
	  break;
	case "5":
	  YAHOO.util.Cookie.set("cy", "UNITED STATES");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "5");
	  window.location="index_tma_us.html";
	  break;
	case "6":
	  YAHOO.util.Cookie.set("cy", "UNITED KINGDOM");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "6");
	  window.location="index_tma_uk.html";
	  break;
	case "7":
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "FRENCH");
	  YAHOO.util.Cookie.set("ad", "7");
	  window.location="index_tma_fr.html";
	  break;
	case "8":
	 //alert(1);
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "8");
	  window.location="index_tma_fr.html";
	  break;
	case "9":
	 //alert(1);
	  YAHOO.util.Cookie.set("cy", "UNITED STATES");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "9");
	  window.location="index_wms_us.html";
	  break;
	case "10":
	  YAHOO.util.Cookie.set("cy", "UNITED KINGDOM");
	  YAHOO.util.Cookie.set("lg", "English");
	  YAHOO.util.Cookie.set("ad", "10");
	  window.location="index_wms_uk.html";
	  break;
	case "11":
	  YAHOO.util.Cookie.set("cy", "FRANCE");
	  YAHOO.util.Cookie.set("lg", "FRENCH");
	  YAHOO.util.Cookie.set("ad", "11");
	  window.location="index_wms_fr.html";
	  break;
	case "13":
	  YAHOO.util.Cookie.set("cy", "ITALY");
	  YAHOO.util.Cookie.set("lg", "ITALIAN");
	  YAHOO.util.Cookie.set("ad", "13");
	  window.location="index_wms_it.html";
	  break;
	default:
	  
	}		
}

function removeCookie(){
	//alert(1);
	 YAHOO.util.Cookie.remove("cy");
	 YAHOO.util.Cookie.remove("lg");
	 YAHOO.util.Cookie.remove("ad");
	 window.location="index.html";
}

//dart tags
function dart(cat){
	
	var divName = createDiv(cat);
	
	//alert("dart tag launched");
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	document.getElementById(divName).innerHTML = ('<IFRAME SRC="http://fls.doubleclick.net/activityi;src=2227922;type=globa760;cat=' + cat + ';ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');
}

//create div for dart iframes
function createDiv(cat)
{
  var newdiv = document.createElement('div');
  var divIdName = 'div'+cat;
  newdiv.setAttribute('id',divIdName);
  newdiv.style.width = "0px";
  newdiv.style.height = "0px";
  newdiv.style.left = "0px";
  newdiv.style.top = "0px";
  newdiv.style.position = "absolute";
  newdiv.style.background = "#FF0000";
  //newdiv.style.border = "1px solid #000000";
  //newdiv.innerHTML = 'this is div number '+arguments[0];

  document.body.appendChild(newdiv);
  
  return divIdName;
  
 }

