var lightwindow = {
    
    options: {
        overlayId: 'overlay',
        lightwindowId: 'lightwindow',
        lightwindowTopDelta: 70
    },
    
    objOverlay: null,
    objLightwindow: null,
    
    show: function(){
        
        this.objOverlay = jQuery('#'+this.options.overlayId).get(0);
        this.objLightwindow = jQuery('#'+this.options.lightwindowId).get(0);
        if ((this.objOverlay != null) && (this.objLightwindow != null)) {
        
            //Position
            this.setElementsPosition();
            
            //Events
            var lw = this;
            jQuery(window).bind('resize', function(){ 
                lw.setElementsPosition();
            });
            
        }
        //Select ausblenden - IE Bug
        jQuery('select').hide();
        
    },
    
    setElementsPosition: function(){
        
        this.objLightwindow.style.display = 'none';
        this.objOverlay.style.display = 'none';
        
          var arrayPageSize = this.getPageSize();
          var arrayPageScroll = this.getPageScroll();
        //Overlay
        this.objOverlay.style.display = 'block';
        this.objOverlay.style.height = (arrayPageSize[1] + 'px');
        this.objOverlay.style.width = (arrayPageSize[0] + 'px');
        
        //Lightwindow
        this.objLightwindow.style.display = 'block';
        
        var lightwindowTop = arrayPageScroll[1] + ((arrayPageSize[3] - this.options.lightwindowTopDelta - this.objLightwindow.offsetHeight) / 2);
        lightwindowTop = (lightwindowTop < 0) ? 0 : lightwindowTop;
        
        var lightwindowLeft = ((arrayPageSize[0] - this.objLightwindow.offsetWidth) / 2);
        
        this.objLightwindow.style.top = (lightwindowTop < 0) ? "0px" : lightwindowTop + "px";
        this.objLightwindow.style.left = (lightwindowLeft < 0) ? "0px" : lightwindowLeft + "px";
    },
    
    hide: function(){
        jQuery(window).unbind('resize');
        jQuery('#'+this.options.overlayId).hide();
        jQuery('#'+this.options.lightwindowId).hide();
        //Select einblenden - IE Bug
        jQuery('select').show();
        
    },
    
    getPageScroll: function(){
    
        var yScroll;
    
        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop){     // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
        } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
        }
    
        var arrayPageScroll = new Array('',yScroll) 
        return arrayPageScroll;
    },
    
    
    getPageSize: function(){
        
        var xScroll, yScroll;
        
        if (window.innerHeight && window.scrollMaxY) {    
            xScroll = window.innerWidth + window.scrollMaxX;
            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
        var pageHeight = null;
        if(yScroll < windowHeight){
            pageHeight = windowHeight;
        } else { 
            pageHeight = yScroll;
        }
    
        // for small pages with total width less then width of the viewport
        var pageWidth = null;
        if(xScroll < windowWidth){    
            pageWidth = windowWidth;
        } else {
            //Firefox - minus Scrollbalken, wenn Y-Scrolling vorhanden ist
            if (window.innerHeight && window.scrollMaxY) {    
              if (yScroll > windowHeight) xScroll = xScroll - 16;
            }        
            pageWidth = xScroll; 
        }
    
        var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 
        return arrayPageSize;
    }
    
};
