var JadeEvents = {
	_vars: function()
	{
		this.beforeEvents = new Array;
		this.onloaded=false;
	},
	Add: function (element, event, fn, useCapture)
	{
		if (element.addEventListener) 
		{
			element.addEventListener(event, fn, useCapture);
			return true;
		}
		else if (element.attachEvent)
		{
			var r = element.attachEvent('on' + event, fn);
			return r;
		}
		else 
		{
			element['on' + event] = fn;
			return true;
		}
	},
	AddLoad: function (fn) 
	{
		if($.Events.onloaded){ fn(); }
		else{ Jade.Events.Add(window,'load',fn,false); }
	},
	AddBeforeLoad: function(fn)
	{
		Jade.Events.beforeEvents.push(fn);
	},
	OnLoad: function()
	{
		for(var i=0;i<Jade.Events.beforeEvents.length;i++)
		{
			setTimeout(Jade.Events.beforeEvents[i],1);
		}
		$.Events.onloaded=true;
	},
	Remove: function (element, event, fn, useCapture) 
	{
		if (element.addEventListener) 
		{
			element.removeEventListener(event, fn, useCapture);
			return true;
		}
		else if (element.attachEvent) 
		{
			var r = element.detachEvent('on' + event, fn);
			return r;
		}
		else 
		{
			element['on' + event] = null;
			return true;
		}
	},
	RemoveLoad: function (fn) {
		Jade.Events.Remove(window,'load',fn,false);
	},
	NoSelect: function(element) {
		if (typeof(element.onselectstart)!="undefined") { element.onselectstart=function(){ return false; }; }
		else if ($.Browser.isFF){ element.style.MozUserSelect="none"; }
		else if ($.Browser.isChr){ element.style.webkitUserSelect="none"; element.style.webkitTouchCallout= "none"; }
		else { element.onmousedown=function(){ return false; } }
		
		/*
		element.style.
		-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
		*/
		
	},
	StopPropagation: function(event){
		if(typeof(event.stopPropagation)!="undefined"){ event.stopPropagation(); }
		else if(typeof(event.cancelBubble)!="undefined"){ event.cancelBubble=true; }

	},
	fire: function(element, event){
		if(typeof(element[event])!="undefined"){ element[event](); }
	}
	
}
//
Jade.LoadLibrary('Events',JadeEvents);
Jade.Events.AddLoad(Jade.Events.OnLoad);