﻿ 
        jQuery.fn.center = function() {
        return this.each(function() {
                var t = jQuery(this);
                t.css({position: 'fixed'});

                var w = t.width(), 
                        h = t.height(), 
                        lrPadding = parseInt(t.css('paddingLeft'), 10) + parseInt(t.css('paddingRight'), 10), 
                        lrBorder = parseInt(t.css('borderLeftWidth'), 10) + parseInt(t.css('borderRightWidth'), 10), 
                        tbPadding = parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10), 
                        tbBorder = parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10), 
                       // leftMargin = (w + lrPadding + lrBorder) / 2;
                       leftMargin = (GetWidth() - w)/4;
                       // alert('leftM: ' + leftMargin +'pageWidth: ' + GetWidth() +'Width: ' + w +'leftM: ');
                        topMargin = (h + tbPadding + tbBorder) / 2;


                t.css({
                        position: 'fixed', 
                        left: '40%', 
                        top: '40%', 
                        marginLeft: '-' +leftMargin +'px', 
                       // marginTop: '-' +topMargin +'px', 
                        zIndex: '200'
                });

        });
};


// Sizes

// Size Object
function Size()
{

}

Size.prototype._windowX;
Size.prototype._windowY;
Size.prototype._scrOfY;
Size.prototype._scrOfY;
Size.prototype._y;
Size.prototype._x;
//Get Sizes
function GetSizes()
{
//alert( getDocHeight());
    var result = new Size();
    
    result._windowX = GetWidth() ;
    result._windowY = GetHeight();    
    var scrolls = getScrollXY();
    result._scrOfX = scrolls._x;
    result._scrOfY = scrolls._y;
    result._y =getDocHeight();
    result._x = getDocWidth();
    //alert('x: ' + result._scrOfX +'y: ' + result._scrOfY+'Wx: ' + result._windowX+'Wy: ' + result._windowY);
    return result;
}
// window size
 function GetHeight()
        {
            var y = 0;
            if (window.innerHeight) {
                y=window.innerHeight;
            }
            else if (document.documentElement && document.documentElement.clientHeight) {
                y=document.documentElement.clientHeight;
            }
            else if (document.body) {
                y=document.body.clientHeight;
            }
            return y;
        }
        
        function GetWidth()
        {
                var x = 0;
                if (self.innerHeight)
                {
                        x = self.innerWidth;
                }
                else if (document.documentElement && document.documentElement.clientHeight)
                {
                        x = document.documentElement.clientWidth;
                }
                else if (document.body)
                {
                        x = document.body.clientWidth;
                }
                return x;
        }
// Brower size
function getScrollXY() {
    var result = new Size();
      var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      result._x= scrOfX;
        result._y = scrOfY;
      return result;
}
function getDocHeight() {
   var db = document.body;
   var dde = document.documentElement;
   return Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight)
}
function getDocWidth() {
   var db = document.body;
   var dde = document.documentElement;
   return Math.max(db.scrollWidth, dde.scrollWidth, db.offsetWidth, dde.offsetWidth, db.clientWidth, dde.clientWidth)
}