// (c) 2004-2006 Rob Rohan, Richard Applebaum, and Barney Boisvert

if(typeof BROWSER_SNIFFER_VERSION=="undefined"||DEBUG_VERSION=="undefined"){alert("Fatal Error: EventManager is missing required libraries");throw new Error("ui/events/eventmanager.js missing required libraries");}
var EVENTMANAGER_VERSION="0.1";SysDocument=document;if(SysDocument.captureEvents)
{if(Event.MOUSEMOVE)
{SysDocument.captureEvents(Event.MOUSEMOVE);}}
var neuro_onloadListeners=new Array();var neuro_clickListeners=new Array();var neuro_mdownListeners=new Array();var neuro_mupListeners=new Array();var neuro_moveListeners=new Array();var neuro_keyDownListeners=new Array();var neuro_keyUpListeners=new Array();var neuro_keyPressListeners=new Array();function neuro_addLoadListener(func)
{__addListener(neuro_onloadListeners,func);}
function neuro_addMouseDownListener(func)
{__addListener(neuro_mdownListeners,func);}
function neuro_addMouseUpListener(func)
{__addListener(neuro_mupListeners,func);}
function neuro_addClickListener(func)
{__addListener(neuro_clickListeners,func);}
function neuro_addMoveListener(func)
{__addListener(neuro_moveListeners,func);}
function neuro_addKeyDownListener(func)
{__addListener(neuro_keyDownListeners,func);}
function neuro_addKeyUpListener(func)
{__addListener(neuro_keyUpListeners,func);}
function neuro_addKeyPressListener(func)
{__addListener(neuro_keyPressListeners,func);}
function __addListener(arry,func)
{arry[arry.length]=func;}
function _checkClick(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_clickListeners,e);return true;}
function _checkMDown(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_mdownListeners,e);if(e.target.tagName=="IMG"||e.target.className.indexOf("Item")>0)
{return false;}
return true;}
function _checkMUp(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_mupListeners,e);return true;}
function _checkMove(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_moveListeners,e);return true;}
function _checkOnLoad(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_onloadListeners,e);}
function _checkKeyDown(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_keyDownListeners,e);return true;}
function _checkKeyUp(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_keyUpListeners,e);return true;}
function _checkKeyPress(e)
{e=__normalizeEvent(e);__fireEventListeners(neuro_keyPressListeners,e);return true;}
function __fireEventListeners(arry,evt)
{var len=arry.length;for(var i=0;i<len;i++)
{try
{arry[i](evt);}
catch(e)
{alert(e);log.error("Tryed to fire an event on "+arry[i]+" and failed because: "+e.toString());}}}
function __normalizeEvent(evt)
{if((!evt||evt==null||typeof evt=="undefined")&&SysBrowser.explore)
{evt=window.event;}
if(typeof evt.target=="undefined"&&typeof evt.srcElement!="undefined")
{evt.target=evt.srcElement;}
return evt;}
function neuro_getKeyCodeFromEvent(evt)
{if(SysBrowser.explore)
return evt.keyCode;else if(SysBrowser.gecko||SysBrowser.safari)
return evt.which;}
function neuro_getKeyFromEvent(evt)
{return String.fromCharCode(neuro_getKeyCodeFromEvent(evt));}
SysDocument.onmousemove=_checkMove;SysDocument.onmousedown=_checkMDown;SysDocument.onmouseup=_checkMUp;SysDocument.onclick=_checkClick;SysDocument.onkeydown=_checkKeyDown;SysDocument.onkeyup=_checkKeyUp;SysDocument.onkeypress=_checkKeyPress;window.onload=_checkOnLoad;