// JavaScript Document

/****************************************
 *
 * RO_Bank
 *
 ****************************************
 * Stores offscreen images so that source files are cached by the browser 
 *
 * Properties
 *
 *
 * Methods
 *
 *
 */

function RO_Bank (id_array, suffix) {
	this.ro_array = new Array();
	
	this.initialise (id_array, suffix);
	delete id_array;
}

RO_Bank.prototype.initialise = function (id_array, suffix) {
	for (i = 0; i < id_array.length; i ++) {
		this.ro_array[id_array[i]] = new Rollover(id_array[i], suffix)
	}
};

/****************************************
 *
 * Rollover
 *
 ****************************************
 * Stores offscreen images so that source files are cached by the browser 
 *
 * Properties
 *
 *
 * Methods
 *
 *
 */
function Rollover (id, suffix) {
	this.orig = new Image();
	this.swap = new Image();
	
	this.initialise (id, suffix);
}

Rollover.prototype.initialise = function (id, suffix) {
	// Derive source of id's corresponding element
	imgobj = document.getElementById(id);

	// Store path to original image src
	this.orig.src = imgobj.src;
	
	// Establish position of last dot in the image src URL
	insertpoint = this.orig.src.lastIndexOf('.');
	
	// Store path to swap image src
	this.swap.src = this.orig.src.substring(0, insertpoint) + suffix + this.orig.src.substring(insertpoint);
	
};	

Rollover.prototype.swapImage = function () {
	return this.swap.src;
};

Rollover.prototype.restoreImage = function () {
	return this.orig.src;
};

function preloadRollovers (id_list, suffix) {
	id_array = id_list.split(',');
	// Instantiate RO_Bank
	document.button_bank = new RO_Bank(id_array, suffix);
}

function swapImage (img_id, menu_id){
	// Acquire reference to the image upon which to act
	imgobj = document.getElementById(img_id);
	
	imgobj.src = document.button_bank.ro_array[img_id].swapImage();
	
	if (menu_id != undefined) {
		var menu = document.getElementById(menu_id);
		menu.className = 'menu_visible';
	}
}

function restoreImage (img_id, menu_id){
	// Acquire reference to the image upon which to act
	imgobj = document.getElementById(img_id);
	
	imgobj.src = document.button_bank.ro_array[img_id].restoreImage();
	
	if (menu_id != undefined) {
		startMenuTimer(menu_id);
	}
}

function menuOver (menu_id) {
	menu = document.getElementById(menu_id);
	menu.className = 'menu_item_over';
	clearTimeout(document.menutimer);
}

function menuOff (menu_id) {
	menu = document.getElementById(menu_id);
	menu.className = 'menu_item_off';
	startMenuTimer(menu.parentNode.parentNode.id);
}

function startMenuTimer (menu_id) {
	document.menutimer = setTimeout("hideMenu('" + menu_id + "')", 100);
}

function hideMenu (menu_id) {
	menu = document.getElementById(menu_id);
	menu.className = 'menu_hidden';
}

function overThumb (thumb_id) {
	thumb = document.getElementById(thumb_id);
	thumb.className = 'thumbnail_over';
}

function outThumb (thumb_id) {
	thumb = document.getElementById(thumb_id);
	thumb.className = 'thumbnail';	
}

function showImage (img_id, img_url, img_title, img_width, img_height) {
		
	target_img = document.getElementById(img_id);
	
	target_img.src = img_url;
	
	if (navigator.platform != 'Win32') {
		target_img.width = img_width;
		target_img.height = img_height;
	}
	
	target_img.setAttribute('title', img_title);
	
	caption.innerHTML = img_title;
}