var MAG = Object.extend({}, MAG || {});
MAG.Mask = {
	layer: null,
	body: null,
	iframe: null,

	scroll_offset: function() {
		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;
		}
		return {left: scrOfX, top: scrOfY};
	},

	client_size: function()
	{
		return {width: window.innerWidth
						|| (document.documentElement && document.documentElement.clientWidth)
						|| (document.body && document.body.clientWidth)
						|| 0,
				height: window.innerHeight
						|| (document.documentElement && document.documentElement.clientHeight)
						|| (document.body && document.body.clientHeight)
						|| 0};
	},

	getDimensions: function()
	{
	  var myWidth = 0, myHeight = 0;
	  if( document.documentElement &&
	  				 ( document.documentElement.clientWidth ||
	  				 	 document.documentElement.clientHeight ) )
	  {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  }
	  else if( typeof( window.innerWidth ) == 'number' )
	  {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  }
	  else if( document.body &&
	  				 ( document.body.clientWidth ||
	  				 	 document.body.clientHeight ) )
	  {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	  return { width: myWidth, height: myHeight };
	},

	show: function(opacity)
	{
		this.body = $$('body').first();

		var dim_real = this.getDimensions();
		var dim_body = this.body.getDimensions();

		var fogWidth = dim_body.width > dim_real.width ? dim_body.width : dim_real.width;
		var fogHeight = dim_body.height > dim_real.height ? dim_body.height : dim_real.height;

		var fogWidth = dim_body.width > dim_real.width ? dim_body.width : dim_real.width;
		var fogHeight = dim_body.height > dim_real.height ? dim_body.height : dim_real.height;

		this.layer = (new Element('div')).setStyle({
			width: fogWidth + "px",
			height: fogHeight + "px",
			position: 'absolute',
			background: '#333',
			top: 0,
			left: 0,
			opacity: opacity / 100
		});

		if(/MSIE 6.0/.test(navigator.userAgent)) {
			$$('select').invoke('setStyle', {visibility: 'hidden'});
		}
		this.layer.style.zIndex = 500;
		this.body.insert(this.layer);
	},

	hide: function() {
		this.layer.remove();
		if(/MSIE 6.0/.test(navigator.userAgent)) {
			$$('select').invoke('setStyle', {visibility: 'visible'});
		}
	}
};
