﻿YAHOO.util.Event.onContentReady("osMenu", function ()
{
	var optionSelectionMenu = new YAHOO.widget.Menu("osMenu", 
		{ 
			context: ["defaultOptionSelection", "tl", "bl"],
			visible: true,
			clicktohide: true
		}
	);

	YAHOO.util.Event.addListener("defaultOptionSelection", "click", optionSelectionMenu.show, null, optionSelectionMenu);
	YAHOO.util.Event.addListener("selectionArrow", "click", optionSelectionMenu.show, null, optionSelectionMenu);
	YAHOO.util.Event.addListener("optionSelectionSelected", "click", optionSelectionMenu.hide, null, optionSelectionMenu);
    
	// Bind escape key to hide menu
	var kl = new YAHOO.util.KeyListener(document, { keys:27 }, { fn:optionSelectionMenu.hide, scope:optionSelectionMenu, correctScope:true } );
	optionSelectionMenu.cfg.queueProperty("keylisteners", kl);
	kl.enable();
	
	optionSelectionMenu.render();
	
	// To stop the flicker effect at the bottom of the containing div
	optionSelectionMenu.hide();
});

function selectVariant(variantID, colorText)
{
    if (variantID != 0)
	{
	    window.document.getElementById("selectedVariant").setAttribute("value", variantID);
	    window.document.getElementById("selectedVariant").setAttribute("title", colorText);
		
	    var defaultOption = document.getElementById("defaultOptionSelection");
	    if(defaultOption != null)
	    {
			defaultOption.style["display"] = "none";
			
			var optionSelectionSelected = document.getElementById("optionSelectionSelected");
			defaultOption.style["display"] = "block";

			var selectedOption = document.getElementById(variantID);
			defaultOption.innerHTML = selectedOption.innerHTML;
			
			window.document.getElementById("osMenu").style["visible"] = "hidden";
			
			if (window.document.getElementById("topOptionalBox") != null)
			{
				fixIE7zIndexBug();
			}
			
			var shipdate_id = "shipdate_" + variantID;
			var availabilityDate = window.document.getElementById(shipdate_id).getAttribute("value");	
			setAvailability(availabilityDate);
		}
		else
		{
			var defaultOption = document.getElementById("secondDropDown");
			if(defaultOption != null && defaultOption.disabled != true)
			{
				for(var i = 1; i < defaultOption.length; i++)
				{
					if(defaultOption.options[i].text.indexOf(colorText) != -1)
					{
						defaultOption.selectedIndex = i;
					}
				}
				
				setAvailabilityPMO();
			}
		}
	 }
}

function setAvailability (availability)
{
	window.document.getElementById('availability').innerHTML = availability;
}

function SetColorDesc(colorDesc) //Onclick make the desc stay
{	
	var colorDescObj = document.getElementById("availableColorDesc");
	
	if (colorDesc != "" && colorDescObj != null)
	{
		colorDescObj.innerHTML = "Available Colors (" + colorDesc + ")";
	}
}

