var subMenuHeight = new Array();


// A cascading menu script by Fredrik Fridsten 2000 (c)
// Feel free to use this, but please mention in a comment in the code.

// Original Script can be found at: http://www.fridsten.se/
// Modified extensively by Heartland Business Systems http://www.hbs.net
// Portions of original code also found in nav.css

// Compatible with NN4+, IE5+, Opera, Omniweb, Safari, Mozilla and derivatives
// Thanks to Fredrick Fridstein for this easy to read, easy to use, wonderfully cross browser compatible script

// To configure the script:
// Change the nom value to the number of menus that you want to use
// Note: Always make sure that this is correct, otherwise you might get a javascript error.

// The phrases "images/opened.gif" and "images/closed.gif" should be referring to the
// pictures you might use.
// If you don't want to use images, just remove the mainIndOn and mainIndOff functions.
// Also remove the lines in the toggle function that refer to those.

// The input variables to the toggle function are the number of the submenu to open/close,
// starting with 1, and the number of pixels to move the objects below.
// For example toggle(2,60) opens/closes the second submenu and moves the objects below 60 pixels.

var nom = 7; // Number of menus
var currSub = 0; //-- added
var currMMTect = 0; //-- added
var contentSec = 'content';  //-- added

var secs = new Array(); // An array for the secle objects // -- Original
var subs = new Array(); // An array for the submenu objects // -- Original
var lastn; // -- Original
var lastmove; // -- Original
var isIE4; // -- Original
var isNav4; // -- Original
var isNav6; // -- Original
var re = new RegExp('px'); // -- Original

function setbrowser() { // -- Original
	if (navigator.appVersion.charAt(0) == "4") {
		if (navigator.appName.indexOf("Explorer") >= 0) {
			isIE4 = true;
		}
		else {
			isNav4 = true;
		}
	}
	else if (navigator.appVersion.charAt(0) > "4") {
		isNav6 = true;
	}
	if (isNav4) { // Setting the visibility for NN and IE
		visible = 'show';
		hidden = 'hide';
	}
	else if (isIE4) {
		visible = 'visible';
		hidden = 'hidden';
	}
	else if (isNav6) {
		visible = 'visible';
		hidden = 'hidden';
	}
}

for (var i = 1; i <= nom; i++) { // Fills the arrays with secle and submenu objects // -- Original
	subs[i] = ('submenu' +i);
}

// A couple of small functions that changes the image by the clicked menu
// Tertiary (Third Level) Nav indicator scripts -- added
function terIndOff(image) 
{	
	imgName = "tm_ind_" + image;
	var sec = contentSec;

	if (isNav4) {
		document.layers[sec].document.images[imgName].src =  SITEPREFIX + "/framework/gfx/nav/side/ind/off.gif";
	}
	else if (isIE4) {
		document.all(imgName).src =  SITEPREFIX + "/framework/gfx/nav/side/ind/off.gif";
	}
	else if (isNav6) {
		document.getElementById(imgName).src =  SITEPREFIX + "/framework/gfx/nav/side/ind/off.gif";
	}

}

function terIndOn(image) 
{
	imgName = "tm_ind_" + image;
	var sec = contentSec;

	if (isNav4) {
		document.layers[sec].document.images[imgName].src =  SITEPREFIX + "/framework/gfx/nav/side/ind/on.gif";
	}
	else if (isIE4) {
		document.all(imgName).src =  SITEPREFIX + "/framework/gfx/nav/side/ind/on.gif";
	}
	else if (isNav6) {
		document.getElementById(imgName).src =  SITEPREFIX + "/framework/gfx/nav/side/ind/on.gif";
	}

}

// Secondary (Submenu Level) Nav indicator scripts -- added
function subIndOff(image) 
{	
	imgName = "sm_ind_" + image;
	var sec = "submenu" + currSub;

	if (isNav4) {
		document.layers[sec].document.images[imgName].src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/off.gif";
	}
	else if (isIE4) {
		document.all(imgName).src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/off.gif";
	}
	else if (isNav6) {
		document.getElementById(imgName).src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/off.gif";
	}
}

function subIndOn(image) 
{
	imgName = "sm_ind_" + image;
	var sec = "submenu" + currSub;

	if (isNav4) {
		document.layers[sec].document.images[imgName].src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/on.gif";
	}
	else if (isIE4) {
		document.all(imgName).src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/on.gif";
	}
	else if (isNav6) {
		document.getElementById(imgName).src =  SITEPREFIX + "/framework/gfx/nav/sub/ind/on.gif";
	}
}

// Main (Main Menu Level) Nav indicator scripts -- modified from original
function mainIndOn() 
{	
	var sec = "mainMenu";
	var down = "mm_ind_" + currSub;
	
	if (isNav4) {
		document.layers[sec].document.images[down].src =  SITEPREFIX + "/framework/gfx/nav/main/ind/here.gif";
	}
	else if (isIE4) {
		document.all(down).src =  SITEPREFIX + "/framework/gfx/nav/main/ind/here.gif";
	}
	else if (isNav6) {
		document.getElementById(down).src =  SITEPREFIX + "/framework/gfx/nav/main/ind/here.gif";
	}
}

function mainTxtOn(imgName) 
{	
	if ( !imgName )
	{
		imgName = currMMText;
	}
	var sec = "mainMenu";
	var txtImg = "mm_txt_" + imgName;

	if (isNav4) {
		document.layers[sec].document.images[txtImg].src =  SITEPREFIX + "/framework/gfx/nav/main/txt/on/" + imgName + ".gif";
	}
	else if (isIE4) {
		document.all(txtImg).src =  SITEPREFIX + "/framework/gfx/nav/main/txt/on/" + imgName + ".gif";
	}
	else if (isNav6) {
		document.getElementById(txtImg).src =  SITEPREFIX + "/framework/gfx/nav/main/txt/on/" + imgName + ".gif";
	}
}

function mainIndOff() 
{
	var sec = "mainMenu";
	var down = "mm_ind_" + currSub;

	if (isNav4) {
		document.layers[sec].document.images[down].src =  SITEPREFIX + "/framework/gfx/nav/main/ind/on.gif";
	}
	else if (isIE4) {
		document.all(down).src =  SITEPREFIX + "/framework/gfx/nav/main/ind/on.gif";
	}
	else if (isNav6) {
		document.getElementById(down).src =  SITEPREFIX + "/framework/gfx/nav/main/ind/on.gif";
	}
}

function mainTxtOff(imgName) 
{	
	if ( !imgName )
	{
		imgName = currMMText;
	}
	var sec = "mainMenu";
	var txtImg = "mm_txt_" + imgName;
	
	if (isNav4) {
		document.layers[sec].document.images[txtImg].src =  SITEPREFIX + "/framework/gfx/nav/main/txt/off/" + imgName + ".gif";
	}
	else if (isIE4) {
		document.all(txtImg).src =  SITEPREFIX + "/framework/gfx/nav/main/txt/off/" + imgName + ".gif";
	}
	else if (isNav6) {
		document.getElementById(txtImg).src =  SITEPREFIX + "/framework/gfx/nav/main/txt/off/" + imgName + ".gif";
	}
}
// The main script for toggling the selected menu
// Input variables:
// n = the number of the submenu to show/hide
// move = the number of pixels for moving the objects below

lastn = (nom + 1);
lastmove = 0;

function lasttoggle(n,move) // -- Modified
{

	if (n <= nom) {
		menu = ('submenu' + n);
		if (isNav4) {
			submenu = document.layers[menu];
		}
		else if (isIE4) {
			submenu = document.all(menu).style;
		}
		else if (isNav6) {
			submenu = document.getElementById(menu).style;
		}
		
		if (submenu.visibility.toLowerCase() == visible) 
		{
			submenu.visibility = hidden;
			mainIndOff(); // Remove this if you don't use pictures
			mainTxtOff(); // Remove this if you don't use pictures
			
			if (isNav4) {
				var sec = document.layers[contentSec];
			}
			else if (isIE4) {
				var sec = document.all(contentSec).style;
			}
			else if (isNav6) {
				var sec = document.getElementById(contentSec).style;
			}
						
			var tmpsec = parseInt(sec.top);
			
			if (isNav4) {
				sec.top = (tmpsec - move);
			} else {
				sec.top = (tmpsec - move) + "px";
			}
		}
	}
}

function toggle(n,move,imgName) // -- Modified
{
	
	if (lastn != n) {
		lasttoggle(lastn,lastmove);
	}
	currSub = n;
	currMMText = imgName;
	
	//alert(lastn);

	if ( lastn != currSub )
	{	
		var menu = 'submenu' + n;
		if (isNav4) {
			submenu = document.layers[menu];
		}
		else if (isIE4) {
			submenu = document.all(menu).style;
		}
		else if (isNav6) {
			submenu = document.getElementById(menu).style;
		}

		//alert(submenu);

		if (submenu.visibility.toLowerCase() == visible) {
			submenu.visibility = hidden;
			mainIndOff(); // Remove this if you don't use pictures
			mainTxtOff(); // Remove this if you don't use pictures
			
			if (isNav4) {
				var sec = document.layers[contentSec];
			}
			else if (isIE4) {
				var sec = document.all(contentSec).style;
			}
			else if (isNav6) {
				var sec = document.getElementById(contentSec).style;
			}
			
			var tmpsec = parseInt(sec.top);

			if (isNav4) {
				sec.top = (tmpsec - move);
			} else {
				sec.top = (tmpsec - move) + "px";
			}			
		}
		else {
			submenu.visibility = visible;
			mainIndOn(); // Remove this if you don't use pictures
			mainTxtOn(); // Remove this if you don't use pictures
			
			if (isNav4) {
				var sec = document.layers[contentSec];
			}
			else if (isIE4) {
				var sec = document.all(contentSec).style;
			}
			else if (isNav6) {
				var sec = document.getElementById(contentSec).style;
			}
			
			var tmpsec = parseInt(sec.top);
			
			if (isNav4) {
				sec.top = (tmpsec + move);
			} else {
				sec.top = (tmpsec + move) + "px";
			}		
		}
		lastn = n;
		lastmove = move;

	}
}

function init() { // -- Modified
	setbrowser();
}

function closeMenus()  // -- added
{
	if ( currSub != "0" ) 
	{
		lasttoggle(currSub,lastmove);
		currSub = 0;
		lastn = (nom + 1);
		lastmove = 0;
	}
 }