var active_menu      = 0;
var active_menu_disp = 0;
var active_nav_id    = 0;
var active_nav_name  = '';
var active_siteroot = '';

var IE50 = (navigator.appVersion.indexOf('MSIE 5.0')>-1 ? true : false);

/*
function imageswap(name)
{
	var x = document.getElementById(name);
	var y = document.getElementById(name+'-over');

	var z = x.src;
	x.src = y.src;
	y.src = z;
}
*/

// Toggle button mouse-over graphic on and off...
function navon(id, name, siteroot)
{
	if( active_nav_id!=0 )
	{
		navoff( active_nav_id, active_nav_name, siteroot);
	}

	active_nav_name = name;
	active_nav_id   = id;
	active_siteroot = siteroot;

	document.images['img-' + id].src=siteroot + 'Images/nav-' + name + '-over.gif';
}

function navoff(id, name, siteroot)
{
	active_siteroot = siteroot;

	document.images['img-' + id].src=siteroot + 'Images/nav-' + name + '.gif';
}

// Toggle submenus on and off..
function menuon(submenu_id)
{
	if (active_menu > 0)
	{
		menuoff(active_menu);
	}

	active_menu = submenu_id;

//	alert( "version="+navigator.appVersion );

	if (submenu_id != 0)
	{
		submenu = document.getElementById('submenu' + submenu_id);
		style = submenu.style;

		// IE5.0 doesn't work with visibility alone...
		if (IE50)
		{
			style.display = 'block';
		}

		style.visibility = 'visible';

		blocker = document.getElementById('blocker' + submenu_id).style;

		if (IE50)
		{
			blocker.display = 'block';
		}

		blocker.visibility = 'visible';
		blocker.height = submenu.offsetHeight + "px";
	}
}

function menuoff(submenu_id)
{
	if (submenu_id != 0)
	{
		style = document.getElementById('submenu' + submenu_id).style;

		// IE5.0 doesn't work with visibility alone...
		if (IE50)
		{
			style.display = 'none';
		}

		style.visibility = 'hidden';

		blocker = document.getElementById('blocker' + submenu_id).style;

		// IE5.0 doesn't work with visibility alone...
		if (IE50)
		{
			blocker.display = 'none';
		}

		blocker.visibility = 'hidden';
	}
}

loadImage = new Object;

function loadImg(filename)
{
	if( !document.images )
	{
		alert( "No Images!" );
		return( null );
	}

	if( !loadImage[filename] )
	{
		loadImage[filename]     = new Image;
		loadImage[filename].src = filename;
	}

	return( loadImage[filename].src );
}

// Timed menu hiding...
var timer_id;
var timer_menu_id;
var timer_menu_name;

function timerstart( id, name, siteroot )
{
	timer_menu_id = id;
	timer_menu_name = name;
	active_siteroot = siteroot;

	timer_id = setTimeout( 'timeractivate()', 50 );

	return;
}

function timercancel()
{
	if( timer_id!=0 )
	{
		clearTimeout( timer_id );
		timer_id = 0;
	}

	return;
}

function timeractivate()
{
	navoff( timer_menu_id, timer_menu_name, active_siteroot );
	menuoff( timer_menu_id );

	timercancel();

	return;
}


function saveHTML(theFrame,theField)
{
	code = theFrame.contentWindow.document.body.innerHTML;
	theField.value = code;
	return( "" );
}

function domRollover()
{
	if (navigator.userAgent.match(/Opera (\S+)/))
	{
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}

	if (!document.getElementById || operaVersion < 7)
	{
		return;
	}

	var imgarr = document.getElementsByTagName('img');
	var imgPreload = new Array();
	var imgSrc = new Array();
	var imgClass = new Array();

	for (i = 0; i < imgarr.length; i++)
	{
		if (imgarr[i].className.indexOf('domroll') != -1)
		{
			imgSrc[i] = imgarr[i].getAttribute('src');
			imgClass[i] = imgarr[i].className;
			imgPreload[i] = new Image();

			if (imgClass[i].match(/domroll (\S+)/))
			{
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}

			imgarr[i].setAttribute('xsrc', imgSrc[i]);

			imgarr[i].onmouseover = function()
			{
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}

			imgarr[i].onmouseout = function()
			{
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}