﻿
var selectedImage;	// Image which indicates current section
var imagePath = "/mall/Tate/images/"; // path to images
var navFolder = "top_nav_new/"; // Name of folder containing navigation images
var preloadImagesArray = new Array('basket_on.gif','currency_eur_on.gif','currency_gbp_on.gif','currency_gbp_on.gif','currency_usd_on.gif','details_on.gif','divider_on.gif','divider_on.gif','faq_on.gif','gallery_on.gif','home_on.gif','nav_artists_on.gif','nav_colour_on.gif','nav_tate_on.gif');

// Does the onLoad stuff
function initiate(theImage, currencyHidden) {
	if (theImage && theImage.length > 0) {
		selectedImage = theImage;
		swapImage(selectedImage,'on',true);
	}
	if (!currencyHidden) {
		showhide('currencyDiv','visible');
	}
	preloadImages()
}	

// Image rollovers. Assumes the image has the suffixes _on and _off
function swapImage(whichImage, state, override) {
	if (selectedImage != whichImage || override == true) {
		var theImage = document.images[whichImage];
		var lastIndex = theImage.src.lastIndexOf("_");
		var newPath = theImage.src.substring(0,lastIndex + 1);
		theImage.src = newPath + state + ".gif";
		//alert(theImage.src);
	}
}

// Shows or hides a div (for the currency)
function showhide(layer_ref, state) {
	if (state == undefined) {
		state = 'visible';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.visibility = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].visibility = state;
	}
	if (document.getElementById && !document.all) {
		var maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.visibility = state;
	}
}

// Assumes all images are in the same folder
function preloadImages() {
	for (var i=0; i<preloadImagesArray.length; i++) {
		var imageToLoad = imagePath + navFolder + preloadImagesArray[i];
		preloadImagesArray[i] = new Image();
		preloadImagesArray[i].src = imageToLoad;
	}
}