/******************************************************************************/
/*	@name    vw left nav javascript functions
/*  @date    Feb 03, 2007
/*  @version 2.0.0
/******************************************************************************/
//=============================================================================
// CONSTRUCTOR (create singleton instance of the vwLeftNav object)
//=============================================================================
if(typeof vwLeftNav=="undefined")
{
	var vwLeftNav = {};
}
//=============================================================================
// INITIALIZE vwLeftNav
//=============================================================================
vwLeftNav.build = function(inContainer, inConfig, inLang, inCountry)
{
	vwLeftNav.util.setLangCountry(inLang, inCountry);
	vwLeftNav.data.init();
	vwLeftNav.util.setContainer(inContainer);
	vwLeftNav.util.setImagePath(inLang, inCountry);
	vwLeftNav.menu.build(inConfig);
	pngpong.util.preloadImage("/global/images/comingSoon.jpg");
};
//=============================================================================
// CONTROLERS FOR THE MENU OBJECT
//=============================================================================
vwLeftNav.menu =
{
	//=========================================================================
	build : function(inConfig)
	{
		this.hrCounter = 0;
		this.subMenuHeight = 0;
		this.submenu = false;
		this.m = inConfig.split("_")[0].toLowerCase();
		try{
			this.sm = inConfig.split("_")[1].toLowerCase();
		}catch(e){
			this.sm = null;
		}
		try{
			this.ssm = inConfig.split("_")[2].toLowerCase();
		}catch(e){
			this.ssm = null;
		}
		// controls whether the menu should animate down or just show
		if(this.sm == null)
			this.animateMenu = true;
		else
			this.animateMenu = false;
		//======================================================
		// title
		if(vwLeftNav.data.nav[0].type == "t")
			vwLeftNav.util.createNode("leftNav_title", "menu_"+vwLeftNav.data.nav[0].height);
		
		this.serve("leftNav_title", vwLeftNav.data.nav[0].title);
		//======================================================
		// build nav
		for(var i=1; i<vwLeftNav.data.nav.length; i++)
		{
			if(vwLeftNav.data.nav[i].type == "m")
			{
				this.addMenu(i);
			}
			else if(vwLeftNav.data.nav[i].type == "sm")
			{
				this.addMenu(i);
			}
			else if(vwLeftNav.data.nav[i].type == "ssm" && vwLeftNav.data.nav[i].revealSub == true)
			{
				this.addMenu(i);
			}
			else if(vwLeftNav.data.nav[i].type == "hr")
			{
				this.addHr();
			}
			else if(vwLeftNav.data.nav[i].type == "hr_7")
			{
				this.addHr_7();
			}
		}
		/*if(this.animateMenu == true)
			this.menu_timeout = setInterval("vwLeftNav.menu.animate();", 3000);
		else*/
		if(this.subMenuHeight != 0)
			util.setStyle("smenuContainer", "height", this.subMenuHeight, "px");
		//======================================================
		// add comging soon
		for(var i=0; i<vwLeftNav.data.comingSoon.length; i++)
		{
			vwLeftNav.tooltip.add(vwLeftNav.data.comingSoon[i]);
		}
	},
	//=========================================================================
	// add item functions
	addMenu : function(inIndex)
	{
		//2px container
		if(this.m == vwLeftNav.data.nav[inIndex].title.split("_")[1].toLowerCase())
			vwLeftNav.util.createNode("spacer_2px", "menu_2");

		vwLeftNav.util.createNode(vwLeftNav.data.nav[inIndex].title, vwLeftNav.util.getClass(inIndex));
		if(this.m == vwLeftNav.data.nav[inIndex].title.split("_")[1].toLowerCase())
		{
			//insert 2px
			this.serve("spacer_2px","m_spacer_2px.gif");

			if(this.sm == null)
				this.serve(vwLeftNav.data.nav[inIndex].title, vwLeftNav.data.nav[inIndex].title+"_active.gif");
			else if(vwLeftNav.data.nav[inIndex].isActive == true)
				this.serveButtonUrl(vwLeftNav.data.nav[inIndex].title, vwLeftNav.data.nav[inIndex].title+"_active.gif", vwLeftNav.data.nav[inIndex].title+"_over.gif", vwLeftNav.data.nav[inIndex].url);
			else
				this.serve(vwLeftNav.data.nav[inIndex].title, vwLeftNav.data.nav[inIndex].title+"_active.gif");
				
			if(vwLeftNav.data.nav[inIndex].items.length >= 1)
			{
				vwLeftNav.util.createNode("smenuContainer", "smenuContainer");
				this.addSubMenu(this.sm, this.ssm, vwLeftNav.data.nav[inIndex]);
			}
		}
		else if(vwLeftNav.data.nav[inIndex].title.split("_")[0].toLowerCase()=="p")
		{
			this.serveButtonPopup(vwLeftNav.data.nav[inIndex].title, vwLeftNav.data.nav[inIndex].title+"_out.gif", vwLeftNav.data.nav[inIndex].title+"_over.gif", vwLeftNav.data.nav[inIndex].url,"");
		}
		else
		{
			this.serveButtonUrl(vwLeftNav.data.nav[inIndex].title, vwLeftNav.data.nav[inIndex].title+"_out.gif", vwLeftNav.data.nav[inIndex].title+"_over.gif", vwLeftNav.data.nav[inIndex].url);
		}
	},
	addHr : function()
	{
		var name = "hr_" + this.hrCounter;
		vwLeftNav.util.createNode(name, "hr");
		this.serve(name, "m_hr.gif");
		this.hrCounter += 1;
	},
	addHr_7 : function()
	{
		var name = "hr_7_" + this.hrCounter;
		vwLeftNav.util.createNode(name, "hr_7");
		this.serve(name, "m_hr_7.gif");
		this.hrCounter += 1;
	},
	//=========================================================================
	// add sub menu function
	addSubMenu : function(inType, inSub, inArray)
	{
		try{
			if(inArray.items.length > 0)
				this.submenu = true;
			for(var i=0; i<inArray.items.length; i++)
			{
				var name = inArray.items[i].title;
				vwLeftNav.util.createNodeSMenu(name, "menu_"+inArray.items[i].height);
				if(inType == name.split("_")[1].toLowerCase())
				{
					if(inSub == null)
					{
						if(inArray.items[i].expand == true)
							vwLeftNav.menu.animateMenu = true;
						this.serve(name, name+"_active.gif");
						if(inArray.items[i].revealSub)
							this.addSubMenu(inSub, null, inArray.items[i]);
					}
					else if(inArray.items[i].isActive == true)
					{
						this.serveButtonUrl(name, name+"_out.gif", name+"_out.gif", inArray.items[i].url);
						this.addSubMenu(inSub, null, inArray.items[i]);
					}
					else
					{
						this.serve(name, name+"_out.gif");
						this.addSubMenu(inSub, null, inArray.items[i]);
					}
					
				}
				else
					this.serveButtonUrl(name, name+"_out.gif", name+"_over.gif", inArray.items[i].url);
				if(this.submenu == true)
					this.subMenuHeight += inArray.items[i].height;
			}
		}catch(e){}
	},
	animate : function()
	{
		clearInterval(this.menu_timeout);
		// animate menu down
		if(this.submenu)
		{
			myAnimObj = new YAHOO.util.Anim("smenuContainer", {height:{by: this.subMenuHeight}}, 0.7, YAHOO.util.Easing.easeOut);
			myAnimObj.animate();
		}
	},
	//=========================================================================
	// pngpong functions
	serve : function(inName, inImageName)
	{
		pngpong.serve(inName, vwLeftNav.util.getImagePath() + inImageName);
	},
	serveButtonUrl : function(inName, inImage_out, inImage_over, inAction)
	{
		pngpong.serveButtonUrl(inName, vwLeftNav.util.getImagePath() + inImage_out, vwLeftNav.util.getImagePath() + inImage_over, inAction);
	},
	serveButtonPopup : function(inName, inImage_out, inImage_over, inUrl, inParams)
	{
		pngpong.util.addpngButtonPopup(inName, "", vwLeftNav.util.getImagePath() + inImage_out, vwLeftNav.util.getImagePath() + inImage_over, escape(inUrl), inParams);
	}
}
//=============================================================================
// UTILITY FUNCTIONS
//=============================================================================
vwLeftNav.util = 
{
	setContainer : function(inContainer)
	{
		this.container = inContainer;
	},
	getContainer : function()
	{
		return this.container;
	},
	createNode : function(inIdName, inClassName)
	{
		util.createNode(this.getContainer(), inIdName, inClassName);
	},
	createNodeSMenu : function(inIdName, inClassName)
	{
		util.createNode("smenuContainer", inIdName, inClassName);
	},
	setImagePath : function(inLang, inCountry)
	{
		this.imagePath = "/global/images/hybridPages/"+vwLeftNav.data.rootFolder+"/"+inLang+"/"+inCountry+"/";
	},
	getImagePath : function()
	{
		return this.imagePath;
	},
	setLangCountry : function(inLang, inCountry)
	{
		this.langCountry = "/"+inLang+"/"+inCountry+"/";
	},
	getLangCountry : function()
	{
		return this.langCountry;
	},
	getClass : function(inIndex)
	{
		return "menu_"+vwLeftNav.data.nav[inIndex].height;
	}
}
//=============================================================================
// TOOLTIP FUNCTIONS
//=============================================================================
vwLeftNav.tooltip =
{
	add : function(inName)
	{
		try{
			var d = util.getNode(inName);
			d.onmouseover = function()
			{
				vwLeftNav.tooltip.show(inName);
			};
			d.onmouseout = function()
			{
				vwLeftNav.tooltip.hide();
			};
		}catch(e){}
	},
	get : function(inName)
	{
		var tooltip = util.getNode(inName);
		if(tooltip == null)
		{
			util.createNode("body", inName, inName);
			pngpong.serve(inName, "/global/images/comingSoon.jpg");
		}
		var tooltip = util.getNode(inName);
		return tooltip;
	},
	show : function(inTarget)
	{
		try{var tooltip = vwLeftNav.tooltip.get("comingSoon");
		var newX = YAHOO.util.Dom.getX(inTarget)+8;
		var newY = YAHOO.util.Dom.getY(inTarget)-20;
		YAHOO.util.Dom.setX("comingSoon", newX);
		YAHOO.util.Dom.setY("comingSoon", newY);
		util.setStyle("comingSoon", "visibility", "visible");
		util.setStyle("comingSoon_img", "visibility", "visible");}catch(e){}
	},
	hide : function()
	{
		try{util.setStyle("comingSoon", "visibility", "hidden");
		util.setStyle("comingSoon_img", "visibility", "hidden");}catch(e){}
	}
}
//=============================================================================
// TRACE FUNCTIONS
//=============================================================================
vwLeftNav.trace = 
{
	get : function(inName)
	{
		var out = util.getNode(inName);
		if(out == null)
		{
			util.createNode("body", inName, "traceDiv");
			out = util.getNode(inName);
		}
		return out;
	},

	write : function(inStr)
	{
		var out = vwLeftNav.trace.get("traceDiv");
		out.innerHTML += inStr + "<br>";
	},
	clear : function()
	{
		var out = vwLeftNav.trace.get("traceDiv");
		out.innerHTML = "";
	}
}