/****************************************************************************/
/* Browser information object												*/
/****************************************************************************/

/**
 * Provides information about the browser.
 *
 * @since	4.2.2
 * @access	public
 */
function BrowserInfo() {

	this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	this.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
	this.isSafari = navigator.userAgent.indexOf('Safari') != -1;
	this.isMac = navigator.userAgent.indexOf('Mac') != -1;
	this.isOpera = navigator.userAgent.indexOf('Opera') != -1;

	// Version of MSIE or -1 for other browsers.
	this.version = (navigator.appName=='Microsoft Internet Explorer')
		? parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1])
		: -1;

} // end constructor BrowserInfo.

/**
 * Browser information.
 *
 * @type	BrowserInfo
 * @access	public
 * @since	4.2.2
 */
document.browserInfo = new BrowserInfo();

/****************************************************************************/
/* Event information object													*/
/****************************************************************************/

/**
 * Provides standardised information about an event.
 *
 * @access	public
 * @since	4.2.2
 */
function EventInfo(e) {

	if (!e) {
		e = window.event;
	}

	// Store original event object.
	this.event = e;

	// Event type.
	this.type = e.type;

	// Event target.
	if (e.target != null || e.srcElement != null) {
		this.target = (e.target != null ? e.target : e.srcElement);
		if (this.target.nodeType == 3) {
			// Safari bug.
			this.target = this.target.parentNode;
		}
	}

	// Key press.
	if (e.which != null) {
		this.keyCode = e.which;
	} else {
		this.keyCode = e.keyCode;
	}
	this.keyCharacter = String.fromCharCode(this.keyCode);
	this.shiftKey = e.shiftKey;

	// Button type.
	this.rightClick = (e.button == 2);

	// Mouse position

	this.mouseX = 0;
	this.mouseY = 0;
	if (e.pageX || e.pageY) {
		this.mouseX = e.pageX;
		this.mouseY = e.pageY;
	} else if (e.clientX || e.clientY) {
		this.mouseX = e.clientX + document.body.scrollLeft;
		this.mouseY = e.clientY + document.body.scrollTop;
	}

} // end constructor EventInfo.

/**
 * Cancels the event.
 *
 * @access	public
 * @since	4.2.2
 */
EventInfo.prototype.cancel = function() {

	document.cancelEvent(this.event);

} // end function cancel.

/****************************************************************************/
/* Document element extensions												*/
/****************************************************************************/

/**
 * Cancels an event.
 *
 * @param	Event	e	The event to cancel.
 * @access	public
 * @since	4.2.2
 */
document.cancelEvent = function(e) {

	// Check if an EventInfo object was provided.
	if (e.event != null) {
		e = e.event;
	}

	if (document.browserInfo.isMSIE) {
		e.returnValue = false;
		e.cancelBubble = true;
	}
	if (e.stopPropagation) {
		e.stopPropagation();
	}
	if (e.preventDefault) {
		e.preventDefault();
	}

} // end function cancelEvent.

/**
 * Registers an event handler for an object.
 *
 * @param	Object		obj			The object.
 * @param	String		eventName	The event that will be handled.
 * @param	Function	handler		The function that will handle the event.
 * @access	public
 * @since	4.2.2
 */
document.registerEvent = function(obj, eventName, handler) {

	if (this.browserInfo.isMSIE) {
		obj.attachEvent('on' + eventName, handler);
	} else {
		obj.addEventListener(eventName, handler, true);
	}

} // end function registerEvent.

/****************************************************************************/
/* Template functions														*/
/****************************************************************************/

function buttonDown(e){e=new EventInfo(e);if(e.target.src)e.target.src=e.target.src.replace('.gif','_down.gif')}
function buttonUp(e){e=new EventInfo(e);if(e.target.src)e.target.src=e.target.src.replace('_down.gif','.gif')}

/**
 * Assigns actions to buttons on the website.
 *
 * @access	public
 */
function loadButtons() {

	var images = document.getElementsByTagName('IMG');
	for (var i = 0; i < images.length; i++) {
		if (images[i].className == 'yellowButton') {
			document.registerEvent(images[i], 'mousedown', buttonDown);
			document.registerEvent(images[i], 'mouseup', buttonUp);
			document.registerEvent(images[i], 'mouseout', buttonUp);
		}
	}

} // end function loadButtons.

document.registerEvent(window, 'load', loadButtons);
