//screen manager
var Smgr =
{
	Handles : [], ResizeHandles : [],
	IHandleIndex : 0, IResizeHandle : 0,
	Resolution : { Height : window.screen.height, Width : window.screen.width},
	Top : window.screen.top,
	Left : 0,
	Right : window.screen.width,
	Bottom : window.screen.height,
	Height : window.screen.height,
	Width : window.screen.width,
	IsIE  : (window.navigator.appName.indexOf("Microsoft")>-1),
	ListenerThread : null,
	MouseX : -1,
	MouseY : -1,
	HandleMouseCoords : function(event)
	{
		if(event == null) 
			event = window.event;
		if(event.pageX == null) {
			Smgr.MouseY =  Math.max( document.documentElement.scrollTop,document.body.scrollTop) + event.clientY;
			Smgr.MouseX =  Math.max( document.documentElement.scrollLeft,document.body.scrollLeft) + event.clientX;
		}
		else {
			Smgr.MouseX = event.pageX;
			Smgr.MouseY = event.pageY;
		}
		
		Smgr.Handles.foreach(function(arg){
				arg(Smgr.MouseX, Smgr.MouseY);
			});
	},
	AddMoveEvent : function( _handler )
	{
		this.Handles[IHandleIndex] = _handler;	IHandleIndex+=1;
	},
	AddResizeEvent : function( _handler )
	{
		this.ResizeHandles[this.IResizeHandle] = _handler;	this.IResizeHandle+=1;
	},
	onWindowResize : function()
	{
		Smgr.ResizeHandles.foreach(function(arg){
								arg(); //exec callbacks
							});
	},
	onWindowRefresh : function()
	{
		var blnCallEventHandler = false;
		if(Smgr.Right!=document.body.offsetWidth||Smgr.Bottom!=document.body.offsetHeight) blnCallEventHandler=true; 
		Smgr.Right = document.body.offsetWidth;
		Smgr.Bottom = document.body.offsetHeight;
		Smgr.Height = document.body.offsetHeight;
		Smgr.Width = document.body.offsetWidth;
		
		if(blnCallEventHandler)
			Smgr.onWindowResize();
	}
	
};

window.onmousemove = Smgr.HandleMouseCoords;

//onload event
DOM.AddOnLoadEvent(function()
{
	
	Smgr.onWindowRefresh();
	
	//create resize thread
	Smgr.ListenerThread = setInterval("Smgr.onWindowRefresh()", 3000);
});
