/*
 * Function list:
 * 		getSize(aAxis:string:"width"||"height")
 * 			definition: Get's the size of the visible inner window - the scroll bars excluded.
 *		getFullSize(aAxis:string:"width"||"height")
 * 			definition: Get's the size of the whole document, including the invisible scroll area (if there).
 * 		getPreloadSize 
 *  		definition: Get's the window size before scroll bars.
 */

var windower = {
	ready : function(aFunction) {
		/* for Mozilla/Opera9 */
		if (document.addEventListener) {
		    document.addEventListener("DOMContentLoaded", aFunction, false);
		}
		
		/* for Internet Explorer */
		/*@cc_on @*/
		/*@if (@_win32)
		    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		    var script = document.getElementById("__ie_onload");
		    script.onreadystatechange = function() {
		        if (this.readyState == "complete") {
		            aFunction(); // call the onload handler
		        }
		    };
		/*@end @*/
		
		/* for Safari */
		if (/WebKit/i.test(navigator.userAgent)) { // sniff
		    _timer = setInterval(function() {
		        if (/loaded|complete/.test(document.readyState)) {
		            aFunction(); // call the onload handler
		            clearInterval(_timer);
		        }
		    }, 10);
		}
	},
	
	getScroll : function (aAxis) {
		var _x = 0, _y = 0;
		if(typeof(window.pageYOffset) == "number") {
			//Netscape compliant
			_x = window.pageXOffset;
			_y = window.pageYOffset;
		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop )) {
			//DOM compliant
			_x = document.body.scrollLeft;
			_y = document.body.scrollTop;
		} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			//IE6 standards compliant mode
			_x = document.documentElement.scrollLeft;
			_y = document.documentElement.scrollTop;
		}
		
		if(aAxis == "width") { return _x; }
			else if(aAxis == "height") { return _y; }
			else { return { _x: _x, _y: _y }
		}
	},
	
	getSize : function(aAxis) {
		// The dimensions with scroll bars
		var body = document.body;
		var element = document.createElement("div");
		var oldBodyHeight = body.style.height;
		
		// Create an element that is the size of the window
		// offset it and then get the dimensions
		// delete it, reset
		element.style.position = "absolute";
		element.style.top = "-2000px";
		element.style.left = "-2000px";
		body.appendChild(element);
		body.style.height = "100%";
		element.style.width = "100%";
		element.style.height = "100%";
		
		// Set the dimensions 
		_x = element.offsetWidth;
		_y = element.offsetHeight;
		
		// Reset
		body.removeChild(body.lastChild);
		body.style.height = oldBodyHeight;
		
		if(aAxis == "width") { return _x; }
			else if(aAxis == "height") { return _y; }
			else { return { _x: _x, _y: _y } }
	},
	
	getFullSize : function(aAxis) {
		// Everything including scroll stuff
		var _x = document.documentElement.scrollWidth > document.body.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
		var _y = document.documentElement.scrollHeight > document.body.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
		
		if(aAxis == "width") { return _x; }
			else if(aAxis == "height") { return _y; }
			else { return { _x: _x, _y: _y } }
	},
	
	getPreloadSize : function(aAxis) {
		// The dimensions without scroll bars
		var _x = 0, _y = 0;
		if(typeof(window.innerWidth) == "number") { // !=ie
			_x = window.innerWidth;
			_y = window.innerHeight;
		} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			// >= ie4
			_x = document.documentElement.clientWidth;
			_y = document.documentElement.clientHeight;
		} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
			// == ie4
			_x = document.body.clientWidth;
			_y = document.body.clientHeight;
		}
		if(aAxis == "width") { return _x; }
			else if(aAxis == "height") { return _y; }
			else { return { _x: _x, _y: _y } }
	}
}

