
/************************************************************************/
/******************** HTML Element Functions ****************************/
/************************************************************************/
/*!
	\brief cross-browser(?) element fetcher - fetches an HTML element
	\param id - the ID of the element to fetch
	\returns HTMLElement object
*/
function get_element(id)
{
	if(document.getElementById)
		return document.getElementById(id);
	return document.layers[id];
}

/*!
	\brief Returns a reference to a form in the page with a particular id
	\param id - the id of the form to retrieve
	\returns Form object, or false if the form is not found
*/
function get_form(id)
{
	for(var i=0; i<document.forms.length; i++)
		if(document.forms[i].id == id)
			return document.forms[i];
	
	return false;
}

/************************************************************************/
/******************* Image Swapper Functions ****************************/
/************************************************************************/

/*!
	\brief Image preloader (for swapping images)
	
	This function can accept any number of parameters. Each parameter should be the URL of an image
	to preload (string).
*/
function PreloadImages()
{
	if(document.images)
	{
		if(!document.preloaded_images)
			document.preloaded_images = new Array();
		
		var j = document.preloaded_images.length;
		var args = PreloadImages.arguments;
		
		for(var i=0; i < args.length; i++)
		{
			document.preloaded_images[j] = new Image;
			document.preloaded_images[j++].src = args[i];
		}
	}
}

/*!
	\brief Image swapper function
	\param obj - string or HTML element reference of the image object to swap
	\param newsrc - URL of the new image to load
	\returns nothing
*/
function SwapImage(obj, newsrc)
{
	var img = (typeof obj == "string") ? get_element(obj) : obj;
	
	if(!img.prev_src)
		img.prev_src = img.src;
	img.src = newsrc;

	document.swapped_image = img;
}

/*!
	\brief Restores a previously-swapped image to its original SRC
	\returns nothing
*/
function SwapImageRestore()
{
	document.swapped_image.src = document.swapped_image.prev_src;
}

