function ControlPannelLightbox (pannelLayer) {
                var thisObj = this;
                                
                this.calllB_bGs = {
                    nextImage:null,
                    prevImage:null,
                    slideShow:null
                }
            }
        
function Lightbox () {
    var thisObj = this;
    var displayHeight = window.innerHeight || document.documentElement.clientHeight; // Broweranzeige höhe
    var displayWidth  = window.innerWidth  || document.documentElement.clientWidth;  // Broweranzeige weite
                                
    var scrollAmountTop  = null; // Scrollwert von oben
    var scrollAmountLeft = null; // Scrollwert von links
    var screenMiddle     = null; // Mittelpunkt
                
    var lB_Groundlayer = null;  //Anzeigen Grundlayer
    var lB_ViewLayer   = null;  // Layer wo das Bild abgelegt wird
    var lB_closeButton = null;  // schliessen button
                                                
    var lB_imageValues  = new Array();  // Array für alle Bilder die geladen werden sollen
    var lB_loadImage    = false;        // Bool wird das Bild eben geladen
    var lB_fadeOut      = false;        // Bool wird das Bild eben ausgeblendet
    var lB_currentIndex = 0;            // Index des bildes welches eben geladen ist
    var lB_currentImage = null;         // aktuelles bild welches geladen wurde und angezeigt wird
    var lB_currentImageProperties = {height:0,width:0}; // aktuelle Bildhöhe und weite 
                                                        // nimmt immer die weite vom aktuellen Bild auf
       
    var lB_browser  = (navigator.appName == 'Microsoft Internet Explorer');
    var lB_imgLayer = null;  //Layer wo das aktuelle Bild gespeichert ist 
                             // kann den Wert von ViewLayer übernehmen
                             // oder aber ein neues Object werden 
                
    var lB_ControlPannel = null; // Control Pannel zur Steuerung 
                                 // speichert eine Instanz der Klasse ControlPannelLightbox           
                                             
    var lB_slideShow  = false;
    var start_lb      = false; // bool wurde die Lightbox gestartet
    var loopInterval  = null;
    var loopOrder     = null;
    var lB_bG         = null;
    var lB_preloadBox = null;
    var lB_timer      = null;
    var lB_resetOnClose  = null; // im Config verankert ob der Bildindex nach dem schliessen der LB 
                                 // zurück auf 0 gesetzt werden soll
    var lB_finish = null;
                                
    var changeImageScreen = {                
        growingHeight:true,
        growingWidth:true,
        min_left:0,
        max_left:0, 
        min_top:0,
        max_top:0,
        setCoords:function(pX,pY,w,h) {
            this.min_left = pX;
            this.min_top  = pY;
            this.max_left = w;
            this.max_top  = h;
        },
        growWidth:function () {     
            var growsWidth = changeImageScreen.growingWidth = false;
            if (parseInt(lB_Groundlayer.style.left)-8 <= changeImageScreen.min_left)
            {
                lB_Groundlayer.style.left = changeImageScreen.min_left+"px";
                lB_Groundlayer.style.width = changeImageScreen.max_left+"px";
            }
            else 
            {
                growsWidth = changeImageScreen.growingWidth = true;
                lB_Groundlayer.style.left = parseInt(lB_Groundlayer.style.left)-8+"px";
                lB_Groundlayer.style.width = parseInt(lB_Groundlayer.style.width)+16+"px";
            }
            
            if(!growsWidth) {
                changeImageScreen.onReadyState.setReady();
            }                      
        },
        growHeight:function () {                        
            var growsHeight = changeImageScreen.growingHeight = false;
                        
            if (parseInt(lB_Groundlayer.style.top)-8 <= changeImageScreen.min_top)
            {
                lB_Groundlayer.style.top = changeImageScreen.min_top+"px";
                lB_Groundlayer.style.height = changeImageScreen.max_top+"px";
            }
            else 
            {
                growsHeight = changeImageScreen.growingHeight= true;
                lB_Groundlayer.style.top = parseInt(lB_Groundlayer.style.top)-8+"px";
                lB_Groundlayer.style.height = parseInt(lB_Groundlayer.style.height)+16+"px";
            }
                                
            if(!growsHeight) {
                changeImageScreen.onReadyState.setReady();
            }
        },
        shrinkWidth:function () {
            var shrinksWidth = changeImageScreen.growingWidth = false;
            if (parseInt(lB_Groundlayer.style.left)+8 >= changeImageScreen.min_left)
            {
                lB_Groundlayer.style.left = changeImageScreen.min_left+"px";
                lB_Groundlayer.style.width = changeImageScreen.max_left+"px"
            }
            else 
            {
                shrinksWidth = changeImageScreen.growingWidth = true;
                lB_Groundlayer.style.left = parseInt(lB_Groundlayer.style.left)+8+"px";
                lB_Groundlayer.style.width = parseInt(lB_Groundlayer.style.width)-16+"px";
            }
                                                        
            if(!shrinksWidth) {
                changeImageScreen.onReadyState.setReady();
            }
        },                 
        shrinkHeight:function () {
            var shrinksHeight = changeImageScreen.growingHeight= false;
            if (parseInt(lB_Groundlayer.style.top)+8 >= changeImageScreen.min_top)
            {
                lB_Groundlayer.style.top = changeImageScreen.min_top+"px";
                lB_Groundlayer.style.height = changeImageScreen.max_top+"px";
            }
            else 
            {
                shrinksHeight = changeImageScreen.growingHeight = true;
                lB_Groundlayer.style.top = parseInt(lB_Groundlayer.style.top)+8+"px";
                lB_Groundlayer.style.height = parseInt(lB_Groundlayer.style.height)-16+"px";
            }
                                 
            if(!shrinksHeight) {
                changeImageScreen.onReadyState.setReady();
            }                            
        },
        onReadyState:{
            setReady:function() {
                if(!changeImageScreen.growingWidth && !changeImageScreen.growingHeight){
                    clearLoop();
                    lB_timer = window.setTimeout(fadeImageIn,500);
                                
                    changeImageScreen.growingWidth  = true;
                    changeImageScreen.growingHeight = true; 
                } else if (!changeImageScreen.growingWidth) { 
                    clearLoop();
                } else if (!changeImageScreen.growingHeight) { 
                    clearLoop();
                }else {
                    return;
                }
            }
        }                        
    }
                
    function loop (func) {
        if(!func || typeof func != 'function' ) func = loopOrder.shift();
                    
        if(func)
            loopInterval = window.setInterval(func,25);
    }
                
    function clearLoop (closeAll) {                    
        window.clearInterval(loopInterval);
        if(!closeAll && loopOrder && loopOrder.length > 0) 
            lB_timer = window.setTimeout(loop,200);
    }

    function getScrollAmount () {
        scrollAmountTop   = 0; //window.pageYOffset || document.documentElement.scrollTop;
        scrollAmountLeft  = window.pageXOffset || document.documentElement.scrollLeft;

        screenMiddle = {
            posXM:Math.floor(displayWidth/2)+scrollAmountLeft,
            posYM:Math.floor(displayHeight/2)+scrollAmountTop
        }                    
    }
                
    function placePreloader () {
        if(!lB_preloadBox) {
            lB_preloadBox = document.createElement('div');
            lB_preloadBox.style.position = 'absolute';
            lB_preloadBox.style.height   = '50px';
            lB_preloadBox.style.width    = '200px';
            lB_preloadBox.style.top      = screenMiddle.posYM-25+"px";
            lB_preloadBox.style.left     = screenMiddle.posXM-100+"px";                    
            lB_preloadBox.style.backgroundColor = '#DCDCDC';
            lB_preloadBox.appendChild(document.createTextNode('Lade...')); 
        }
                    
        document.getElementsByTagName('BODY')[0].appendChild(lB_preloadBox);
        return;
    }
                
    function destroyPreloader () {
        lB_preloadBox.parentNode.removeChild(lB_preloadBox);
        return;
    }
                
    function placeImageGround() {                                                   
        if(lB_loadImage != true ) {
            clearLoop();
            destroyPreloader();
                            
            if(!lB_bG) {
                lB_bG = document.createElement('div');
                lB_bG.style.position = 'absolute';
                lB_bG.style.height   =  document.documentElement.scrollHeight+"px";
                lB_bG.style.width    =  document.body.offsetWidth+"px";
                lB_bG.style.top      = '0px';
                lB_bG.style.left     = '0px';
                lB_bG.style.zIndex   = '999';
                                                           
                lB_bG.style.backgroundColor = '#000';
                                
                if(lB_browser)
                    lB_bG.style.filter = 'alpha(opacity=85)';
                else 
                    lB_bG.style.opacity = .85;
            }
                                                                                                                
            var imgLeftPos = screenMiddle.posXM-parseInt(currentImage.width)/2;
            var imgTopPos  = screenMiddle.posYM-parseInt(currentImage.height/2);
                            
            with(lB_Groundlayer) {
                style.top     =  screenMiddle.posYM-200+"px";
                style.left    =  screenMiddle.posXM-200+"px";
                style.display = 'block';
                style.border  = '1px solid';
                                   
                changeImageScreen.setCoords(imgLeftPos,imgTopPos,currentImage.width,currentImage.height);
                                   
                if(lB_currentImageProperties.height > currentImage.height) {
                    loopOrder = new Array(changeImageScreen.shrinkHeight);
                } else {
                    loopOrder = new Array(changeImageScreen.growHeight);
                }
                                    
                if(lB_currentImageProperties.width > currentImage.width) {
                    loop(changeImageScreen.shrinkWidth);
                } else {
                    loop(changeImageScreen.growWidth);
                }
                    
                lB_currentImageProperties.width  = currentImage.width;
                lB_currentImageProperties.height = currentImage.height;
            }
                          
            document.getElementsByTagName('BODY')[0].insertBefore(lB_bG,lB_Groundlayer);                            
        }
    }
                
    function getImage (lB_imageSrc) {
        lB_loadImage = true;
                    
        currentImage     = new Image();
        currentImage.src = lB_imageSrc;
                                         
        if(currentImage.complete) {
            lB_loadImage = false;
            return true;
        } else {
            currentImage.onload = function () {
                lB_loadImage = false;
                return true;
             }                       
        }                                               
    }
                                
    function closeLightbox () {
        loopOrder = new Array();
                
        clearLoop(true);
        window.clearTimeout(lB_timer);
        setOpacityZero ();                    
                    
        lB_currentImageProperties.height = 0;
        lB_currentImageProperties.width  = 0;
        lB_currentIndex = (lB_resetOnClose)?0:lB_currentIndex;
          
        lB_bG.parentNode.removeChild(lB_bG);
                    
        lB_Groundlayer.style.display = 'none';
        lB_Groundlayer.style.height   = '400px';
        lB_Groundlayer.style.width    = '400px';
        lB_currentImageProperties.height = 400;
        lB_currentImageProperties.width  = 400;
                    
        start_lb = false;       

        if(lB_finish) lB_finish();
        return;
    }
                                                                
    function fadeImageIn () {
                
        var opa_start = 0;
        var opa_end   = 0;
                                                           
        // Bild einfügen 
        if(!lB_imgLayer) {
            if(lB_ViewLayer.nodeName == 'img') {
                lB_imgLayer = lB_ViewLayer;
            } else {
                lB_imgLayer = document.createElement('img');
                lB_ViewLayer.innerHTML = '';
                lB_ViewLayer.appendChild(lB_imgLayer);
            }
                        
            setOpacityZero();    
        } else { lB_imgLayer.src = currentImage.src; }
        
        loop(fadeIn);
                    
        function fadeIn () {
            opa_start += 7;
            opa_end = opa_start;
                        
            if(lB_browser) 
                lB_imgLayer.style.filter = "Alpha(opacity="+opa_start+", finishopacity=0)";
            else 
                lB_imgLayer.style.opacity = opa_start/100;
                      
            if(opa_end >= 100) {
                clearLoop();
                if(lB_slideShow) lB_timer = window.setTimeout(nextImage,5000);
            }
        }
    }
                
    function setOpacityZero () {
        if(lB_browser) {
            lB_imgLayer.style.filter  = 'Alpha(opacity=0, finishopacity=0)';
        } else {
            lB_imgLayer.style.opacity = 0;
        }
                        
        lB_imgLayer.src = currentImage.src;
    }
                
    function fadeImageOut (cb) {
        var opa_start = 100;
        var opa_end   = 0;
                                                                             
        loop(fadeOut);
                    
        function fadeOut () {
            opa_start -= 7;
            opa_end = opa_start;
                        
            if(lB_browser) {                
                lB_imgLayer.style.filter  = 'Alpha(opacity='+opa_start+', finishopacity=0)';
            } else {
                lB_imgLayer.style.opacity = opa_start/100;
            }
                        
            if(opa_end <= 0) { 
                clearLoop(); 
                lB_imgLayer.style.opacity = 0;                            
                cb();
            }
        }
    }
                
    function nextImage () {                    
        var imgWidth;
        var imgHeight;
        var posX;
        var posY;
                                                            
        if(lB_currentIndex+1 >= lB_imageValues.length)
            lB_currentIndex = 0;
        else 
            lB_currentIndex++;
                        
        getImage(lB_imageValues[lB_currentIndex]);
        loop(imageLoaded);
                    
        function imageLoaded () {                        
            if(!lB_loadImage) {
                clearLoop();
                imgWidth  = currentImage.width;
                imgHeight = currentImage.height;
                                                        
                posX = screenMiddle.posXM-imgWidth/2;
                posY = screenMiddle.posYM-imgHeight/2;
                                                        
                fadeImageOut(displayNewImage);                            
            }
        }
                    
        function displayNewImage () {
            changeImageScreen.setCoords(posX,posY,imgWidth,imgHeight);
                           
            if(lB_currentImageProperties.height > imgHeight)
            {
                loop(changeImageScreen.shrinkHeight);
            } else {
                loop(changeImageScreen.growHeight);
            }                      
                           
            if(lB_currentImageProperties.width > imgWidth) {
                loopOrder.push(changeImageScreen.shrinkWidth);
            } else {
                loopOrder.push(changeImageScreen.growWidth);
            }
                                                        
            lB_currentImageProperties.height = imgHeight;
            lB_currentImageProperties.width  = imgWidth;
        }                                    
    }
                
    function prevImage () {
    }
                
    function slideShow () {
    }
                
    function loadImageValues (path,delimeter) {
        lB_loadImage = true;
                   
        function imagesLoaded (rv) {
            lB_loadImage = false;                        
            lB_imageValues = rv.split(delimeter);
        }
    }
                                
    function setConfigValues (config) {
               
        if(typeof config != "object") {
            alert('config parameter fehlerhaft');
            return;
        }
                    
        try {
            if(!config.imageWindow) throw ("kein Fensterobjekt beschrieben");
            with (config.imageWindow) {
                lB_Groundlayer = iW_GroundLayer;
                lB_ViewLayer   = iW_ViewLayer;
                lB_closeButton = iW_closeButton;
                            
                Element.addEvent(lB_closeButton,'click',closeLightbox);
                            
                /*
                                            * Anpassung des Grundlayers der das fertige Bild darstellen soll
                                            * absolute posi
                                           * versteckt , 0px höhe und weiter sowie overflow hidden für den IE
                                           */
                lB_Groundlayer.style.position = 'absolute';
                lB_Groundlayer.style.display  = 'none';
                lB_Groundlayer.style.height   = '400px';
                lB_Groundlayer.style.width    = '400px';
                lB_Groundlayer.style.overflow = 'hidden';
                            
                lB_currentImageProperties.height = 400;
                lB_currentImageProperties.width  = 400;
            }
                        
            if(!config.imageLoad || !(config.imageLoad.iL_ajaxLoad || config.imageLoad.iL_imageArray) ) {                      
                throw ("wie sollen die Bilder geladen werden Ajax oder aus einen Array ?");
            } 
                       
            if(config.imageLoad.iL_ajaxLoad) {
                with (config.imageLoad.iL_ajaxLoad) {
                    loadImageValues(lB_imageLoad.path,lB_imageLoad.delimeter);
                }                             
            } else if (config.imageLoad.iL_imageArray) {
                lB_imageValues = config.imageLoad.iL_imageArray;
            }
                        
            lB_slideShow    = (config.onlySlideShow)?true:false;
            lB_resetOnClose = (config.resetOnClose)?true:false;
            lB_finish       = (config.onLBClose)?config.onLBClose:null;
                  
            if(config.controlPannel.show) {
                lB_ControlPannel = new ControlPannelLightbox(config.controlPannel.controlPannelObject);
            }                
        } catch (e) {
            alert(e);
            return;
        }
    }
                
    this.addConfigValues = function (config) {
        setConfigValues (config);
    }
                
    this.initGallery = function () {
        
        if(start_lb) return;
                    
        getImage(lB_imageValues[lB_currentIndex]);
        getScrollAmount();
        placePreloader();
        loop(placeImageGround);
        start_lb = true;
    }               
}