/**
 * Utility class for cross-browser position properties
 */
function PositionUtil(){}

PositionUtil.getObjectPosition = function(obj){
	return new ObjectPosition(obj);
}

PositionUtil.getDisplayHeight = function() {
	if (window.innerHeight) return parseInt(window.innerHeight);
	if (document.documentElement.clientHeight) return parseInt(document.documentElement.clientHeight);
	if (document.body.clientHeight) return parseInt(document.body.clientHeight);
	return -1;
}

PositionUtil.getDisplayWidth = function() {
	if (window.innerWidth) return parseInt(window.innerWidth);
	if (document.documentElement.clientWidth) return parseInt(document.documentElement.clientWidth);
	if (document.body.clientWidth) return parseInt(document.body.clientWidth);
	return -1;
}

PositionUtil.getHeightOffset = function() {
	if (window.pageYOffset) return parseInt(window.pageYOffset);
	if (document.documentElement.scrollTop) return parseInt(document.documentElement.scrollTop);
	if (document.body.scrollTop) return parseInt(document.body.scrollTop);
	return 0;
}

PositionUtil.getWidthOffset = function() {
	if (window.pageXOffset) return parseInt(window.pageXOffset);
	if (document.documentElement.scrollLeft) return parseInt(document.documentElement.scrollLeft);
	if (document.body.scrollLeft) return parseInt(document.body.scrollLeft);
	return 0;
}

/*
(kg) 
First arg is the marker to adjust the following elements height to
*/
PositionUtil.normalizeHeight = function(){

    var obj;
    var pos;

    if (arguments.length < 2)
        throw('Must provide marker block element id and at least one block element to adjust');
    
    var marker = PositionUtil.getObjectPosition(document.getElementById(arguments[0]));
    
	for(var i = 1; i != arguments.length; i++){
		obj = document.getElementById(arguments[i]);
		pos = PositionUtil.getObjectPosition(obj);
		obj.style.height = marker.top - pos.top + 'px';
	}	
}

function ObjectPosition(obj) {
	this.top = 0;
	this.left = 0;

	do {
		this.top += (isNaN(parseInt(obj.offsetTop))) ? 0 : parseInt(obj.offsetTop);
		this.left += (isNaN(parseInt(obj.offsetLeft))) ? 0 : parseInt(obj.offsetLeft);
	} while (obj = obj.offsetParent)
}	
