var WindowUtilities = {
  // From script.aculo.us
  getWindowScroll: function() {
    var w = window;
      var T, L, W, H;
      with (w.document) {
        if (w.document.documentElement && documentElement.scrollTop) {
          T = documentElement.scrollTop;
          L = documentElement.scrollLeft;
        } else if (w.document.body) {
          T = body.scrollTop;
          L = body.scrollLeft;
        }
        if (w.innerWidth) {
          W = w.innerWidth;
          H = w.innerHeight;
        } else if (w.document.documentElement && documentElement.clientWidth) {
          W = documentElement.clientWidth;
          H = documentElement.clientHeight;
        } else {
          W = body.offsetWidth;
          H = body.offsetHeight
        }
      }
      return { top: T, left: L, width: W, height: H };
    
  }, 
  //
  // getPageSize()
  // Returns array with page width, height and window width, height
  // Core code from - quirksmode.org
  // Edit for Firefox by pHaez
  //
  getPageSize: function(){
  	var xScroll, yScroll;

  	if (window.innerHeight && window.scrollMaxY) {	
  		xScroll = document.body.scrollWidth;
  		yScroll = window.innerHeight + window.scrollMaxY;
  	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  		xScroll = document.body.scrollWidth;
  		yScroll = document.body.scrollHeight;
  	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  		xScroll = document.body.offsetWidth;
  		yScroll = document.body.offsetHeight;
  	}

  	var windowWidth, windowHeight;

  	if (self.innerHeight) {	// all except Explorer
  		windowWidth = self.innerWidth;
  		windowHeight = self.innerHeight;
  	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  		windowWidth = document.documentElement.clientWidth;
  		windowHeight = document.documentElement.clientHeight;
  	} else if (document.body) { // other Explorers
  		windowWidth = document.body.clientWidth;
  		windowHeight = document.body.clientHeight;
  	}	
  	var pageHeight, pageWidth;

  	// for small pages with total height less then height of the viewport
  	if(yScroll < windowHeight){
  		pageHeight = windowHeight;
  	} else { 
  		pageHeight = yScroll;
  	}

  	// for small pages with total width less then width of the viewport
  	if(xScroll < windowWidth){	
  		pageWidth = windowWidth;
  	} else {
  		pageWidth = xScroll;
  	}

  	return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  },
  getPageScrolling: function(){
       var scroll = {left:0, top:0};
       scroll.top = (document.body.scrollTop > document.documentElement.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
       scroll.left = (document.body.scrollLeft > document.documentElement.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft;
       return scroll;
  }
}
var Pos = {
    overlayObj: function(over, obj, options){
        /**
         * over - what object to place over
         * obj - what object to cover
         * options.minwidth
         * options.minheight
         * options.maxwidth
         * options.maxheight
         */
        if (options == undefined) options = {};
        if ( typeof(obj) == 'string' ) obj = $(obj);
        if ( typeof(over) == 'string' ) over = $(over);
        var dimensions = Element.getDimensions(obj);
        var pos = Position.cumulativeOffset(obj);
        over.style.position = 'absolute';
        var width = dimensions.width;
        var height = dimensions.height;
        if (options.minwidth != undefined) if (width < options.minwidth) width = options.minwidth;
        if (options.minheight != undefined) if (height < options.minheight) height = options.minheight;
        if (options.maxwidth != undefined) if (width > options.maxwidth) width = options.maxwidth;
        if (options.maxheight != undefined) if (height > options.maxheight) height = options.maxheight;
        var offset = Position.cumulativeOffset(Position.offsetParent($(over)));
        over.style.width = parseInt(width) + 'px'; 
        over.style.height = parseInt(height) + 'px'; 
        over.style.top = parseInt(pos[1]-offset[1]) + 'px'; 
        over.style.left = parseInt(pos[0]-offset[0]) + 'px';
        Element.show(over); 
    },
    centerObject: function(obj){
        if (typeof(obj) == 'string') obj = $(obj);
        var sizes = WindowUtilities.getPageSize();
        var offset = Position.cumulativeOffset(Position.offsetParent(obj));
        var elemSizes = Element.getDimensions(obj);
        var scroll = WindowUtilities.getPageScrolling();
        
        var top = parseInt(scroll.top - offset[1] + sizes.windowHeight/2 - elemSizes.height/2);
        var left = parseInt(scroll.left - offset[0] + sizes.windowWidth/2 - elemSizes.width/2);
        if (top < 0) top=0;
        if (left < 0) left=0;
        obj.style.top	= top + 'px';
        obj.style.left	= left +'px';
    }
}
overlayObject = function(obj){
    Pos.overlayObj('orginizerloadindicator', obj, {minheight:40});
}
overlayOff = function(){
    Element.hide('orginizerloadindicator');
}