
function WindowControl (window)
	{
	this.window = window ;
	this.scrollX = 0 ;
	this.scrollY = 0 ;
	//this.postback = new Postback (this.window) ;
	
	this.window.onfocus = WindowControl_onWindowFocus ;
	this.window.onload = WindowControl_onWindowLoad ;
	this.window.onunload = WindowControl_onWindowUnload ;

	this.addEventListener (window) ;
	}

function WindowControl_onWindowFocus ()
	{
	if (this.windowControl)
		if (this.windowControl.notifyWindowFocus)
			this.windowControl.notifyWindowFocus () ;
	}

function WindowControl_onWindowLoad ()
	{
	if (this.windowControl)
		if (this.windowControl.notifyWindowLoad)
			this.windowControl.notifyWindowLoad () ;
	}

function WindowControl_onWindowUnload ()
	{
	if (this.windowControl)
		if (this.windowControl.notifyWindowUnload)
			this.windowControl.notifyWindowUnload () ;
	}

WindowControl.prototype = new EventSource () ;

WindowControl.prototype.WINDOW_FOCUS	= 'WindowFocus' ;
WindowControl.prototype.WINDOW_LOAD		= 'WindowLoad' ;
WindowControl.prototype.WINDOW_UNLOAD	= 'WindowUnload' ;
WindowControl.prototype.WINDOW_POSTBACK	= 'WindowPostback' ;
WindowControl.prototype.WINDOW_SCROLLED	= 'WindowScrolled' ;

WindowControl.prototype.notifyWindowFocus = function ()
	{
	this.dispatchEvent (this.WINDOW_FOCUS) ;
	}

WindowControl.prototype.notifyWindowLoad = function ()
	{
	this.dispatchEvent (this.WINDOW_LOAD) ;
	}

WindowControl.prototype.notifyWindowUnload = function ()
	{
	this.dispatchEvent (this.WINDOW_UNLOAD) ;
	}

WindowControl.prototype.notifyWindowPostback = function (action)
	{
	this.window.postback.scrollX = this.scrollX ;
	this.window.postback.scrollY = this.scrollY ;
	this.dispatchEvent (this.WINDOW_POSTBACK) ;
	}

WindowControl.prototype.scrollTo = function (x, y)
	{
	this.window.scrollTo (x, y) ;
	this.notifyWindowScrolled () ;
	}

WindowControl.prototype.notifyWindowScrolled = function ()
	{
	this.scrollX = this.scrollY = 0 ;
	if (this.window.scrollX || this.window.scrollY)
		{
		this.scrollX = this.window.scrollX ;
		this.scrollY = this.window.scrollY ;
		}
	else if (typeof (this.window.pageYOffset) == 'number')
		{
		this.scrollX = this.window.pageXOffset ;
		this.scrollY = this.window.pageYOffset ;
		}
	else if (this.window.document.documentElement && (this.window.document.documentElement.scrollLeft || this.window.document.documentElement.scrollTop))
		{
		this.scrollX = this.window.document.documentElement.scrollLeft ;
		this.scrollY = this.window.document.documentElement.scrollTop ;
		}
	else if (this.window.document.body && (this.window.document.body.scrollLeft || this.window.document.body.scrollTop))
		{
		this.scrollX = this.window.document.body.scrollLeft ;
		this.scrollY = this.window.document.body.scrollTop ;
		}

	this.dispatchEvent (this.WINDOW_SCROLLED, this.scrollX, this.scrollY) ;
	}

if (!window.windowControl)
	window.windowControl = new WindowControl (window) ;
