/* ------------------------------------------------------------------------------- +

	File:		custom.js
	Author:		Ben Nadel
	Date:		February 05, 2005
	Desc:		These are functions that are custom to this application and no
				where else.

+ ------------------------------------------------------------------------------- */

// Set up drop down menus object to hold important data
var DropDownMenus = new Object();
DropDownMenus.Interval = null;
DropDownMenus.NavItems = new Array("AboutUs", "OnlineCatalog", "NewReleases", "CustomerService", "OurProducts", "ContactUs", "ShoppingCart");
DropDownMenus.Selects = new Object();

function fixTransItem(cl) {
	var transImg = ENV.WebRoot + 'x.gif';
	$('.' + cl).supersleight({shim: transImg});
 }

// This sets up the select menu exceptions for the page
function SetSelectCompatibility(strMenuName){
	var arrSettings = new Array();
	
	for (var i = 1 ; i < arguments.length ; i++){
		arrSettings[arrSettings.length] = arguments[i];
	}

	// Check to see if we have any settings
	if (arrSettings.length > 0){
		DropDownMenus.Selects[ strMenuName ] = arrSettings;
	}
}


// This gets called when the global nav or its menu get moused over
function GnavOver(strNavName){
	// First, clear the timer
	clearInterval(DropDownMenus.Interval);

	// Next thing we want to do on the mouse over is clear everything 
	// that's not this name
	for (var i = 0 ; i < DropDownMenus.NavItems.length ; i++){
		if (DropDownMenus.NavItems[i] != strNavName){
			// This is not our item, so close it
			CloseNavButton(DropDownMenus.NavItems[i]);
			CloseNavMenu(DropDownMenus.NavItems[i]);
		}
	}

	// Open current nav item
	OpenNavButton(strNavName);
	OpenNavMenu(strNavName);
	fixTransItem('fixtransitem_extended');
}


// This gets called when the global nav or its menu get mouse out of. 
// At this point, we have to close the menu, but we don't want to do
// it right away as that will be too fast. We must but a small delay
// on it.
function GnavOut(strNavName){
	// Set the interval
	DropDownMenus.Interval = setInterval("DoGnavOut('" + strNavName + "')", 100);
}


function DoGnavOut(strNavName){
	// First, clear the timer
	clearInterval(DropDownMenus.Interval);
	
	// Close the button
	CloseNavButton(strNavName);
	
	// Close the menu
	CloseNavMenu(strNavName);
	
	fixTransItem('fixtransitem_extended');
}


// This opens up the given nav button
function OpenNavButton(strNavName){
	document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_on").src;
	//alert("img" + strNavName + "_on");
}


// This opens up the given nav menu item
function OpenNavMenu(strNavName){
	//fixTransItem('fixtransitem_extended');
	var objMenu = document.getElementById("Menu" + strNavName);
	
	if (objMenu){
		// Hide any needed select menus
		if (DropDownMenus.Selects["Menu" + strNavName] != null){
			for (var i = 0 ; i < DropDownMenus.Selects["Menu" + strNavName].length ; i++){
				DropDownMenus.Selects["Menu" + strNavName][i].style.visibility = "hidden";
			}
		}
	
		objMenu.style.visibility = "visible";
	}
}


// This closes the given nav button
function CloseNavButton(strNavName){
	// We only want to close the button if we are NOT in this section
	if ((strNavName == "AboutUs") && (ENV.PG != "about_us")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "OurProducts") && (ENV.PG != "our_products")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "NewReleases") && (ENV.PG != "new_releases")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "OnlineCatalog") && (ENV.PG != "monthly_awareness")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	//} else if ((strNavName == "ContactUs") && (ENV.PG != "contact_us")){
		//document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "ShoppingCart") && (ENV.PG != "shopping_cart")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "CustomerService") && (ENV.PG != "customer_service")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	//} else if ((strNavName == "FocusOn") && (ENV.PG != "focus_on")){
		//document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} else if ((strNavName == "OnlineCatalogBot") && (ENV.PG != "online_catalog")){
		document.images["Gnav" + strNavName].src = eval("img" + strNavName + "_off").src;
	} 
}


// This closes the given nav menu item 
function CloseNavMenu(strNavName){
	//fixTransItem('fixtransitem_extended');
	var objMenu = document.getElementById("Menu" + strNavName);
	
	if (objMenu){
		// Hide any needed select menus
		if (DropDownMenus.Selects["Menu" + strNavName] != null){
			for (var i = 0 ; i < DropDownMenus.Selects["Menu" + strNavName].length ; i++){
				DropDownMenus.Selects["Menu" + strNavName][i].style.visibility = "visible";
			}
		}
		
		objMenu.style.visibility = "hidden";
	}
}

function showDiv(div, lin){
	if(div.style.display == "block") {
		div.style.display = "none";
		document.getElementById(lin.id).setAttribute("class", "");
	} else {
		div.style.display = "block";
		document.getElementById(lin.id).setAttribute("class", "active");
		var i=1;
		for (i=1; i <= 14; i++) {
			if(div.id != 'sub'+i){ 
				document.getElementById("sub"+i).style.display = "none"; 
				document.getElementById("link"+i).setAttribute("class", ""); 
			}
		}
	}
}
