/**
 * This file contains functions to help position
 * a div or other element within a page.
 */
 
 
 
/**
 * NAME: positionAbsDiv_Center
 * Arguments: 	id (Id of the element)
 *              offset_x (amount to offset the div) [Optional]
 *				offset_y (amount to offset the div) [Optional]
 * 				w (Width of the element)  [Optional]
 *				h (Height of the element) [Optional]
 *
 * 
 * This function will absolutely position a div on
 * the screen in the center.
 */
function positionAbsDiv_Center(id,offset_x,offset_y,w,h) {

	/**
	 * We need to get the height and width
	 * of the element we are positioning. 
	 * If it was not passed to the function
	 * we will try to figure it out. If the 
	 * dimensions were not defined or we cannot
	 * retrieve them we will put in some default 
	 * values.
	 */
    var offset_x = (offset_x == null) ? 0 : offset_x;
    var offset_y = (offset_y == null) ? 0 : offset_y;
	var myWidth = (w == null) ? 0 : w;
	var myHeight = (h == null) ? 0 : h;
	
	if (myHeight == 0) {
		myHeight = document.getElementById(id).offsetHeight;
        //alert(myHeight)
		if (myHeight == 0 || typeof(myHeight) == "undefined") {
			myHeight = 574;
		}		
	}
	
	if (myWidth == 0) {
		myWidth = parseInt(document.getElementById(id).style.width);
        //alert(myWidth)
		if (myWidth == 0 || typeof(myWidth) == "undefined" || isNaN(myWidth)) {
			myWidth = 1210;
		}		
	}
	//alert('myHeight: ' + myHeight + " myWidth: " + myWidth);
    myHeight = myHeight / 2;
	myWidth  = myWidth / 2;
    //alert('myHeight: ' + myHeight + " myWidth: " + myWidth);
	
	// VIEWPORT HEIGHT
	var screenWidth = 0
	var screenHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		screenWidth = window.innerWidth;
		screenHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		screenWidth = document.documentElement.clientWidth;
		screenHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		screenWidth = document.body.clientWidth;
		screenHeight = document.body.clientHeight;
	}
	
	var scrollTop   = window.pageYOffset || document.documentElement.scrollTop || 0; 
	var scrollLeft  = window.pageXOffset || document.documentElement.scrollLeft || 0;

    //alert('ScrollLeft: ' + scrollLeft + '\nscreenWidth: ' + screenWidth + '\nmyWidth: ' + myWidth + '\noffset_x: ' + offset_x);

	var topPadding  = Math.round(scrollTop + ((screenHeight/2)-(myHeight+offset_y)));
	var leftPadding = Math.round(scrollLeft + ((screenWidth/2)-(myWidth+offset_x)));

    //alert('Top Padding: ' + topPadding + " Left Padding: " + leftPadding);
	
	document.getElementById(id).style.top = topPadding + "px";
	document.getElementById(id).style.left = leftPadding + "px";

    //alert('AM I HERE?');

}
