// Copyright Vanbar Multimedia Ltd 2008

// Global Var
var submenu = '';

function swapButton(image){
	if (image != document.body.id && image != submenu) {
		var imageSrc = document[image].src;
		var onoff = imageSrc.substr(( imageSrc.lastIndexOf("_")+1 ),2);
		var imageName = imageSrc.substr(0, ( imageSrc.lastIndexOf("_") ));
		document[image].src = (onoff == "on")?
			imageName + "_off.gif" : image.src = imageName + "_on.gif";
	}
}

function preloadButtons() {
	for(i = 0; i < document.images.length; i++){
		if(document.images[i].src.substr( document.images[i].src.lastIndexOf("/")+1, 6 ) == 'button') {
			document['image' + i] = new Image();
			document['image' + i].src = document.images[i].src.substr(0, ( document.images[i].src.lastIndexOf("_") )) + '_on.gif';
		}
	}
}

function init(sub) {
	// The ID of the Body tag must be the same as the Name of the Menu button
	preloadButtons();
	var imageName = document.body.id;
	var imageSrc = document[imageName].src;
	document[imageName].src = imageSrc.substr(0, ( imageSrc.lastIndexOf("_") )) + "_on.gif";
	if (sub != '') {
		submenu = sub;
		imageSrc = document[sub].src;
		document[sub].src = imageSrc.substr(0, ( imageSrc.lastIndexOf("_") )) + "_on.gif";
	}
}