var myCover = 
{
	cover_content:'cover_content',
	cover_id:'cover',
	
	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;
		}	
		
		// 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;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;

	},
	
	getScrollerWidth: function() 
	{
	    var scr = null;
	    var inn = null;
	    var wNoScroll = 0;
	    var wScroll = 0;

	    // Outer scrolling div
	    scr = document.createElement('div');
	    scr.style.position = 'absolute';
	    scr.style.top = '-1000px';
	    scr.style.left = '-1000px';
	    scr.style.width = '100px';
	    scr.style.height = '50px';
	    // Start with no scrollbar
	    scr.style.overflow = 'hidden';

	    // Inner content div
	    inn = document.createElement('div');
	    inn.style.width = '100%';
	    inn.style.height = '200px';

	    // Put the inner div in the scrolling div
	    scr.appendChild(inn);
	    // Append the scrolling div to the doc

	    document.body.appendChild(scr);

	    // Width of the inner div sans scrollbar
	    wNoScroll = inn.offsetWidth;
	    // Add the scrollbar
	    scr.style.overflow = 'auto';
	    // Width of the inner div width scrollbar
	    wScroll = inn.offsetWidth;

	    // Remove the scrolling div from the doc
	    document.body.removeChild(
	    document.body.lastChild);

	    // Pixel width of the scroller
	    return (wNoScroll - wScroll);
	},
		
	showCover: function()
	{
		$('cover').style.display = 'block';
		
		var arrayPageSize = myCover.getPageSize();
		
		var pageWidth = arrayPageSize[0];
		var pageHeight = arrayPageSize[1];

		var scrollerWidth = myCover.getScrollerWidth()
		
		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 - scrollerWidth;
			windowHeight = document.documentElement.clientHeight - scrollerWidth;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth - scrollerWidth;
			windowHeight = document.body.clientHeight - scrollerWidth;
		}

		$('cover').style.width = windowWidth + 'px';
		$('cover').style.height = pageHeight + 'px';
		
		var top = (windowHeight - $('cover_content').getDimensions().height)/2;
		var left = (windowWidth - $('cover_content').getDimensions().width)/2;
		
		if( top < 0 ) top = 0;
		if( left < 0 ) left = 0;
		
		$('cover_content').style.top =  top + 'px';
		$('cover_content').style.left =  left + 'px';
	},
	
	hideCover: function()
	{
		return true;
		$('cover').style.display = 'none';
	},
	
	cancelBubble: function(e)
	{
		if (!e) var e = window.event

		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
	
		return false;
	},
	
	init: function()
	{
		$('cover').onclick = function(){myCover.hideCover();};
		$('cover_close').onclick = function(){myCover.hideCover();};
		$('cover_content').onclick = function(event){myCover.cancelBubble(event);};
		new Draggable('cover_content', { scroll: window,  handle: 'cover_content' });
		
	}

}

window.addEvent('domready', myCover.init.bind(myCover) );

if (document.all && !window.opera)
{ 
  document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
  var contentloadtag=document.getElementById("contentloadtag")
  contentloadtag.onreadystatechange=function()
  {
    if (this.readyState=="complete")
      myCover.init();
  }
}


/*
window.addEvent('domready', 
function()
{ 
  new Ajax.Request('xxx', {
  onSuccess: function(response) 
  {
		$('cover_content').innerHTML = response.responseText;
  }
  });
}
); */
