/* 
 * QJS.qWindow
 *  Provides information and usefull methods for manipulation the browser window.
 *
*/ 
qWindow = {};


// DOM Detection -- critical because different browsers expose styles in different ways
if (document.documentElement && 
	document.documentElement.clientWidth) {          // ----- Explorer 6 strict -----
	
	qWindow.element = document.documentElement;
	
} else if (document.body && 
	document.body.clientWidth){						// ----- Explorer, Gecko -----
	
	qWindow.element = document.body;

} else {											// ----- Netscape 4 -----
	
	// Dimensions/Positioning Functions
	qWindow.getWidth = function () {
		w = window.innerWidth;
    	if(document.height > window.innerHeight) w -= 16;
		return w;
	}
	qWindow.getHeight = function () {
		h = window.innerHeight;
    	if(document.width > window.innerWidth) h -= 16;
		return h;
	}
	qWindow.getScrollLeft = function () { return pageXOffset; }
	qWindow.getScrollTop = function () { return pageYOffset; }
}

// Dimensions/Positioning Functions
if (!qWindow.getWidth) {
	qWindow.getWidth = function () { return this.element.clientWidth; }
	qWindow.getHeight = function () { return this.element.clientHeight; }
	qWindow.getScrollLeft = function () { return this.element.scrollLeft; }
	qWindow.getScrollTop = function () { return this.element.scrollTop; }
}
qWindow.resizeTo = function (w, h) { window.resizeTo(w, h); }

// Popup function
qWindow.open = function(url,name,width,height,xpos,ypos,chrome,scroll,fullscreen) {
	var x, y, w, h, moveX=0, moveY=0, features="";
	chrome = chrome ? "yes" : "no";
	scroll = scroll ? "yes" : "no";
	features += "toolbar="+chrome;
	features += ",menubar="+chrome;
	features += ",location="+chrome;
	features += ",status="+chrome;
	features += ",scrollbars="+scroll;
	features += ",resizable="+scroll;
	features += ",alwaysRaised=true"
	if(width) features += ",width="+width;
	if(height) features += ",height="+height;
	if(fullscreen) features += ",fullscreen=yes";
	if(xpos){
		w = window.screen ? window.screen.availWidth : 0;
		width = parseInt(width);
		switch(xpos){
			case "left": x = 0; break;
			case "center": x = Math.round((w-width)/2); break;
			case "right": x = w-width; break;
			default: x = xpos;
		}
		features += ",screenX="+x+",left="+x;
	}
	if(ypos){
		h = window.screen ? window.screen.availHeight : 0;
		height = parseInt(height);
		switch(ypos){
			case "top": y = 0; break;
			case "middle": y = Math.round((h-height)/2); break;
			case "bottom": y = h-height; break;
			default: y = ypos;
		}
		features += ",screenY="+y+",top="+y;
	}
	this.element = window.open(url,name,features);
}

