var menuPreloadFlag = false;
var loadedImages = new Array();
var browserName = window.navigator.userAgent;

function init()
{
	//	Load header images.
	var nextName;
	var nextIndex;
	for (nextIndex in imageNames)
	{
		nextName = imageNames[nextIndex];
		loadedImages[nextName] = new Array(new Image(), new Image());
		loadedImages[nextName][0].src = rolloverImageDir + nextName + '-off.gif';
		loadedImages[nextName][1].src = rolloverImageDir + nextName + '-over.gif';
	}
	menuPreloadFlag = true;
	
	setBoundaries();
}

function swapImageOn(imageName)
{
	if (document.images && menuPreloadFlag)
		document.images[imageName + 'Image'].src = loadedImages[imageName][1].src;
}

function swapImageOff(imageName)
{
	if (document.images && menuPreloadFlag)
		document.images[imageName + 'Image'].src = loadedImages[imageName][0].src;
}

function mailer(name, domain) {
	if (domain == null || domain == "") domain = 'taniabass.com';
	document.write('<a href="mailto:taniabass@aol.com" target="extpage">email us</a>');
}
//'<a href="mailto:' + name + '@' + domain + '">' + name + '@' + domain + '</a>'

///////////////////////////////
// Dropdown menu functions.
///////////////////////////////

//	Initialize variables.
var undefined; // Used in mouseWatcher(). Necessary for browsers that do not implement "undefined".
var currentMenu = null;
var currentMenuIndex = null;
var menuBoundaries = null;

// Custom for Tania Bass.
var eventHandler = null;
var currentFlyoutImage = null;

function finit() {
	menuOff();
}

function mouseWatcherOn() {
	if (document.layers) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove = mouseWatcher;
}

function mouseWatcher(e) {
	if (!e) e = window.event;
	var minx, miny, maxx, maxy;

	//	Custom for Tania Bass.
	eventHandler = e;

	//	pageX is a document coordinate.
	// This is implemented by Netscape 4 and Safari.
	if (e.pageX) {
		minx = e.pageX;
		miny = e.pageY;
		maxx = e.pageX;
		maxy = e.pageY;	
	}
	//	clientX is a window coordinate.
	// Level 2 DOM Event Module: Netscape 6+, Mozilla
	//	Safari has clientX, but it acts like pageX - as a document coordinate.
	else if (document.addEventListener) {
		minx = e.clientX + window.pageXOffset;
		miny = e.clientY + window.pageYOffset;
		maxx = e.clientX + window.pageXOffset;
		maxy = e.clientY + window.pageYOffset;
	}
	// Internet Explorer Event Module (IE4-6)
	else if (document.body && document.body.scrollLeft !== undefined) {
		minx = e.clientX + document.body.scrollLeft;
		miny = e.clientY + document.body.scrollTop;
		maxx = e.clientX + document.body.scrollLeft;
		maxy = e.clientY + document.body.scrollTop;
	}
	else return;
	var bounds = menuBoundaries[currentMenuIndex];
	if (minx < bounds[0] || maxx > bounds[1] ||
		miny < bounds[2] || maxy > bounds[3]) menuOff();
}

function menuOn(menuName) {
	if (!menuPreloadFlag) return;
	menuOff();
	for (var i = 0; i < menus.length; i++) {
		if (menuName == menus[i]) {
			currentMenuIndex = i;
			break;
		}
	}
	if (currentMenuIndex == null) return;
	mouseWatcherOn(menuName);
	var menu;
	if (document.layers) {
		menu = eval('document.layers.' + menuName);
		menu.visibility = 'show';
	}
	else if (document.all) {
		menu = document.all(menuName);
		menu.style.visibility = 'visible';
	}
	else if (document.getElementById) {
		menu = document.getElementById(menuName);
		menu.style.visibility = 'visible';
	}
	currentMenu = menuName;
	
	//	Custom functionality for Tania Bass.
	setInitialOnState(menuName);
}

// timeout is needed so menu won't flash in Netscape (all versions)
function menuOff() {
	var menu;
	for (var i = 0; i < menus.length; i++) {
		//if (menus[i] == currentMenu) continue;
		if (document.layers) {
			menu = eval('document.layers.' + menus[i]);
			menu.visibility = 'hide';
		}
		else if (document.all) {
			menu = document.all(menus[i]);
			menu.style.visibility = 'hidden';
		}
		else if (document.getElementById) {
			menu = document.getElementById(menus[i]);
			menu.style.visibility = 'hidden';
		}
	}
	currentMenu = null;
	if (document.layers) document.releaseEvents(Event.MOUSEMOVE);
	document.onmousemove = null;

	//	Custom functionality for Tania Bass.
	if (null != currentFlyoutImage) swapImageOff(currentFlyoutImage);
}

function getDropdownXOffset(tableWidth)
{
	frameWidth = 0;

	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;

		//	We need to detect for browsers that include scrollbars in the frame width.
		if (document.height > self.innerHeight)
		{
			//	Firefox on the Mac.
			if (-1 != browserName.indexOf('Firefox') && -1 != browserName.indexOf('Mac'))
				frameWidth = frameWidth - 15;

			//	Netscape on the Mac.
			else if (-1 != browserName.indexOf('Firefox') && -1 != browserName.indexOf('Windows'))
				frameWidth = frameWidth - 16;

			//	Netscape on the Mac.
			else if (-1 != browserName.indexOf('Netscape') && -1 != browserName.indexOf('Mac'))
				frameWidth = frameWidth - 15;

			//	Netscape on Windows.
			else if (-1 != browserName.indexOf('Netscape') && -1 != browserName.indexOf('Windows'))
				frameWidth = frameWidth - 15;
		}
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
	}

	//	One half of frame width - one half of floating table.
	dropdownXOffset = Math.ceil((frameWidth / 2) - (tableWidth / 2));
	if (dropdownXOffset < 0) dropdownXOffset = 0;
	
	return dropdownXOffset;
}

//	A time delay is needed for some browsers so that the eventHandler can be set up.
//	Mozilla browsers will not behave properly with the time delay.
function setInitialOnState(menuName)
{
	if (-1 != browserName.indexOf('Safari'))
		window.setTimeout('setInitialOnStateRelay("' + menuName + '");', 10);
	else setInitialOnStateRelay(menuName);
}

