/**
 * taken from http://textsnippets.com/tag/prototype
 */

Position.GetWindowSize = function(w) {
	var width, height;
        w = w ? w : window;
        this.width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
        this.height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
        
        return this;
}

Position.Center = function(element, parent) {
        var w, h, pw, ph;
        var d = Element.getDimensions(element);
        w = d.width;
        h = d.height;
        Position.prepare();
        if (!parent) {
                var ws = Position.GetWindowSize();
                pw = ws.width;
                ph = ws.height;
        } else {
                pw = parent.offsetWidth;
                ph = parent.offsetHeight;
        }
		// Position.deltaX, Position.deltaY is the scrollbar position
        element_top = (ph/2) - (h/2);
        
        // FIX the IE 6 issue
        nua = navigator.userAgent;
        fix = false;
        op=(nua.indexOf('Opera')!=-1);
        if ((nua.indexOf('MSIE')!=-1)&&!op) {
          	str_pos = nua.indexOf('MSIE');
            nu = nua.substr((str_pos+5),3);	
            brow = 'Microsoft Internet Explorer';
            fix = (nu.substring(0,1)==6);
        }
        if (fix) element_top = element_top + Position.deltaY;
        // end of the FIX
        
        element.style.top = element_top + 'px'
        element.style.left = (pw/2) - (w/2) + "px";
}

