// JavaScript Document
var currentTags = new Array();
var currentDivs = new Array();
/*var nav_timeoutTime = 250;*/
var nav_timeoutTime = 1000;
var nav_timeout = -1;
var num_panels = 3;

/*window.onload = function ()
{
    var elm = document.getElementById(sub_3_0);
    if (elm) {
        elm.style.display = "none";
    }
}*/

function overMain(numID, level)
{
	clearTimeout(nav_timeout);
	 
	while (currentTags.length) dehighlight(currentTags.pop());	
	currentTags.push("main"+numID);
	
	while (currentDivs.length) hideDiv(currentDivs.pop());
	currentDivs.push("sub_"+level+"_"+numID);
	
	showDiv("subpanel_1");
	hideDiv("subpanel_2");
	hideDiv("subpanel_3");
	
	updateMenu();
}

function outMain()
{
	clearTimeout(nav_timeout);
	nav_timeout = setTimeout("menu_reset()", nav_timeoutTime);
}

function menu_reset()
{
	for (i = 0; i < currentTags.length; i++) dehighlight(currentTags[i]);
	for (j = 0; j < currentDivs.length; j++) hideDiv(currentDivs[j]);
	
	hideDiv("subpanel_1");
	hideDiv("subpanel_2");
	hideDiv("subpanel_3");
}

function overSub(numID, level, pid)
{
	/*added bit for swaping-loading thumbnails*/
	if (level > 2){
		switch_image(numID);
	}
	
	clearTimeout(nav_timeout);
	
	while (currentTags.length > level - 1) dehighlight(currentTags.pop());	
	currentTags.push(pid);
	
	while (currentDivs.length > level - 1) hideDiv(currentDivs.pop());
	currentDivs.push("sub_"+level+"_"+numID);
	
	for (i = num_panels; i > level; i--) hideDiv("subpanel_"+i);
	for (j = 0; j <= level; j++) showDiv("subpanel_"+j);

	
	updateMenu();
}


function updateMenu()
{
	for (i = 0; i < currentTags.length; i++) highlight(currentTags[i]);	
	for (j = 0; j < currentDivs.length; j++) showDiv(currentDivs[j]);

}

function highlight(id)
{
	setTextColor(id, "rgb(255, 153, 0)");
	setBackground(id, "rgb(255, 255, 255)");
	setArrowColor(id, "url(images/arrow_orange.gif)");
}

function dehighlight(id)
{
	if (id.indexOf("main") != -1)
	{
		setTextColor(id, "rgb(255, 255, 255)");
		setBackground(id, "transparent");
		setArrowColor(id, "url(images/arrow_grey.gif)");
	}
	else
	{
		setTextColor(id, "rgb(102, 102, 102)");
		setBackground(id, "rgb(238, 238, 238)");
		setArrowColor(id, "url(images/arrow_grey.gif)");
	}
}

function showSubmenu(id, subpanel)
{
	showDiv(id);
	showDiv(subpanel);
}

function hideSubmenu(id, subpanel)
{
	hideDiv(id)
	hideDiv(subpanel);
}

function showDiv(id)
{
	var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "block";
    }
}

function hideDiv(id)
{
    var elm = document.getElementById(id);
    if (elm) {
        elm.style.display = "none";
    }
}

function setBackground(id, rgbVal)
{
    var elm = document.getElementById(id);
    elm.style.backgroundColor = rgbVal;
}

function setTextColor(id, rgbVal)
{
	var elm = document.getElementById(id);
    elm.style.color = rgbVal;
}

function setArrowColor(id, locimg)
{
    var elm = document.getElementById(id);
    elm.style.backgroundImage = locimg;
}

function gotoUrl(loc)
{
    document.location.href = loc;
}

function returnMain(numID, level)
{
	clearTimeout(nav_timeout);
	 
	while (currentTags.length) dehighlight(currentTags.pop());	
	currentTags.push("main"+numID);
	
	while (currentDivs.length) hideDiv(currentDivs.pop());
	currentDivs.push("sub_"+level+"_"+numID);
	
	hideDiv("subpanel_1");
	hideDiv("subpanel_2");
	hideDiv("subpanel_3");
	
	updateMenu();
}

function overThumbox()
{
	clearTimeout(nav_timeout);
}

function outThumbox()
{
	clearTimeout(nav_timeout);
	nav_timeout = setTimeout("menu_reset()", nav_timeoutTime);
}

function image_open_popup(imgURL)
{
	window.open(imgURL,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=600");
}
