//
//	EventManager
//
var EventManager = new Class({		
		events: [],					 
		timers: [],					 
		delays: [],					 
		//
		//  events
		//
		pushEvents: function(obj,typ,f,grp) {
			var ehash = new Hash({
				object: obj,
				type: typ,
				func: f,
				group: grp
			})
			this.events.push(ehash)
            if ($type(obj) == 'object') obj.addEvent(typ,f)
			else document.id(obj).addEvent(typ,f)
			return ehash
		},
		pullEvent: function(ehsh){
			document.id(ehsh.object).removeEvent(ehsh.type,ehsh.func)	
			ehsh = null
		},
		pullEvents: function(grp){
			if ($chk(grp)){
				this.events.each(function(ehsh){
						if (ehsh.group == grp) this.pullEvent(ehsh)
				}.bind(this))
			} else {
				this.events.each(function(ehsh){
					this.pullEvent(ehsh)				 
				}.bind(this))
			}
		},
		//
		// periodicals
		//
		pushTimers: function(f,dur,bnd,grp){
			if ($chk(bnd)) var tmr = f.periodical(dur,bnd)
			else var tmr = f.periodical(dur)
			var thash = new Hash({
				timer: tmr,
				group: grp
			})
			this.timers.push(thash)
			return thash
		},
		pullTimer: function(thsh){
			$clear(thsh.timer)
			thsh = null
		},
		pullTimers: function(grp){
			if ($chk(grp)){
				this.timers.each(function(thsh){
					if (thsh.group == grp) this.pullTimer(thsh)				 
				}.bind(this))
			} else {
				this.timers.each(function(thsh){
					this.pullTimer(thsh)	
				}.bind(this))
			}
		},
		//
		// delays
		//
		pushDelays: function(f,dur,bnd,grp){
			if ($chk(bnd)) var dly = f.delay(dur,bnd)
			else var dly = f.delay(dur)
			var dhash = new Hash({
				delay: dly,
				group: grp
			})
			this.delays.push(dhash)
			return dhash
		},
		pullDelay: function(dhsh){
			$clear(dhsh.delay)
			dhsh = null
		},
		pullDelays: function(grp){
			if ($chk(grp)){
				this.delays.each(function(dhsh){
					if (dhsh.group == grp) this.pullDelay(dhsh)				 
				}.bind(this))
			} else {
				this.delays.each(function(dhsh){
					this.pullTimer(dhsh)	
				}.bind(this))
			}
		},
		//
		//
		//
		killAll: function(){
			this.pullEvents()
			this.pullTimers()
			this.pullDelays()
			events = null
			timers = null
			delays = null
		},
		selectionStopper: function(){
				this.pushEvents(document,'selectstart', function(e) {
						if (this.killSelection) e.stop()
				}.bind(this))		
		}
});
