

function toggleDisplay(elementId){
	oEle = document.getElementById(elementId);
	// must be this way round, if no style is secified 
	// it needs to be hidden as it will be the same as display: block
	if(oEle.style.display == 'none') {
		oEle.style.display = 'block';
	} else {
		oEle.style.display = 'none';
	}
}

function toggleRevealLabel(elementId){
	oEle = document.getElementById(elementId);
	if(oEle.innerHTML == '« hide') {
		oEle.innerHTML = 'reveal &raquo;';
	} else {
		oEle.innerHTML = '&laquo; hide';
	}
}


function showElement(elementId){
	oEle = document.getElementById(elementId);
	oEle.style.display = 'block';
}

function hideElement(elementId){
	oEle = document.getElementById(elementId);
	oEle.style.display = 'none';
}


var image_nav = new Array();
image_nav[0] = "http://www.aqualux.co.uk/pics_home/pn_trade2.gif";
image_nav[1] = "http://www.aqualux.co.uk/pics_home/pn_home2.gif";
image_nav[2] = "http://www.aqualux.co.uk/pics_home/pn_aqualux2.gif";
image_nav[3] = "http://www.aqualux.co.uk/pics_home/pn_productRange2.gif";
image_nav[4] = "http://www.aqualux.co.uk/pics_home/pn_findStockist2.gif";

var image_misc = new Array();
image_misc[0] = "http://www.aqualux.co.uk/pics_home/panel_showerEnclosures2.jpg";
image_misc[1] = "http://www.aqualux.co.uk/pics_home/panel_showerTrays2.jpg";
image_misc[2] = "http://www.aqualux.co.uk/pics_home/panel_bathScreens2.jpg";
image_misc[3] = "http://www.aqualux.co.uk/pics_home/panel_steamCabins2.jpg";
image_misc[4] = "http://www.aqualux.co.uk/pics_home/panel_otherProducts2.jpg";
image_misc[5] = "http://www.aqualux.co.uk/pics_home/panel_accessories2.jpg";
image_misc[6] = "http://www.aqualux.co.uk/pics_home/panel_technicalInfo2.jpg";
image_misc[7] = "http://www.aqualux.co.uk/pics_home/panel_search2.jpg";
image_misc[8] = "http://www.aqualux.co.uk/pics_home/c2a_email2.jpg";

function preload_image_array(image_array) {
	if (document.images) {
		preload_image_object = new Image();
		var i = 0;
		for(i=0; i<=image_array.length-1; i++) {
			preload_image_object.src = image_array[i];
		}
	}
}





function init() {
	// hide the about aqualux section
	// toggleDisplay('home_aboutProducts');
	// toggleRevealLabel('home_aboutProducts_reveal');
	// preload navigation images
	//preload_image_array(image_nav);
	// preload other rollover images
	//preload_image_array(image_misc);
}
window.onload = init;



// swaps image.gif
// for image2.gif
// and vice versa
function swapThisImage(oElement){
	imageSource = oElement.src;
	arrayParts = imageSource.split('.');
	var extension = arrayParts.pop();
	var path = arrayParts.join('.');
	if(imageSource.lastIndexOf('2.') > 1) {
		path = path.substring(0,path.length-1)
		oElement.src = path + '.' + extension;
	} else {
		oElement.src = path + '2.' + extension;
	}
}


// stores an array of id's as strings relating to visible menu's
// when hide menus is called all the menus in the array
// will be hidden
var openMenus = new Array(); // LIFO stack

// stores a reference to the currently opened navigation image
// so that when hide menus is called it can swap the image back to normal
// swapThisImage wont work because it cant be called by another function
var swappedMenuImages = new Array(); // LIFO stack

// holds the timer values
var menuTimers = new Array(); // LIFO stack
var menu_hideAllTimer = false;




function menu_image_hideLevel(level) {
	// typeof(null) == 'object' arrgh why !?
	if(typeof(swappedMenuImages[level]) == 'object') {
		swapThisImage(swappedMenuImages[level]);
		swappedMenuImages[level] = false;
	}
}

function menu_image_hideAll(){
	lastImageIndex = swappedMenuImages.length-1;
	for (var x=lastImageIndex; x>=0; x--) {
		menu_image_hideLevel(x)
	}
}




function menuShow(menu_id, level, oImage){
	if(oImage){
		menu_image_hideLevel(level);
		swapThisImage(oImage);
		swappedMenuImages[level] = oImage;
	}
	// cancel any current timers for the level we want to show
	menu_clearTimer_hideLevel(level);
	menu_clearTimer_HideAll();
	// hide all menus at the same level as the one we are trying to open
	// incase there are any already open
	menu_hideLevel(level);
	// show the menu
	showElement(menu_id);
	// save the open menu
	openMenus[level] = menu_id;
}



// hides only menu items on this level
function menu_hideLevel(level){
	if(typeof(openMenus[level]) == 'string') {
		hideElement(openMenus[level]);
		openMenus[level] = false;
	}
	// menu_image_hideLevel(level);
}
// hides all open menus
function menu_hideAll(){
	lastOpenMenuIndex = openMenus.length-1;
	// loop backwards - so it hides the sub menus first
	for (var x=lastOpenMenuIndex; x>=0; x--) {
		menu_hideLevel(x);
	}
	menu_image_hideAll();
}


// mouseout
// sets a timer the specified level
function menu_startTimer_hideLevel(level){
	// starts the hide everything timer incase the menu has been abandoned - can always be cancelled later on
	menu_startTimer_HideAll();
	// see not about setting timers in menu_startTimer_HideAll
	if(!menuTimers[level]){
		menuTimers[level] = setTimeout('menu_hideLevel('+level+')', 1000);
	}
}
// mouseover
// cancels all timers from 0 up to the specified level
function menu_clearTimer_hideLevel(level){
	menu_clearTimer_HideAll();
	for (var x=0; x<=level; x++) {
		clearTimeout(menuTimers[x]);
		menuTimers[x] = false;
	}
}



// sets a timer to hide everything
function menu_startTimer_HideAll(){
	// only set the timer if it's not already set
	// this is because it creates a seperate timer - which is impossible to find and cancel
	if(!menu_hideAllTimer){
		menu_hideAllTimer = setTimeout('menu_hideAll()', 1000);
	}
}
// cancels the timer which hides everything
function menu_clearTimer_HideAll(){
	clearTimeout(menu_hideAllTimer);
	menu_hideAllTimer = false;
}






function debug(message){
	document.getElementById('debug').innerHTML += message+'<br />';
}
function debugArray(arrayName){
	debug('debugArray start');
	for (var x=0; x<=arrayName.length-1; x++) {
		debug('__x='+x+' = '+arrayName[x]);
	}
	debug('debugArray end');
}

function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}
