﻿var glOldThumb = "";
    var glIndex = 0;
    var diaState = 0; //0 ... pause, 1 ... playing
    var iv;

    function loadMainImage(no,mode) {
    
        if (mode == 0 && iv) {
            diaState = 1;
            dia();
        }
        var img = document.getElementById('imgMain');
        
        //Preloader -------------------
        //img.style.display='';
        //img.className='';
        //img.src="/images/loading3.gif";
        //img.style.padding="80px";
        //-----------------------------
        
        setTimeout("setImgSrc("+no+","+mode+")",200);
    }
    
    function setImgSrc(no,mode) {
        var img = document.getElementById('imgMain');
        //Bildpfad suchen
        var thumb = document.getElementsByName('img'+no)[0];
        var path = thumb.alt;
                
        img.style.padding="0";
        
        if(navigator.appName=="Microsoft Internet Explorer") {
            img.style.filter="blendTrans(duration=1)";
            img.style.filter="blendTrans(duration=crossFadeDuration)";
            img.filters.blendTrans.Apply();
        }
                
        img.src="../includes/bild.aspx?bild1=../" + path+"&qualitaet=80&maxbreite=750&maxhoehe=350";
        img.className="b";
        if(navigator.appName=="Microsoft Internet Explorer") {
            img.filters.blendTrans.Play();
        }
        
        glIndex=no;
        
        
        if (glOldThumb != "") glOldThumb.style.border = "solid 5px #eef5fa";        
        thumb.style.border = "solid 5px #666666";
        
        //zu document scrollen - nur wenn aufruf über Pfeile oder Diashow
        if (mode==1) location.href="#a"+no;
        
        glOldThumb = thumb;
        
        //Checken ob es das letzte bild ist -> dann button ausblenden
        if (no == 1) { 
            document.getElementById('galleryBack').style.display='none';
            document.getElementById('galleryNext').style.marginLeft = 28; 
        } else {
            document.getElementById('galleryBack').style.display='';
            document.getElementById('galleryNext').style.marginLeft = 0;
        }
        
        if (document.getElementsByName('img'+(no+1)).length > 0) {
            document.getElementById('galleryNext').style.display='';
        } else {
            document.getElementById('galleryNext').style.display='none';
        }
    }
    
    
    function back() {
        loadMainImage(glIndex-1);
    }
    
    function next() {
        loadMainImage(glIndex+1,1);    
    }
    
    function dia() {
        if (diaState == 0) {
            //Starten
            document.getElementById('galleryDia').src="../images/pause.gif";
            iv=setInterval("loaddia();",4000);
            diaState = 1;
        } else {
            document.getElementById('galleryDia').src="../images/play.gif";
            window.clearInterval(iv);
            diaState = 0;
        }
        
    }
    
    function loaddia() {
        glIndex = glIndex+1;
        if (document.getElementsByName('img'+(glIndex)).length > 0) {
            loadMainImage(glIndex,1);   
        } else {
            //Ende
            window.clearInterval(iv);
        }
    }
    
    
    //erstes Bild laden
    loadMainImage(1);  

