﻿var ImageButtonRootFolder = 'App_Themes/R';
var ImageButtonNormal = '_Hout';
var ImageButtonDisabled = '';
var ImageButtonHighlighted = '_Hover';
var ImageButtonExtension = '.gif';
var imageExploder;
var slideshowImages = new Array();
var slideshowCaptions = new Array();
var slideshowCurrent = 0;
var slideshowTimer = null;
var slideshowDelay = 4000;
var initialLoad = true;
var initialSideHeight = 0;
var initialContentHeight = 0;
var doHeightTweak = true;
var lastSlideShowIndex = 0;
var slideShowDivs = null;
var slideShowOrder;

HomeSlideshow_Init = 
	function()
	{
		slideShowDivs = YAHOO.util.Dom.getElementsByClassName('slideshow', 'div');
		if (slideShowDivs != null && slideShowDivs != undefined && slideShowDivs.length > 0)
		{
			slideShowOrder = new Array(slideShowDivs.length-1);
			var setX = 0;
			var sety = 0;
			for (var i=0; i<slideShowDivs.length; i++)
			{
				slideShowOrder[i] = i;
				YAHOO.util.Dom.generateId(slideShowDivs[i]);
				if (i == 0)
				{
					setX = YAHOO.util.Dom.getX(slideShowDivs[i]);
					setY = YAHOO.util.Dom.getY(slideShowDivs[i]);
				}
				else
				{
					YAHOO.util.Dom.setX(slideShowDivs[i], setX);
					YAHOO.util.Dom.setY(slideShowDivs[i], setY);
					YAHOO.util.Dom.setStyle(slideShowDivs[i], 'display', 'none');
				}
			}
			RandomizeSlides();
			setTimeout('HomeSlideShowTransition()', 4000);
		}
	}

HomeSlideShowTransition =
	function()
	{
		var oldLayer = slideShowDivs[slideShowOrder[lastSlideShowIndex]];
		lastSlideShowIndex++;
		if (lastSlideShowIndex >= slideShowDivs.length) 
		{
			lastSlideShowIndex = 0;
			RandomizeSlides();
		}
		var newLayer = slideShowDivs[slideShowOrder[lastSlideShowIndex]];

		var fadeOut = new YAHOO.util.Anim(oldLayer, {opacity: {to: 0}}, 1);
		var fadeIn = new YAHOO.util.Anim(newLayer, {opacity: {to: 1}}, 1);
		if (lastSlideShowIndex != 0) YAHOO.util.Dom.setStyle(newLayer, 'display', 'block');
		YAHOO.util.Dom.setStyle(newLayer, 'visible', 'visible');

		fadeOut.onComplete.subscribe(function() {
			YAHOO.util.Dom.setStyle(oldLayer, 'visible', 'hidden');
			if (lastSlideShowIndex != 1) YAHOO.util.Dom.setStyle(oldLayer, 'display', 'none');
		});
		fadeOut.animate();
		fadeIn.animate();

		setTimeout('HomeSlideShowTransition()', 10000);

	}
	
RandomizeSlides =
	function()
	{
		slideShowOrder.shift();
		slideShowOrder.sort(RandomOrder);
		slideShowOrder.unshift(0);
	}

RandomOrder = 
	function()
	{
		return (Math.round(Math.random())-0.5); 
	} 
	
Slideshow_Init =
	function()
	{
		var thumbs = YAHOO.util.Dom.getElementsByClassName('CustomerPhoto', 'table');
		for (var i=0; i<thumbs.length; i++)
		{
			var img = thumbs[i].getElementsByTagName('img');
			slideshowCaptions.push(Premier.Web.GetAttribute('string',img[0],'alt',''));
			slideshowImages.push(img[0].src.replace(/thumb/gi, ''));
			YAHOO.util.Event.addListener(img[0], 'click', Slideshow_Override);
		}
		Slideshow_Play();
	}

Slideshow_Auto =
	function()
	{
		slideshowCurrent++;
		if (slideshowCurrent >= slideshowImages.length) slideshowCurrent = 0;
		if (slideshowCurrent < 0) slideshowCurrent = slideshowImages.length-1;
		Slideshow_Show();
		slideshowTimer = setTimeout("Slideshow_Auto()",slideshowDelay);
	}
	
Slideshow_Next =
	function()
	{
		clearTimeout(slideshowTimer);
		Slideshow_Auto();
	}

Slideshow_Override =
	function(e)
	{
		clearTimeout(slideshowTimer);
		var elImage = YAHOO.util.Event.getTarget(e);
		for (var i=0;i<slideshowImages.length; i++)
		{
			if (elImage.src.replace(/thumb/gi, '') == slideshowImages[i]) slideshowCurrent = i-1;
		}
		Slideshow_Auto();
	}
		
Slideshow_Pause = 
	function() 
	{
		clearTimeout(slideshowTimer);
	}

Slideshow_Play = 
	function()
	{
		Slideshow_Show();
		slideshowTimer = setTimeout("Slideshow_Auto()",slideshowDelay);
	}
	
Slideshow_Prev =
	function()
	{
		clearTimeout(slideshowTimer);
		slideshowCurrent -= 2;
		Slideshow_Auto();
	}
	
Slideshow_Show =
	function()
	{
		var elImage = YAHOO.util.Dom.get('SlideshowImage');	
		var elCaption = YAHOO.util.Dom.get('SlideshowCaption');	
		elImage.src = slideshowImages[slideshowCurrent];
		elImage.setAttribute('alt', slideshowCaptions[slideshowCurrent]);
		elCaption.innerHTML = slideshowCaptions[slideshowCurrent];
	}
	
Window_OnLoad = 
	function() 
	{
	
		var elSecondMenu = YAHOO.util.Dom.get('SecondMenu');
		if (elSecondMenu != null) 
		{
			var oMenu = new YAHOO.widget.Menu(
												"SecondMenu", 
												{
													position:"static", 
													hidedelay:750, 
													lazyload:true
												}
											);

			oMenu.render();
		}
		PopupMenus_Init('TopMenu');
		
		var tags = YAHOO.util.Dom.getElementsByClassName('BigTag', 'a');
		for (var i=0;i<tags.length;i++)
		{
			var tag = new Premier.Web.ImageLink(tags[i].id);
		}
		var tags = YAHOO.util.Dom.getElementsByClassName('SmallTag', 'a');
		for (var i=0;i<tags.length;i++)
		{
			var tag = new Premier.Web.ImageLink(tags[i].id);
		}
		var ctl00_SideLocatorLink = new Premier.Web.ImageLink('ctl00_SideLocatorLink');
		var ctl00_InternationalLink = new Premier.Web.ImageLink('ctl00_InternationalLink');
		﻿AutoHover_OnLoad();
		
		var imgs = YAHOO.util.Dom.get('socialr').getElementsByTagName('a');
		for (var i=0;i<imgs.length;i++)
		{
			if (Premier.Web.GetAttribute('string',imgs[i],'imagename','').length > 0)
			{
				if (imgs[i].id.length == 0) YAHOO.util.Dom.generateId(imgs[i]);
				var x = new Premier.Web.ImageLink(imgs[i].id);
			}
		}
		var imgs = YAHOO.util.Dom.get('sociall').getElementsByTagName('a');
		for (var i=0;i<imgs.length;i++)
		{
			if (Premier.Web.GetAttribute('string',imgs[i],'imagename','').length > 0)
			{
				if (imgs[i].id.length == 0) YAHOO.util.Dom.generateId(imgs[i]);
				var x = new Premier.Web.ImageLink(imgs[i].id);
			}
		}
		
		HomeSlideshow_Init();
		if (YAHOO.util.Dom.inDocument('Slideshow')) Slideshow_Init();
		
		// see if the page has any modal thumbnails
		
		var thumbs = YAHOO.util.Dom.getElementsByClassName('ModalThumbnail', 'img');
		if (thumbs.length > 0)
		{
			for (var i=0; i<thumbs.length; i++)
			{
				//YAHOO.util.generateId(thumbs[i]);
				YAHOO.util.Event.addListener(thumbs[i], 'click', ModalThumbnail_Show);
			}
            imageExploder = new YAHOO.widget.Panel('ModalThumbnailViewer',  
													{ 
													width: "390px", 
													fixedcenter: true,
													close: true,
													draggable: true,
													modal: true,
													zindex:100,
													visible: false
													}
													);
            imageExploder.setHeader('<span id=\'ModalThumbnailHeader\'></span>');
            imageExploder.setBody('<img id=\'ModalThumbnailImage\' width=\'370\' height=\'480\' src=\'C/shim.gif\'/>');
            imageExploder.render(document.body);
		}
		
		Window_Standard_OnResize();
		YAHOO.util.Event.addListener(window, 'resize', Window_Standard_OnResize);

		try
		{
			Local_Window_OnLoad();
		}
		catch(e)
		{
		}
	}
	
Window_Standard_OnResize =
	function()
	{
		var elSide = YAHOO.util.Dom.get('Side');
		var elTop = YAHOO.util.Dom.get('Top');
		var elBottom = YAHOO.util.Dom.get('Bottom');
		var elVeryBottom = YAHOO.util.Dom.get('VeryBottom');
		var elContent = YAHOO.util.Dom.get('Content');
		var hackHeight = 11; // I have no idea where 11 is coming from here
		var screenHeight = YAHOO.util.Dom.getViewportHeight() - elTop.offsetHeight - elVeryBottom.offsetHeight;
		var sideHeight = initialSideHeight;
		var contentHeight = initialContentHeight
		var newHeight = 0;

		if (initialLoad)
		{
			sideHeight = elSide.offsetHeight;
			initialSideHeight = elSide.offsetHeight;
			contentHeight = elContent.offsetHeight;
			initialContentHeight = elContent.offsetHeight;
			initialLoad = false;
		}
		
		//alert('Screen ' + screenHeight + ' Content ' + contentHeight + ' Side ' + sideHeight);
		if (contentHeight < sideHeight)
		{
			if (sideHeight < screenHeight)
			{
				//alert('Screen ' + screenHeight + ' Side ' + sideHeight);
				newHeight = screenHeight;
				YAHOO.util.Dom.setStyle(elSide, 'height', newHeight.toString() + 'px');
				sideHeight = elSide.offsetHeight;
				//alert('Screen ' + screenHeight + ' Side ' + sideHeight);
			}
			newHeight -= parseInt(YAHOO.util.Dom.getStyle(elContent, 'padding-top'));
			//if (contentHeight != sideHeight) YAHOO.util.Dom.setStyle(elContent, 'height', newHeight.toString() + 'px');
		}
		else
		{
			screenHeight -= 11;
			if (contentHeight < screenHeight)
			{
				//alert('Screen ' + screenHeight + ' Content ' + contentHeight);
				newHeight = screenHeight - parseInt(YAHOO.util.Dom.getStyle(elContent, 'padding-top'));
				YAHOO.util.Dom.setStyle(elContent, 'height', newHeight.toString() + 'px');
				contentHeight = elContent.offsetHeight;
				//alert('Screen ' + screenHeight + ' Content ' + contentHeight);
			}
			contentHeight += 11;
			if (sideHeight != contentHeight) YAHOO.util.Dom.setStyle(elSide, 'height', contentHeight.toString() + 'px');
		}
		
		// not sure why I need to do thsi part, but I do. try/catch is necessary because IE
		if (doHeightTweak)
		{
			newHeight = elBottom.offsetHeight - 1 - parseInt(YAHOO.util.Dom.getStyle(elBottom, 'padding-top')) - parseInt(YAHOO.util.Dom.getStyle(elBottom, 'padding-bottom'));
			if (YAHOO.env.ua.ie == 0) YAHOO.util.Dom.setStyle(elBottom, 'height', newHeight.toString() + 'px');
		}
	}

	
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();

	};

ModalThumbnail_Show =
	function(e)
	{
		var elSmallImage = YAHOO.util.Event.getTarget(e);
		var elLargeImage = YAHOO.util.Dom.get('ModalThumbnailImage');
		var elImageHeader = YAHOO.util.Dom.get('ModalThumbnailHeader');
		var imageUrl = Premier.Web.GetAttribute('string', elSmallImage, 'alt', '');
		if (imageUrl.length > 0)
		{
			var index = elSmallImage.src.lastIndexOf('/');
			if (index < 0)
			{
				elLargeImage.src = imageUrl;
			}
			else
			{
				elLargeImage.src = elSmallImage.src.substring(0,index+1) + imageUrl;
			}
			elImageHeader.innerHTML = elSmallImage.title;
			imageExploder.show();
		}
	}
	
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(/_out/, '_over'));
				var x = new Premier.Web.Autohover(autoHoverImages[i].id);
			}
		}
	}
	
