/**
*	
*	Event.observe(window, 'load', function () {
*		test = new Lightbox('idOfMyDiv');
*	});
*	
*	Event.observe('lightboxLink', 'click', function () {
*		test.open();
*	});
*
*	Event.observe('closeLink', 'click', function () {
*		test.close();
*	});
*     
*/

if(ie7==undefined) {var ie7 = false; }

var Poper = Class.create({
	open : function () {
		this._centerWindow(this.container);
		this._fade('open', this.container);
		$(document.body).scrollTo();
	},
	
	close : function () {
		this._fade('close', this.container);
	},
	
	_fade : function fadeBg(userAction,whichDiv){
		if(userAction=='close'){
			new Effect.Opacity('bg_fade',
					   {duration:.5,
					    from:0.5,
					    to:0,
					    afterFinish:this._makeInvisible,
					    afterUpdate:this._hideLayer(whichDiv)});
		}else{
			new Effect.Opacity('bg_fade',
					   {duration:.5,
					    from:0,
					    to:0.5,
					    beforeUpdate:this._makeVisible,
					    afterFinish:this._showLayer(whichDiv)});
		}
	},
	
	_makeVisible : function makeVisible(){
		$("bg_fade").style.visibility="visible";
	},

	_makeInvisible : function makeInvisible(){
		$("bg_fade").style.visibility="hidden";
	},

	_showLayer : function showLayer(userAction){
		$(userAction).style.position = (ie7 ? 'absolute' : 'fixed');
		$(userAction).style.zIndex = '3000';
		$(userAction).show();		
	},
		
	_hideLayer : function hideLayer(userAction){
		$(userAction).hide();
	},
	
	_centerWindow : function centerWindow(element) {
		var windowHeight = parseFloat($(element).getHeight())/2; 
		var windowWidth = parseFloat($(element).getWidth())/2;

		if(typeof window.innerHeight != 'undefined') {
			$(element).style.top = Math.round(document.body.offsetTop + ((window.innerHeight - $(element).getHeight()))/2)+'px';
			$(element).style.left = Math.round(document.body.offsetLeft + ((window.innerWidth - $(element).getWidth()))/2)+'px';
		} else {
			$(element).style.top = Math.round(document.body.offsetTop + ((document.documentElement.offsetHeight - $(element).getHeight()))/2)+'px';
			$(element).style.left = Math.round(document.body.offsetLeft + ((document.documentElement.offsetWidth - $(element).getWidth()))/2)+'px';
		}
	},
	
	initialize : function(containerDiv, handle) {
		this.container = containerDiv;
		
		if($('bg_fade') == null) {
			var screens = new Element('div', {'id': 'bg_fade'});
			//screens.onclick = function(){poppup.close();}
			screens.style.position = 'absolute';
//			document.body.appendChild(screens);
			$(document.body).insert({bottom:screens});
		}
		//document.getElementById().style.height
		$('bg_fade').setStyle({height: document.body.clientHeight+'px'});
		
		//new Draggable(this.container, {handle:handle});
		this._hideLayer(this.container);
	}
});


