﻿_PFX = 'ctl00_C_';

Window_OnLoad =
	function() 
	{
		var imgs = document.getElementsByTagName('img');
		for (var i=0;i<imgs.length;i++)
		{
			if (DDI.Web.GetAttribute('string',imgs[i],'hsrc','').length > 0)
			{
				var x = new DDI.Web.ImageButton(imgs[i].id);
			}
		}

		AutoHover_OnLoad();

		if (YAHOO.util.Dom.inDocument('TickerPanel')) YAHOO.snippet.ticker.init("newsTicker");

		PopupMenus_Init('HomePopupMenus');
	}
	
YAHOO.util.Event.addListener(window, 'load', Window_OnLoad);

AutoHover_OnLoad =
	function()
	{
		// activate any autohover images within the content

		var autoHoverImages = YAHOO.util.Dom.getElementsByClassName('autohover', 'img');
		if (autoHoverImages.length > 0) 
		{
			for (var i=0; i<autoHoverImages.length; i++)
			{
				YAHOO.util.Dom.generateId(autoHoverImages[i]);
				autoHoverImages[i].setAttribute('nsrc', autoHoverImages[i].src);
				autoHoverImages[i].setAttribute('hsrc', autoHoverImages[i].src.replace(/\.gif/, '_hover.gif').replace(/\.jpg/, '_hover.jpg').replace(/\.png/, '_hover.png'));
				var x = new DDI.Web.ImageButton(autoHoverImages[i].id);
			}
		}
	}

Go_OnClick =
	function() 
	{
		document.search.submit();
	}

PopupMenus_Init = 
	function(divId) 
	{

		// Animation object
		var oAnim;

		// Utility function used to setup animation for submenus

		function setupMenuAnimation(p_oMenu) {

			if(!p_oMenu.animationSetup) {

				var aItems = p_oMenu.getItemGroups();

				if(aItems && aItems[0]) {

					var i = aItems[0].length - 1;
					var oSubmenu;

					do {

						oSubmenu = p_oMenu.getItem(i).cfg.getProperty("submenu");

						if(oSubmenu) {

							oSubmenu.beforeShowEvent.subscribe(onMenuBeforeShow, oSubmenu, true);
							oSubmenu.showEvent.subscribe(onMenuShow, oSubmenu, true);

						}
	                
					}
					while(i--);
	            
				}

				p_oMenu.animationSetup = true;

			}

		}


		// "beforeshow" event handler for each submenu of the menu bar

		function onMenuBeforeShow(p_sType, p_sArgs, p_oMenu) {

			if(oAnim && oAnim.isAnimated()) {
	        
				oAnim.stop();
				oAnim = null;
	        
			}

			YAHOO.util.Dom.setStyle(this.element, "overflow", "hidden");
			YAHOO.util.Dom.setStyle(this.body, "marginTop", ("-" + this.body.offsetHeight + "px"));

		}


		// "show" event handler for each submenu of the menu bar

		function onMenuShow(p_sType, p_sArgs, p_oMenu) {

			oAnim = new YAHOO.util.Anim(
				this.body, 
				{ marginTop: { to: 0 } },
				.25, 
				YAHOO.util.Easing.easeOut
			);

			oAnim.animate();

			var me = this;
	            
			function onTween() {

				me.cfg.refireEvent("iframe");
	        
			}

			function onAnimationComplete() {

				YAHOO.util.Dom.setStyle(me.body, "marginTop", ("0px"));
				YAHOO.util.Dom.setStyle(me.element, "overflow", "visible");

				setupMenuAnimation(me);

			}
	        

			/*
				 Refire the event handler for the "iframe" 
				 configuration property with each tween so that the  
				 size and position of the iframe shim remain in sync 
				 with the menu.
			*/

			if(this.cfg.getProperty("iframe") == true) {

				oAnim.onTween.subscribe(onTween);

			}

			oAnim.onComplete.subscribe(onAnimationComplete);
	    
		}


		// "render" event handler for the menu bar

		function onMenuRender(p_sType, p_sArgs, p_oMenu) {

			setupMenuAnimation(p_oMenu);

		}


		// Instantiate and render the menu bar

		var oMenuBar = new YAHOO.widget.MenuBar(divId, { autosubmenudisplay:true, submenuhidedelay: 100, showdelay: 100, hidedelay:100, lazyload:true });


		// Subscribe to the "render" event

		oMenuBar.renderEvent.subscribe(onMenuRender, oMenuBar, true);
		oMenuBar.render();

	};

