var Utils = {
   toViewportPosition: function(element) {
   	return this._toAbsolute(element,((Prototype.Browser.Opera || Prototype.Browser.WebKit)?true:false));
   },

   _toAbsolute: function(element,accountForDocScroll) {
      var x = this.getLeftPos(element);
      var y = this.getTopPos(element);

      if ( accountForDocScroll ) {
         x -= this.docScrollLeft();
         y -= this.docScrollTop();
      }
      return { x:x, y:y };
   },

   docScrollLeft: function() {
      if ( window.pageXOffset )
         return window.pageXOffset;
      else if ( document.documentElement && document.documentElement.scrollLeft )
         return document.documentElement.scrollLeft;
      else if ( document.body )
         return document.body.scrollLeft;
      else
         return 0;
   },

   docScrollTop: function() {
      if ( window.pageYOffset )
         return window.pageYOffset;
      else if ( document.documentElement && document.documentElement.scrollTop )
         return document.documentElement.scrollTop;
      else if ( document.body )
         return document.body.scrollTop;
      else
         return 0;
   },

   getClientHeight: function()
   {
   	var max = window.innerHeight ?
      window.height - window.innerHeight :
      document.body.scrollHeight -
        (document.documentElement.clientHeight ?
          document.documentElement.clientHeight : document.body.clientHeight);
    return max;
   },

	getViewportWidth: function()
	{
		var width 	= self.innerWidth;  // Safari
		var mode 	= document.compatMode;

		if ( mode || Prototype.Browser.IE )
		{ // IE, Gecko, Opera
			width = (mode == 'CSS1Compat') ?
				document.documentElement.clientWidth : // Standards
				document.body.clientWidth; // Quirks
		}
		return width;
	},

	getViewportHeight: function()
	{
		var height = self.innerHeight; // Safari, Opera
		var mode = document.compatMode;

		if ( (mode || Prototype.Browser.IE) && !Prototype.Browser.Opera ) { // IE, Gecko
		    height = (mode == 'CSS1Compat') ?
		            document.documentElement.clientHeight : // Standards
		            document.body.clientHeight; // Quirks
		}

		return height;
	},

	getLeftPos: function (obj)
	{
		var res = 0;
		while (obj)
		{
			res += obj.offsetLeft;
			obj = obj.offsetParent;
		}
		return res;
	},

	getTopPos: function (obj)
	{
		var res = 0;
		while (obj)
		{
			res += obj.offsetTop;
			obj = obj.offsetParent;
		}
		return res;
	}
};
