var page = null;
var menuPreloadFlag = false;
var loadedImages = new Array();
var imageNames = new Array(
	'about',
	'collections',
	'expertise',
	'mailinglist',
	'mailinglistjoin',
	'press',
	'retailers',
	'service',
	'shoppingbag',
	'siteindex',

	'expertisemain',
	'expertisebeads',
	'expertisegemstones',
	'expertisegild',
	'expertisegold',
	'expertisepearls',
	'expertisesterling',
	
	'collectionsmain',
	'collectionsbridal',
	'collectionsbrooke',
	'collectionsprayer',
	'collectionsheirloom',
	'collectionscareproducts',
	'collectionslimitededition',

	'jewelrymain',
	'jewelrybracelets',
	'jewelrybrooches',
	'jewelryearrings',
	'jewelrymensjewelry',
	'jewelrynecklaces',
	'jewelryrings'
);

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 = '/images/menus/' + nextName + '.gif';
		loadedImages[nextName][1].src = '/images/menus/' + nextName + '-on.gif';
	}
	menuPreloadFlag = true;
	
	if ('collections' == page) collectionsInit();
}

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;
}

// Dropdown menu functions.

//	Customization variables.
var menus = Array(
	'menuBoxExpertise',
	'menuBoxCollections',
	'menuBoxJewelry'
);

//	minx, maxx, miny, maxy
var menuBoundaries = new Array(
	new Array(336, 444, 52, 166),
	new Array(193, 325, 28, 142),
	new Array(288, 379, 28, 142)
);

//	Initialize variables.
var undefined; // Used in mouseWatcher(). Necessary for browsers that do not implement "undefined".
var currentMenu = null;
var currentMenuIndex = 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;

	//	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;
}

// 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;
}