YAHOO.namespace("valvoline");

YAHOO.valvoline.homepage = 
	function () {
		var yue = YAHOO.util.Event, yud = YAHOO.util.Dom;
	
		var statusOne = 0, statusTwo = 0, statusThree = 0, statusFour = 0, statusFive = 0, statusSix = 0;
		
		var firstPanel = new YAHOO.widget.Panel("productLayerOne", {
			width:"530px", height:"173px", fixedcenter: false, x:20, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		var secondPanel = new YAHOO.widget.Panel("productLayerTwo", {
			width:"530px", height:"173px", fixedcenter: false, x:60, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		var thirdPanel = new YAHOO.widget.Panel("productLayerThree", {
			width:"530px", height:"173px", fixedcenter: false, x:100, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		var fourthPanel = new YAHOO.widget.Panel("productLayerFour", {
			width:"530px", height:"173px", fixedcenter: false, x:140, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		var fifthPanel = new YAHOO.widget.Panel("productLayerFive", {
			width:"530px", height:"173px", fixedcenter: false, x:180, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		var sixthPanel = new YAHOO.widget.Panel("productLayerSix", {
			width:"530px", height:"173px", fixedcenter: false, x:220, y:160, 
			constraintoviewport: false, underlay:"shadow", close:false, visible:false, draggable:false } );
		
		var getPopupItems = function () {
			var aListItems = yud.getElementsByClassName("popuplayer");
			return aListItems;
		};
	
		var getProductLinks = function() {
			var aProductLinkItems = yud.getElementsByClassName("productlink");
			return aProductLinkItems;
		}; 
		
		var failureHandler = function() {};
		
	return  {
	
		// Public methods, format example: YAHOO.valvoline.mast.init()
		init: function () {
			// Render all the pop-up layers
			firstPanel.render(); secondPanel.render(); thirdPanel.render();
			fourthPanel.render(); fifthPanel.render(); sixthPanel.render();
			
			// Set the 'display' CSS style with 'block'.
			// We have JavaScript! Let's change some CSS styles to render the pages properly for JavaScript enabled users
			var items = getPopupItems();
			for (var i=0, j=items.length; i<j; i++) {
				yud.setStyle(items[i], "display", "block");
			}
			
			// We have JavaScript! Let's void all hard-coded links in the products menu and enable our pop-up layer presentation
			var productItems = getProductLinks();
			for (var i=0, j=productItems.length; i<j; i++) {
				productItems[i].href = "javascript:void(0);";
			}
			
		},
		hideAllPanels: function () {
			// Hide all the pop-up layers from view
			firstPanel.hide(); secondPanel.hide(); thirdPanel.hide();
			fourthPanel.hide(); fifthPanel.hide(); sixthPanel.hide();
			
		},
		
		renderPanel: function (layer) {
			this.hideAllPanels();
			
			// If a pop-up layer is already displayed, then a second click on the product will hide the pop-up layer
			if( layer=='one' && statusOne==0) { firstPanel.show(); statusOne=1; } else { firstPanel.hide(); statusOne=0; }
			if( layer=='two' && statusTwo==0) { secondPanel.show(); statusTwo=1; } else { secondPanel.hide(); statusTwo=0; }
			if( layer=='three' && statusThree==0) { thirdPanel.show(); statusThree=1; } else { thirdPanel.hide(); statusThree=0; }
			if( layer=='four' && statusFour==0) { fourthPanel.show(); statusFour=1; } else { fourthPanel.hide(); statusFour=0; }
			if( layer=='five' && statusFive==0) { fifthPanel.show(); statusFive=1; } else { fifthPanel.hide(); statusFive=0; }
			if( layer=='six' && statusSix==0) { sixthPanel.show(); statusSix=1; } else { sixthPanel.hide(); statusSix=0; }
			return(0);
		}
		
	};
		
}();

YAHOO.valvoline.necessary = 
	function () {
		//private members and methods
		var yue = YAHOO.util.Event, yud = YAHOO.util.Dom;
		/*
		var flashMovieLocation = "/media/flash/homepage/index.swf";
		var flashWidth = "770";
		var flashHeight = "430";
		var flashBackgroundColor = "#000000";
		var flashExpressInstall = "/media/flash/swfobject/expressinstall.swf"
		var flashMainBox = "flashcontent";
		var flashVersion = "8";
		
		// setup for SWFObject for main flash area
		var so = new SWFObject(flashMovieLocation, "homepage", flashWidth, flashHeight, flashVersion, flashBackgroundColor);
		so.addVariable("xmlPath", "/include/criticalmass/data");
		so.addVariable("imagePath", "/media/flash/homepage/components");
		so.addVariable("cssPath ", "/media/flash/homepage/css");
		*/
		// setup for SWFObject for video player box
		var video = new SWFObject("/media/flash/homepage/small_video_player.swf", "videobox", "220", "180", "8", "#FFFFFF");
		video.addVariable("flvFilename", "/video/commercials/nhra_highlights.flv");
		
		var racingRssHandler = function(o) {
			var racingNewsWidget = yud.getElementsByClassName("widgetOne");
			var racingRoot = o.responseXML.documentElement;
			var racingDescription = racingRoot.getElementsByTagName('description')[1].firstChild.nodeValue;
			var racingTitle = racingRoot.getElementsByTagName('title')[1].firstChild.nodeValue;
			var racingLink = racingRoot.getElementsByTagName('link')[1].firstChild.nodeValue;
			var racingNews = '/pages/racing/nascar_news.asp';
			
			racingNewsWidget[0].innerHTML =
				'<h1><a class="widgetLinkOne" href="' + racingNews + '">RACING NEWS &#187;</a></h1>' +
				'<p>' + racingDescription + '</p>' +
				'<ul class="additionallinks">' +
				'<li><a class="one" href="' + racingLink + '">Read Story</a></li>' +
				'<li><a class="two" href="' + racingNews + '">See More Racing News</a></li>' +
				'</ul>';
		};
		
		var failureHandler = function() {};
	
	return  {
	
		// Public methods, format example: YAHOO.valvoline.homepage.init()
		init: function () {			
			// Use SWFObject to render the flash movie, or trigger the Express Install for users without flash
			//so.useExpressInstall(flashExpressInstall);
			//so.write(flashMainBox);
			
			video.useExpressInstall(flashExpressInstall);
			if(document.getElementById('videobox')){
			video.write("videobox");
			}
			var sUrl = '/rss/racing.asp';
			var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, { success:racingRssHandler, failure:failureHandler }); 
			
      document.getElementById("flashcontent").style.visibility="visible";	
		}

	};
	
}();
