/*
*	UNIVERSAL EVENT OBJECT
*
*	This file contains a general non browser specific event object whose methods can be used to attach, remove, 
*	and cancel events, as well as retrieve the event source. 
*	Note: This should be the first javascript file imported if this event object is to be used to attach an initialisation routine 
*	to the windows onload event.
*
*	12 - April - 2006
*	version 1.0
*	
*/

EventObj = function(){
//non broweser specific event object 

// #### OBJECT METHODS ####
this.addEvent = function(eventType, element, fn, capture){
//add an event to an element
//parameters are: 	
//eventType:	string containing event type (without the 'on') eg "load", "mouseout", "keyup"
//element: 		element to which the event is to be attached
//fn:			function variable pointing to the handling routine
//capture:		boolean, usually set to false

	if(!element) return;
	
	if(element.addEventListener){//DOM browsers
		element.addEventListener(eventType, fn, capture);
	} else if(element.attachEvent){//older IE model browers
		element.attachEvent("on"+eventType, fn);
	} else {//very old browsers
		element["on"+eventType] = fn;
	}
}//addEvent

this.removeEvent = function(eventType, element, fn, capture){
//removes an evernt from an element
//parameters are:
//eventType: 	string containing event type (without the 'on') eg "load", "mouseout", "keyup"
//element: 		element to which the event is to be attached
//fn:			function variable pointing to the handling routine
//capture:		boolean, usually set to false
	
	if(!element) return;
	
	if(element.removeEventListener){//DOM browsers
		element.removeEventListener(eventType, fn, capture);
	} else if(element.detachEvent){//older IE model browers
		element.detachEvent("on"+eventType, fn);
	} else {//very old browsers
		element["on"+eventType] = null;
	}	

}//removeEvent

this.getEventSource = function(e){
//returns the source of event: e or
//returns null if not found
	var result = null;
	
	if(e && e.target) {//DOM browsers
		result = e.target;
	} else if (window.event && window.event.srcElement){//older IE browsers
		result = window.event.srcElement;
	}
	return result;
}//getEventSource

this.cancelEvent = function(e){
//cancels event: e	
	
	if(e && e.stopPropagation) {
		e.stopPropagation();
	} else if(window.event && window.event.cancelBubble) {
		window.event.cancelBubble = true;
	}
}//cancelEvent

this.getX = function(e){
//returns mouse x pos relative to page
	if(e && e.pageX) {
		return e.pageX;
	} else if(window.event && window.event.clientX){
		return window.event.clientX - 1;
	} else {
		return 0;
	}
}//getX

this.getY = function(e){
//returns mouse y pos relative to page	
	if(e && e.pageY) {
		return e.pageY;	
	} else if(window.event && window.event.clientY){
		return window.event.clientY - 1;
	} else {
		return 0;
	}
}//getY

// #### END OF METHOD DEFINITIONS ####

}//EventObj

