var Events = {
	
	triggerEvent : function(e,type,target){
		e = Events._parseEvent(e);
		
		var event = new Event(e);
		
		if(target == null) return;
		if(typeof target._events == 'undefined' || typeof target._events[type] == 'undefined') return;
		
		for(var i=(target._events[type].length-1);i>=0;i--){
			target._events[type][i](event);
		}
	},
	
	attachEvent : function(elm,type,callback){
		Events.detachEvent(elm,type,callback);
		
		if(typeof elm._events == 'undefined') elm._events = new Object();
		if(typeof elm._events[type] == 'undefined') elm._events[type] = new Array();
		elm._events[type][elm._events[type].length] = callback;

		var f = function(e){Events.triggerEvent(e,type,elm)};
		eval('elm.on'+type+' = f;');
	},
	
	detachEvent : function(elm,type,callback){
		if(typeof elm._events == 'undefined' || typeof elm._events[type] == 'undefined') return;
		
		for(var i=(elm._events[type].length-1);i>=0;i--){
			if(elm._events[type][i] == callback){
				elm._events[type].splice(i,1);
			}
		}
	},
	
	hasAttachedType : function(elm,type){
		if(typeof elm._events == 'undefined' || typeof elm._events[type] == 'undefined') return false;
		else return true;
	},
	
	_parseEvent : function(e){
		if (!e) return window.event;
		else return e;
	}
}