/*  Screen Size functions
 *
 *--------------------------------------------------------------------------*/
if (!Prototype) throw('Need prototype...'); else
if (parseFloat(Prototype.Version.substr(0,3)) < 1.6) throw('Wrong version of prototype...');


/* Window */
Object.extend(window, {
	setResolution: function (element, minWidth, minHeight, sResize) {
		if (!sResize){
			var oldonresize = window.onresize;

			window.onresize = function() {
				window.setResolution(element, minWidth, minHeight, true);

				if (Object.isFunction(oldonresize))
					oldonresize();
			}
		}
		setTimeout(function() {
			element = $(element);
			if (element != null){
				var minWidthBrowser = this.getDimensions().windowWidth,
					minHeightBrowser = this.getDimensions().windowHeight;
		
				element.width = (minWidthBrowser <= minWidth) ? minWidth : '100%';
				element.height = (minHeightBrowser <= minHeight) ? minHeight : '100%';
			}
		},0);
	},

	getDimensions: function () {
		var body = document.body,
			docElement = document.documentElement,
			xScroll, yScroll, windowWidth, windowHeight;

		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (body.scrollHeight > body.offsetHeight){ // all but Explorer Mac
			xScroll = body.scrollWidth;
			yScroll = body.scrollHeight;
		}
		else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = body.offsetWidth;
			yScroll = body.offsetHeight;
		}

		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		}
		else if (docElement && docElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = docElement.clientWidth;
			windowHeight = docElement.clientHeight;
		}
		else if (body) { // other Explorers
			windowWidth = body.clientWidth;
			windowHeight = body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if (yScroll < windowHeight)
			pageHeight = windowHeight;
		else
			pageHeight = yScroll;
	
		// for small pages with total width less then width of the viewport
		if (xScroll < windowWidth)
			pageWidth = windowWidth;
		else
			pageWidth = xScroll;

		return {
			pageWidth: pageWidth,
			pageHeight: pageHeight,
			windowWidth: windowWidth,
			windowHeight: windowHeight
		};
	},

	getPageScroll: function (){
		var body = document.body,
			docElement = document.documentElement,
		    xScroll, yScroll;
	
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (docElement && docElement.scrollTop){
			yScroll = docElement.scrollTop;
			xScroll = docElement.scrollLeft;
		} else if (body) {
			yScroll = body.scrollTop;
			xScroll = body.scrollLeft;	
		}
    
		return {top: yScroll, left: xScroll};
	}
});