/**
##############################################################################################
#
#		Title: Cats Protection - Common script
#
#		Description: Behaviour common to all branch sites
#
##############################################################################################
#   $Source: /data/cvsroot/cats/html/js/common.js,v $
#   $Author: john $
#   $Revision: 1.1 $
#   $Date: 2008-01-02 14:01:58 $ 
##############################################################################################
/*

/**
 * Function: init
 * 
 * Description: Initialise function, called on page load
 */
function init(){
	// Preload nav images
	preloadImage('/furniture/home_on.gif', 'home_on');
	preloadImage('/furniture/help_on.gif', 'help_on');
	preloadImage('/furniture/adopt_on.gif', 'adopt_on');
	preloadImage('/furniture/events_on.gif', 'events_on');
	preloadImage('/furniture/donate_on.gif', 'donate_on');
	preloadImage('/furniture/shop_on.gif', 'shop_on');
	preloadImage('/furniture/contact_on.gif', 'contact_on');
	
	// Add nav event listeners
	var navImages = document.getElementsByClassName('nav-rollover');
	for (var i=0; i<navImages.length; i++){
		Event.observe(navImages[i], 'mouseover', mouseOverNav);
		Event.observe(navImages[i], 'mouseout', mouseOutNav);
	}
}


/**
 * Function: preloadImage
 * 
 * Description: Preloads an image for DHTML use
 * 
 * @param {String} url - URL of the image to preload
 * @param {String} id - Unique Id to assign to this image
 */
function preloadImage(url, id){
	
	var preload = $('preload');
	if (!preload){
		preload = document.createElement('div');
		preload.id = "preload";
		document.body.appendChild(preload);
	}
	
	var img = new Image();
	img.src = url;
	img.id = id;
	preload.appendChild(img);
}

/**
 * Function: mouseOverNav
 * 
 * Description: Handles mouse over nav button
 * 
 * @param {Event} e - the mouse over event
 */
function mouseOverNav(e){
	if (!$(e.target.id + '_off')){
		var img = new Image();
		img.src = e.target.src;
		img.id = e.target.id + '_off';
		$('preload').appendChild(img);
	}
	e.target.src = $(e.target.id + '_on').src;
}



/**
 * Function: mouseOutNav
 * 
 * Description: Handles mouse out nav button
 * 
 * @param {Event} e - the mouse out event
 */
function mouseOutNav(e){
	e.target.src = $(e.target.id + '_off').src;
}

/**
 * Compile-time code
 */
Event.observe(window, 'load', init);

/*
 * END
 */
