// Get the object - crossbrowser for IE4+ and NS6+
function getObjectByName(sName){

	// If NS6 or IE5+
	if(document.getElementById)
		return document.getElementById(sName);
	// If IE4
	else if(document.all)
		return document.all[sName];
	// Else return false
	else return false;
}

// Function to 'activate' images.
function imgClick(sName) {
	var sLocation,objImage;

	// If images are supported
	if (document.images && isInitFinished) {
	
		// Get Object based on browser-model
		objImage=getObjectByName(sName);
		
		// If the object is returned, swap the images
		if(objImage){	
		
			// If the image is not in the current images array
			if(!chkInArray(sName,'arrCurImages') ){
	
				// Get the location property
				sLocation=eval(sName + 'on.location');
				
				// If not empty - redirect the browser
				if(sLocation!='')
					window.location.reload(sLocation);
			}
		}
	}
}

// Function to 'activate' images.
function imgChange(sName,sImgName) {
	var objImage;
	
	// If images are supported
	if (document.images) {
	
		// Get Object based on browser-model
		objImage=getObjectByName(sName);
		
		// If the object is returned, swap the images
		if(objImage){
		
			// swap
			objImage.src = sImgName;
			
        }
	}
}

// Function to 'activate' images.
function imgOn(sName) {
	var sLocation, objImage;
	
	// If images are supported
	if (document.images && isInitFinished) {
	
		// Get Object based on browser-model
		objImage=getObjectByName(sName);

			// If the object is returned, swap the images
		if(objImage){

			// If the object not in the current images array
			if(!chkInArray(sName,'arrCurImages')){
			
				// swap
				objImage.src = eval(sName + 'on.src');
				
				// get target location
				sLocation=eval(sName + 'on.location');

				// If there is a location
				if(sLocation!='')
					// change the mousecursor to a hand
					objImage.style.cursor="hand";
				// If no location
				else
					// change the mousecursor to an arrow
					objImage.style.cursor="normal";
			}
        }
	}
}

// Function to 'deactivate' images.
function imgOff(sName) {
	var objImage;
	
	// If images are supported
	if (document.images && isInitFinished) {
		
		// Get Object based on browser-model
		objImage=getObjectByName(sName);
		
		// If the object is returned, swap the images
		if(objImage){
		
			// If the image is not in the current images array
			if(!chkInArray(sName,'arrCurImages'))
				// swap to highlighted image
				objImage.src = eval(sName + 'off.src');
			
			// If in the current images array
			else 
				// swap to current image
				objImage.src = eval(sName + 'off_current.src');
			
			// set mousecursor to normal
			objImage.style.cursor="normal";
		}
	}
}

// Function to check if a name exists in an array
function chkInArray(sElementName,sArrayName){

	// for each item in the targetArray
	for(var iCounter in eval(sArrayName)){
	
		// If the item found, return TRUE
		if(sElementName==eval(sArrayName + '[iCounter]'))return true;
	}
	
	// Return false
	return false;
}

// Function to create the rollover images.
function addROI(sImgName,sImgFName,sLocation){
	var sImgFExt, iImgFNameLength;
	
	// Get the length of the image filename
	iImgFNameLength = sImgFName.length;
	
	// Get the extension-type of the image
	sImgFExt = sImgFName.substring(iImgFNameLength-4,iImgFNameLength);
	
	// Get the filename without the extension of the image
	sImgFName = sImgFName.substring(0,iImgFNameLength-4);

	eval(sImgName + 'on = new Image();');
	eval(sImgName + 'off = new Image();');
	eval(sImgName + 'off_current = new Image();');

	// If the image is not in the current images array
	if(!chkInArray(sImgName,'arrCurImages')){
	
		// Create a highlighted image-object
		eval(sImgName + 'on.src = "' + sImgPath + sImgFName + sImgOverSuffix + sImgFExt + '";');
		// Create a property 'location'
		eval(sImgName + 'on.location = "' + sLocation + '";');
		// Create a non-highlighted image-object
		eval(sImgName + 'off.src = "' + sImgPath + sImgFName + sImgOutSuffix + sImgFExt + '";');
	}
	// If the image is in the current images array
	else{
		// Create a current image-object
		eval(sImgName + 'off_current.src = "' + sImgPath + sImgFName + sImgCurrentSuffix + sImgFExt + '";');
	}
}

// Function to set all the images to the 'deactivated' state or 'current' state.
function initROImages(){
	var arrDummy;
	isInitFinished=true;	
	// For each element in the image array
	for(var iCounter in arrROImages){
	
		// split up the element
		arrDummy = arrROImages[iCounter].split('|');
		
		// Set the image to default state
		imgOff(arrDummy[0]);
	}
}

function preloadROImages(){
	var arrDummy;
	var objBrowser
	
	// Add the images
	if(document.images){
	
		// For each element in the image array
		for(var iCounter in arrROImages){
		
			// Split the element up
			arrDummy = arrROImages[iCounter].split('|');		
			
			// Create the rollover image
			addROI(arrDummy[0],arrDummy[1],arrDummy[2]);
		}
	}
	else alert("Your browser does not support images...\nI suggest you upgrade your browser");
	
	// Initialise the images
	initROImages();
}

// Declare default variables
var sImgPath,sImgOverSuffix,sImgOutSuffix,sImgCurrentSuffix;
var arrROImages=new Array();
var arrCurImages=new Array();
var isInitFinished=false;