﻿var Lightbox = Class.create({	
        initialize : function(containerDiv) {
	        this.container = containerDiv;
	        this._hideLayer(this.container);
        },
        _hideLayer : function hideLayer(userAction){
	        $(userAction).style.display="none";
        },
        _makeVisible : function makeVisible(){
             if($('bg_fade') == null) {
                shade = new Element('div', {'id': 'bg_fade',
                    'style': 'visibility=hidden;'});
                document.body.appendChild(shade);
             }
             $("bg_fade").setOpacity(0);
             $("toolsTablePopIn").setOpacity(0);
             $("bg_fade").style.backgroundColor="#FFFFFF";
             $("bg_fade").style.visibility="visible";
             $("toolsTablePopIn").style.visibility="visible";
             $("bg_fade").style.position="absolute";
             $("bg_fade").style.zIndex = 99998;
             $("bg_fade").style.height='332px';
        },

        _makeInvisible : function makeInvisible(){
             $("bg_fade").setOpacity(0);
             $("bg_fade").style.visibility="hidden";
             $("toolsTablePopIn").style.visibility="hidden";
             $("bg_fade").style.height='2px';
        },
        _showLayer : function showLayer(userAction){
	        $(userAction).style.display="block";
        },
        _hideLayer : function hideLayer(userAction){
	        $(userAction).style.display="none";
        },
        _fade : function fadeBg(userAction,whichDiv){
	        if(userAction=='close'){
		        new Effect.Opacity('bg_fade',
				           {duration:.5,
				            from:1,
				            to:0,
				            afterFinish:this._makeInvisible(),
				            afterUpdate:this._hideLayer(whichDiv)});
				 new Effect.Opacity('toolsTablePopIn',
				           {duration:.5,
				            from:1,
				            to:0,
				            afterFinish:this._makeInvisible(),
				            afterUpdate:this._hideLayer("toolsTablePopIn")});           
				            
	        }else{
		        new Effect.Opacity('bg_fade',
				           {duration:.5,
				            from:0,
				            to:1,
				            beforeUpdate:this._makeVisible(),
				            afterFinish:this._showLayer(whichDiv)});
				new Effect.Opacity('toolsTablePopIn',
				           {duration:.5,
				            from:0,
				            to:1,
				            beforeUpdate:this._makeVisible(),
				            afterFinish:this._showLayer("toolsTablePopIn")});
	        }
	        
        },
        open : function () {
	        this._fade('open', this.container);
        },
        close : function () {
	        this._fade('close', this.container);
        },
        _centerWindow : function(element) {
             if($(element) != null) {
                  if(typeof window.innerHeight != 'undefined') {
                       $(element).style.top = 
                            Math.round(document.viewport.getScrollOffsets().top + 
                            ((window.innerHeight - $(element).getHeight()))/2)+'px';
                       $(element).style.left = 
                            Math.round(document.viewport.getScrollOffsets().left + 
                            ((window.innerWidth - $(element).getWidth()))/2)+'px';
                  } else {
                       $(element).style.top = 
                            Math.round(document.body.scrollTop + 
                            (($$('body')[0].clientHeight - $(element).getHeight()))/2)+'px';
                       $(element).style.left = 
                            Math.round(document.body.scrollLeft + 
                            (($$('body')[0].clientWidth - $(element).getWidth()))/2)+'px';
                  }
             }
        }
        
    }
);