/*======================================================================*\
|| #################################################################### ||
|| # ÜberNet Javascript Libary                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # All Javascript in this file is ©2000-2007 ÜberNet.               # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # --------------- THIS FILE IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.ubernet.biz  |  http://www.ubernet.biz/license.unc    # ||
|| #################################################################### ||
\*======================================================================*/

//This is called to make the body visible once
// all the images have been loaded.
function setVisible(elementId)
{
	if (document.getElementById && elementId)
		document.getElementById(elementId).className = 'loaded';
}

//This class template allows us to create
// classes with contructors
var Class = {
	create: function()
	{
		return function()
		{
			this.initialize.apply(this, arguments);
		}
	}
}

//This function takes either an element object of element id string as a paramter
// and returns the object relivent. It is useful when a function could be
// passed either the ID or the element itself.
function $(element) {
	if (arguments.length > 1)
	{
		for (var i = 0, elements = [], length = arguments.length; i < length; i++)
			elements.push($(arguments[i]));
		return elements;
	}
  
	if (typeof element == 'string')
		element = document.getElementById(element);
	
	return element;
}

//This function allows us to try multible functions to return an object
//Usage:
//
//	return Try (
//			function1(),
//			function2(),
//			function3()
//		) || false;
function Try() {
    var returnObject;
	var i;

    for (i = 0; i < arguments.length; i++) {
      var exectionFunction = arguments[i];
      try {
        returnObject = exectionFunction();
        break;
      } catch (error) {}
    }

    return returnObject;
}


//This function is a recreation of the PHP require_once function
// designd for javascript
function require_once(objectType)
{
	allScripts = document.getElementsByTagName('script');
	
	pathToInclude = null;
	
	for (i = 0; i < allScripts.length; i++)
	{
		//Find the URL to the scripts directory
		if (allScripts[i].src.match(/utility\.js/))
			pathToInclude = allScripts[i].src.replace(/utility\.js/, '');
		
		//If this script is already in the page, return now!
		if (allScripts[i].src.match(objectType + ".js"))
			return;
	}
	
	if (pathToInclude == null)
	{
		alert('utlitiy.js - require_once(\'' + objectType + '\');\n\nFailed to find the include path for the javascript files.');
		return;
	}
	
	//Now force the browser to read in our new file! (DOM.append fails in Safari 2.0)
	document.write('<script type="text/javascript" src="' + pathToInclude + objectType + '.js"></script>');
}