/*
	EventManager.js
	
	Author: Tony Osibov & David Smith
	
	Last Updated: 6/20/2007 (created)
	
	Description: this is a group of functions to allow for consistant and simple cross-browser event handling
	
	
	***** NOTE: IF U NEED TO USE AN ONLOAD FOR THE PAGE USE THE WINDOW OBJECT NOT THE BODY OBJECT *****
*/

// use this function to execute the array of events per the specific object and event
function executeEvent(obj, evt){
	var ary = obj.evtList[evt];
	var i = 0;
	
	while(i < ary.length){
		ary[i].func(ary[i].params);
		
		i++;
	}
}

// use this function to attach a function to an event to an object
// NOTE: FUNCTIONS WILL BE EXECUTED IN THE ORDER THEY ARE ADDED
function addEvent(obj, evt, evt_name, evt_func, evt_bubble){
	if(obj){
		if(!obj.evtList){
			obj.evtList = new Object();
		}
		
		if(!obj.evtList[evt]){
			obj.evtList[evt] = new Array();
			
			// For Internet Explorer
			if(obj.attachEvent){				
				obj.attachEvent(
					"on" + evt, 
					function(){
						if(!evt_bubble){
							window.event.cancelBubble = true;
						}
						
						executeEvent(obj, evt);
					}
				);
			}
			// For Firefox
			else if(obj.addEventListener){
				obj.addEventListener(
					evt, 
					function(e){
						if(!evt_bubble){
							e.preventBubble();
						}
						
						executeEvent(obj, evt);
					}, 
					false
				);
			}
		}
		
		var temp_obj = new Object();
		
		temp_obj.name = evt_name;
		temp_obj.func = evt_func;
		
		if(arguments[5]){
			temp_obj.params = arguments[5];
		}
		
		obj.evtList[evt].push(temp_obj);
	}
}

// use this function to remove a function of an event of an object
function removeEvent(obj, evt, evt_name){
	var ary = obj.evtList[evt];
	var i = 0;
	
	if(ary){
		while(i < ary.length){
			if(ary[i].name == evt_name){
				ary.splice(i, 1);
				
				break;
			}
			
			i++;
		}
	}
}