/**
  * Top namespace for jx widget library
  */
if (typeof(jx) == "undefined") {
	jx = {};
}
jx.pathRoot = "lib/";

/**
  * Single-hierarchy inheritance (class emulation)
  * @see    http://www.itsalleasy.com/2006/02/05/prototype-chain/
  */
if (typeof(jx.Class) == "undefined") {
	jx.Class = {};
}
/**
  * Extends one prototype by another.
  * The subtype will have two specialpurpose properties:
  *     superconstructor    The parent prototype's constructor
  *     supertype        The parent prototype
  */
jx.Class.extend = function(subClass, superconstructor) {
	var inlineSuper = function(){};
	inlineSuper.prototype = superconstructor.prototype;
	subClass.prototype = new inlineSuper();
	subClass.prototype.constructor = subClass;
	subClass.prototype.superconstructor = superconstructor;
	subClass.prototype.supertype = superconstructor.prototype;
}

/**
  * Various screen utils
  */
if (typeof(jx.Screen) == "undefined") {
	jx.Screen = {};
}
/**
  * The inner dimensions of the window or frame.
  * Straight out of : http://www.quirksmode.org/viewport/compatibility.html
  */
jx.Screen.getScreenDimensions = function() {
	var x,y;
	if (window.innerHeight) {
		// all except Explorer
		x = window.innerWidth;
		y = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) {
		// other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return {
		width : x,
		height : y
	}
}
/**
  * emulates sizeToContent for browsers that doesn't support it natively
  * @see http://www.quirksmode.org/viewport/compatibility.html
  */
jx.Screen.sizeToContent = function() {
	if (window.sizeToContent) {
		window.sizeToContent();
	} else {
		var innerX,innerY;
		if (window.innerHeight) {
			// all except Explorer
			innerX = window.innerWidth;
			innerY = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			// Explorer 6 Strict Mode
			innerX = document.documentElement.clientWidth;
			innerY = document.documentElement.clientHeight;
		} else if (document.body) {
			// other Explorers
			innerX = document.body.clientWidth;
			innerY = document.body.clientHeight;
		}

		var pageX,pageY;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) {
			// all but Explorer Mac
			pageX = document.body.scrollWidth;
			pageY = document.body.scrollHeight;
		} else {
			// Explorer Mac;
			//would also work in Explorer 6 Strict, Mozilla and Safari
			pageX = document.body.offsetWidth;
			pageY = document.body.offsetHeight;
		}
		window.resizeBy(pageX - innerX, pageY - innerY);
	}
};
/**
  * crossbrowser setting of opacity
  */
jx.Screen.setOpacity = function(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	var theStyle = obj.style;
	theStyle.filter = "alpha(opacity=" + opacity + ")";
	theStyle.opacity = theStyle.MozOpacity = theStyle.KhtmlOpacity = (opacity / 100);
};
jx.Screen.getElementPosition = function(elm) {
	var el = elm;
	var ol = el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }

	var el = elm;
	var ot = el.offsetTop;
	while ((el=el.offsetParent) != null) { ot += el.offsetTop; }

	return {
		x : ol,
		y : ot
	}
};

function popwin(href, height, width) {
	if (typeof(height) == "undefined") {
		height = 700;
	}
	if (typeof(width) == "undefined") {
		width = 700;
	}
	var d = window.open(href, "puppy", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height);
	d.focus();
	return false;
}

