
// Global "corrector" for IE/Mac et al., but doesn't hurt others
// (this is for centerIt function only)
//var fudgeFactor = {top:-1, left:-1};


// Position an object at a specific pixel coordinate
function shiftTo(selector, x, y) {
	$(selector).css({"left" : x, "top" : y});
}


// Center a positionable element whose name is passed as 
// a parameter in the current window/frame, and show it
function centerxy(id) {
		
		id = '#' + id;
		
    // set fudgeFactor values only first time
    /*if (fudgeFactor.top == -1) {
        if ((typeof obj.offsetTop == "number") && obj.offsetTop > 0) {
            fudgeFactor.top = obj.offsetTop;
            fudgeFactor.left = obj.offsetLeft;
        } else {
            fudgeFactor.top = 0;
            fudgeFactor.left = 0;
        }
        if (obj.offsetWidth && obj.scrollWidth) {
            if (obj.offsetWidth != obj.scrollWidth) {
                obj.style.width = obj.scrollWidth;    
            }
        }
    }*/
    
    var x = Math.round(($(window).width()/2) - ($(id).width()/2)) + "px";
    var y = Math.round(($(window).height()/2) - ($(id).height()/2)) + "px";
    
    shiftTo(id, x, y);
    $(id).css("visibility","visible");    
}

// use this instead of $(document).ready, due to strange
// bug in Safari (it can't get object widths immediately

$(window).load(function(){
	// assume that the first child <div> within the document
	// <body> is the main container, which is to be centered
	var target = $('body div:first-child').attr("id");
	
	centerxy(target);
		
	$(window).resize(function() {
		centerxy(target);
	});
});

