// ************************************************************************************ //
//
// File name: ImageSwapper.js
// Version: 0.5
// Date: 03/08/2005
// Author: Matt McMahon
// 
// ************************************************************************************ //

// ************************************************************************************ //
// Javscript Object for handling image swaps.  Contains one generic function for 
// doing general image swaps, and 2 others intended to handle navigation specific 
// images. 
// Depends:
//	BrowserCheck.js
// ************************************************************************************ //

/* ************************************************************************** */
// ImageSwapper -- Global config parameters
// Each of these can be overridden by specific function calls
/* ************************************************************************** */
//var _NAV_IMG_DIR = "gametapfiles/images/global/nav/";var _NAV_IMG_DIR = "http://www.gametap.com/mpreview/launch/images/global/nav/";var _NAV_OVER_SUFFIX = "_on";
var _NAV_OFF_SUFFIX = "_off";
var _NAV_IMG_TYPE = "gif";
/* ************************************************************************** */
// ImageSwapper object
/* ************************************************************************** */
function ImageSwapper()
{
	this.nav_img_dir = _NAV_IMG_DIR;
	this.nav_img_over_suffix = _NAV_OVER_SUFFIX;
	this.nav_img_off_suffix = _NAV_OFF_SUFFIX;
	this.nav_img_type = _NAV_IMG_TYPE;
	
	// Check to see if a global BrowserCheck object exists
	if( is != null)
	{
		this.is  = is;
	}
	else
	{
		this.is = new BrowserCheck();
	}
	
	
}
/* ************************************************************************** */

/* ************************************************************************** */
// Public interface
ImageSwapper.prototype.navOver = ImageSwapper_navOver;
ImageSwapper.prototype.navOff = ImageSwapper_navOff;
ImageSwapper.prototype.swapImage = ImageSwapper_swapImage;

// Internal
ImageSwapper.prototype.setImageSrc = ImageSwapper_setImageSrc;
/* ************************************************************************** */


/* ************************************************************************** */
// Function to change a navigation image to its OVER state
// Args:
// 	nav_img_id - the id of the image to swap
// 	OPTIONAL
// 	nav_img_dir - the directory where the nav images are located
// 	nav_img_over_suffix - the common suffix for image over states
// 	nav_img_type - the image type
// 
/* ************************************************************************** */
function ImageSwapper_navOver(nav_img_id, nav_img_dir, nav_img_over_suffix, nav_img_type)
{
	if(nav_img_dir == null) { nav_img_dir = this.nav_img_dir; }
	if(nav_img_over_suffix == null) { nav_img_over_suffix = this.nav_img_over_suffix; }
	if(nav_img_type == null) { nav_img_type = this.nav_img_type; }
	this.swapImage(nav_img_id, nav_img_dir + nav_img_id + nav_img_over_suffix + "." + nav_img_type);
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to change a navigation image to its OFF state
// Args:
// 	nav_img_id - the id of the image to swap
// 	OPTIONAL
// 	nav_img_dir - the directory where the nav images are located
// 	nav_img_off_suffix - the common suffix for image over states
// 	nav_img_type - the image type
// 
/* ************************************************************************** */
function ImageSwapper_navOff(nav_img_id, nav_img_dir, nav_img_off_suffix, nav_img_type)
{
	if(nav_img_dir == null) { nav_img_dir = this.nav_img_dir; }
	if(nav_img_off_suffix == null) { nav_img_off_suffix = this.nav_img_off_suffix; }
	if(nav_img_type == null) { nav_img_type = this.nav_img_type; }
	this.swapImage(nav_img_id, nav_img_dir + nav_img_id + nav_img_off_suffix + "." + nav_img_type);
}
/* ************************************************************************** */

/* ************************************************************************** */
// Function to change a swap out an image src
// Args:
// 	img_id - the id of the image to swap
//  path - the path to the new image source
// 
/* ************************************************************************** */
function ImageSwapper_swapImage(img_id, path)
{
	this.setImageSrc(img_id, path);
	
}
/* ************************************************************************** */

/* ************************************************************************** */
// Function to change a swap out an image src, only used interally by the object
// Args:
// 	id - the id of the image to swap
//  src - the source to the new image source
// 
/* ************************************************************************** */
function ImageSwapper_setImageSrc(id, src)
{
	if(this.is.dom)
	{
		var elm = document.getElementById(id);
		if(elm){ elm["src"] = src ; }
	}
	else
	{
		// Crippled browser backup
		if(document.images[id])
		{
			document.images[id].src = src;
		}
	}
}
/* ************************************************************************** */


// Create the "imageSwapper" object for use by other scripts
var imageSwapper = new ImageSwapper(); 