// JavaScript Document
if(typeof SW_LIB == "undefined") var SW_LIB = new Object();
SW_LIB.EVENT_MANAGER = new Object();

function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

Object.extend = function(destination, source) {
	  for (var property in source)
		destination[property] = source[property];
	  return destination;
	};
/*	
Object.prototype.INIT_EVENT_MNG = function() {
	this.EVENT_MNG = {};
	// Create Event Manager and Initialize it. add Listener Methods for the object
	Object.extend(this.EVENT_MNG, EVENT_MANAGER);
	this.EVENT_MNG.INIT();
	this.addEventListener = function(EventType, Listener_Fn, Listener_Obj) {
		this.EVENT_MNG.addEventListener(EventType, Listener_Fn, Listener_Obj);
	};
	this.removeEventListener = function(EventType, Listener_Fn, Listener_Obj) {
		this.EVENT_MNG.removeEventListener(EventType, Listener_Fn, Listener_Obj);
	};
}*/

INIT_EVENT_MNG_CLASS = function() {
	this.EVENT_MNG = {};
	// Create Event Manager and Initialize it. add Listener Methods for the object
	Object.extend(this.EVENT_MNG, EVENT_MANAGER);
	this.EVENT_MNG.INIT();
	this.addEventListener = function(EventType, Listener_Fn, Listener_Obj) {
		this.EVENT_MNG.addEventListener(EventType, Listener_Fn, Listener_Obj);
	};
	this.removeEventListener = function(EventType, Listener_Fn, Listener_Obj) {
		this.EVENT_MNG.removeEventListener(EventType, Listener_Fn, Listener_Obj);
	};
}


var EVENT_MANAGER = {};
EVENT_MANAGER.INIT = function(){
	this.EVENTS_LISTENER_LIST = {};
}
EVENT_MANAGER.addEventListener = function(EVENT_TYPE, EVENT_FUNCTION, CURRENT_TARGET){
	if(typeof this.EVENTS_LISTENER_LIST[EVENT_TYPE]=="undefined"){
		this.EVENTS_LISTENER_LIST[EVENT_TYPE]=[];
	}
	this.EVENTS_LISTENER_LIST[EVENT_TYPE].push({listener_Fn:EVENT_FUNCTION, currentTarget:CURRENT_TARGET});
}
EVENT_MANAGER.removeEventListener = function(EVENT_TYPE,EVENT_FUNCTION, CURRENT_TARGET){
	if(typeof this.EVENTS_LISTENER_LIST[EVENT_TYPE]!="undefined"){
		for(var i=0;i<this.EVENTS_LISTENER_LIST[EVENT_TYPE].length;i++){
			var listener_OBJ = this.EVENTS_LISTENER_LIST[EVENT_TYPE][i];
			if((listener_OBJ.listener_Fn== EVENT_FUNCTION)&&(listener_OBJ.currentTarget== CURRENT_TARGET)){
				this.EVENTS_LISTENER_LIST[EVENT_TYPE].splice(i,1);
				return;
			}
		}
	}
};
EVENT_MANAGER.dispatchEvent = function(_EVENT){
	//alert("_EVENT.type:"+_EVENT.type+","+this.ID);
	var evtListener_List = this.EVENTS_LISTENER_LIST[_EVENT.type];
	if(typeof evtListener_List!="undefined" && evtListener_List.length){
		for(var i=0;i<evtListener_List.length;i++){
			try{
				var EVENT_LISTENER = evtListener_List[i];
				var CURRENT_TARGET = EVENT_LISTENER.currentTarget;
				eval("CURRENT_TARGET."+EVENT_LISTENER.listener_Fn+"(_EVENT);");
				//alert("CURRENT_TARGET."+F_TARGET+"(_EVENT);");
			}catch(e){ alert("ERROR on DISPATCH:\n"+"CURRENT_TARGET."+EVENT_LISTENER.listener_Fn+"(_EVENT);"+"\n==>"+e);}
			
		}return true;
	}return false;
};

EVENT = function(EVENT_TYPE, _target, _parameters){
	this.toString=function(){
		return "[object EVENT]";
	};
	this.target = _target;
	this.type= EVENT_TYPE;
	// Add Parameters to Event
	Object.extend(this, _parameters);
};
// EVENT TYPES CONSTANTS
EVENT.MOVE="MOVE";
EVENT.START="START";
EVENT.STOP="STOP";
/**/