// JavaScript Document

	var overlay = new Overlay();
	
	function Overlay()
	{
		this.fadeDuration = 200;
		this.fadeLevel = 0.8;
		this.lightboxWidth = 500;
		this.lightboxHeight = 300;
		this.posTop = 100;
		this.posLeft = 0;
		
		this.initialize = function()
		{
			var c = this;
			var arrayPageSize = this.pageSize();
			jQuery('body').append(jQuery(document.createElement('div')).attr({id:'oo_overlay'}));
			jQuery('body').append(jQuery(document.createElement('div')).attr({id:'oo_lightboxwrap'}));
			jQuery('#oo_overlay')
				.hide()
				.width(arrayPageSize[0])
				.height(arrayPageSize[1])
				.click(function(){c.end()});
			jQuery('#oo_lightboxwrap')
				.append(jQuery(document.createElement('div'))
					.attr({id:'oo_lightbox'})
					.width(this.lightboxWidth)
					.height(this.lightboxHeight))
				.hide()
			jQuery(window).resize(function(){
				var arrayPageSize = c.pageSize();
				jQuery('#oo_overlay').width(arrayPageSize[0]).height(arrayPageSize[1]);
			});
		}
		
		this.start = function()
		{
			var pageScroll = this.scrollOffsets();
			jQuery('select').css('visibility','hidden');
			jQuery('object').css('visibility','hidden');
			jQuery('embed').css('visibility','hidden');
			jQuery('#oo_lightboxwrap')
				.css('top',String(pageScroll[1]+this.posTop)+'px')
				.css('left',String(pageScroll[0]+this.posLeft)+'px').show();
			jQuery('#oo_overlay').fadeTo(this.fadeDuration,this.fadeLevel,function(){
				
			});
		}
		
		this.end = function()
		{
			jQuery('#oo_overlay').fadeTo(this.fadeDuration,0,function(){
				jQuery('#oo_lightboxwrap').hide();
				jQuery('#oo_overlay').hide();
				jQuery('select').css('visibility','visible');
				jQuery('object').css('visibility','visible');
				jQuery('embed').css('visibility','visible');
			});
		}
		
		this.content = function(obj)
		{
			jQuery('#oo_lightbox').empty().append(obj);
		}
		
		this.resize = function(w,h)
		{
			jQuery('#oo_lightbox').width(w).height(h);
		}
		
		this.position = function(t,l)
		{
			this.posTop = t;
			this.posLeft = l;
		}
		
		this.pageSize = function()
		{
			var xScroll,yScroll,windowWidth,windowHeight;
			if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}
			else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}
			else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
			if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth = self.innerWidth;}windowHeight = self.innerHeight;}
			else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}
			else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}	
			if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
			return[pageWidth,pageHeight];
		}
		
  		this.scrollOffsets = function() {
			var leftOffset = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;
			var topOffset = window.pageYOffset || document.documentElement.scrollTop  || document.body.scrollTop;
			return [leftOffset,topOffset];
		}
	}
	
	if (typeof jQuery != 'undefined'){ 
		jQuery(document).ready(function(){
			overlay.initialize();
		});
	}

