

/**
 * @author Mark Cassar
 * @version 1.0.0 
 * @lastmodified 19/03/07
 */

if (!com) var com = new Object();
if (!com.cs) com.cs = new Object();
if (!com.cs.general) com.cs.general = new Object();
if (!com.cs.general.Window) com.cs.general.Window = new Object();

//REQUIREMENTS
if (!Class) alert("com.cs.general.Window: Please include Class com.cs.defineClass");
if (!com.cs.general.BrowserDetect) alert("com.cs.general.Window: Please include 'com.cs.general.BrowserDetect'");
//------------

com.cs.general.Window = Class({
	name: "Window",
	statics: {
		getX : function() {
			if (window.screenLeft) return window.screenLeft; //IE and others 
			if (window.screenX) return window.screenX; //Firefox and others
			return 0;
		},
		getY : function() {
			if (window.screenTop) return window.screenTop; //IE and others
			if (window.screenY) return window.screenY; //Firefox and others
			return 0;
		},
		
		getDocHeight : function() {
		    return document.height;
		},
		
		getDocWidth : function() {
		alert(document + ":" + document.width);
		    return document.width;
		},
		/**
		 * This is the get width
		 */
		getWidth : function() {
		    
			if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; // IE6 with doctype
			
			if (window.innerWidth) return window.innerWidth; //All but IE
			if (document.body.clientWidth) return document.body.clientWidth; //	IE other
			return 0;
		},
		getHeight : function() {
			if (window.innerHeight) return window.innerHeight; //All but IE
			if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; // IE6 with doctype
			if (document.body.clientHeight) return document.body.clientHeight; // IE other
			return 0;
		},

		getScrollX : function() {
			
			if (window.pageXOffset) return window.pageXOffset; //All but IE
			
			if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; // IE6 with doctype
			
			if (document.body.scrollLeft) return document.body.scrollLeft; //	IE other
			return 0;
		},
		getScrollY : function() 
		{
			if (window.pageYOffset) return window.pageYOffset; //All but IE
			if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; // IE6 with doctype
			if (document.body.scrollTop) return document.body.scrollTop; //	IE other
			return 0;
		},
		resize : function(width, height) 
		{ //this is so as to take into account the real size of the window
		    
		    if (isExplorer)
		    {
		    // create the checkpoint element
                var cp = document.createElement("div");
                cp.style.position = "absolute";
                cp.style.width = "0px";
                cp.style.height = "0px";
                cp.style.right = "0px";
                cp.style.bottom = "0px";
                // we can only read it's position after we
                // insert it into the document
                document.body.appendChild(cp);

                // here we get the actual client size
                var current_width = cp.offsetLeft;
                var current_height = cp.offsetTop;
                 // here we find out how much more we need
                // in order to get to the needed W x H size
                // (or in other words, we compute the size of
                // window decorations: border, scroll bars, title)
                var dw = width - current_width;
                var dh = height - current_height + 10;
                alert(dh);
                // and _finally_ we get what we need
                window.resizeBy(dw, dh);

                // we can safely delete the checkpoint now
                document.body.removeChild(cp);
		    }
		    else
		    {
		        window.innerHeight = height;
		        window.innerWidth = width;
		    }
		},
		centerInScreen : function()
		{
            var x,y,width,height;
            width = this.getWidth();
            height = this.getHeight();
            x = (screen.availWidth - width) / 2;
            y = (screen.availHeight - height) / 2;
            window.moveTo(x,y);
		}
	}
});

