/*menuDropdown.js - implements a dropdown menu based on an HTML list*/

var currentCategory = null;
var currentMenu = null;
var timerID = null
var timerRunning = false

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, categoryId) {
    var menu = document.getElementById(menuId);
    var category = document.getElementById(categoryId);

    if (menu == null || category == null) return;

    category.onmouseover = function() {
	if (currentMenu != null) {
		stopTimer();
		hideMenu();
	}
	this.showMenu();
	if (currentCategory.id != strparentcategory) {
		currentCategory.className = "categoryover";
	}
    }

    category.onmouseout = function() {
        startTimer();
    }

    menu.onmouseover = function() {
		stopTimer();
    }

    menu.onmouseout = function() {
    	startTimer();
    }

    category.showMenu = function() {
        menu.style.visibility = "visible";
		currentCategory = category;
    	currentMenu = menu;
    }
}

function startTimer()
{
    stopTimer();
    runTimer();
}

function stopTimer()
{
    if(timerRunning) {
        clearTimeout(timerID);
    	timerRunning = false
    }
}

function runTimer()
{
	timerRunning = true;
	timerID = setTimeout("hideMenu()",250);
}

function hideMenu() {
	if (currentCategory.id != strparentcategory) {
		currentCategory.className="category";
	}
        currentMenu.style.visibility = "hidden";
        currentMenu = null;
    }

var strparentcategory = getparentcategory();

function getobj(name) {
	if (document.getElementById(name)) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
}

function getparentcategory() {
	var url = window.location;
	var urlstring = String(url);

	if (urlstring.indexOf("categorylist")>0) {
		return "productcategory";
	}
	else if (urlstring.indexOf("resources")>0) {
		return "resourcescategory";
	}
	else {
		return -1;
	}
}

function styleparentcategory() {
    if	(!document.layers) {
		if (strparentcategory!=-1) {
			var x = new getobj(strparentcategory + "li");
			var y = new getobj(strparentcategory);
			if (x) {
				y.obj.className="categoryselected";
			}
		}
	}
}
