﻿function addLoadEvent(func) 
    {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') 
        {  window.onload = func;
        } 
        else 
        {  window.onload = function() 
           {  if (oldonload) 
              {   oldonload();
              }
              func();
           }
        }
     }
 
     var christianIMGSwapInterval = 0;
     var firstImg = true;
     
     addLoadEvent(function() 
     {
        christianIMGSwap();
        transparency("ZitatDIVBackground",40);
        transparency("ChristianHeaderIMG2",100);
        transparency("PlayerDIV",50);
        
        var zitatUrlParam = getURLParam("zitat") 
        if (zitatUrlParam == "")
        {
            christianIMGSwapInterval = setInterval(christianIMGSwap,15000);
            document.getElementById("LBLZitat").innerHTML = "1";
        }
        else
        {   modusPlay = false;
            document.getElementById("IMGPlayStop").src = "Fotos/Play.gif";
            
            christianIMGIdx= 0;
            
            for (var i = 0;i <christianIMGArray.length;i++)
            {
                if(christianIMGArray[i][3] == parseInt(zitatUrlParam))
                  christianIMGIdx = i;  
            }
                        
            document.getElementById("LBLZitat").innerHTML = (parseInt(christianIMGIdx)+1);
            document.getElementById("ChristianHeaderIMG").src = "Fotos/"+christianIMGArray[christianIMGIdx][2];
            document.getElementById("ZitatDIV").innerHTML= christianIMGArray[christianIMGIdx][1];
        }
        
        document.getElementById("LBLSumZitate").innerHTML = christianIMGArray.length;
        
        
        checkMenuHeight();
                                                            
     });

    // Menuehoehe anpassen
    function checkMenuHeight( )
    {
        
        height = 425;
        if (document.getElementById("ContentBox_Referenz_StatementsDIV")!= null)
        {
            height = document.getElementById("ContentBox_Referenz_StatementsDIV").offsetHeight;
        } 
        
        var StateTop = document.getElementById("MainArea").offsetTop;
        StateTop += document.getElementById("DivContentPlaceHolder").offsetTop;

        document.getElementById("MenuBorder").style.height = (height-40);  // 40 = 30 (Höhe Designed by pic) + 10 (Abstand)
        document.getElementById("LoginDIV").style.top = (height-40) - 
                                                        document.getElementById("MenuOnlyDIV").offsetHeight - 
                                                        document.getElementById("LoginDIV").offsetHeight;
    }
        


    
    var christianIMGIdx = -1;

    var christianFadeInterval = 0;
    var fadeStep = 5;
    
    function christianFader()
    {
        transparency("ChristianHeaderIMG2",fadeStep);
        transparency("ChristianHeaderIMG",100-fadeStep);
        
        if (fadeStep >= 100)
        {   clearInterval(christianFadeInterval);
            christianFadeInterval = 0;
            fadeStep = 5;
            document.getElementById("ZitatDIV").innerHTML= christianIMGArray[christianIMGIdx][1];
            document.getElementById("LBLZitat").innerHTML= christianIMGIdx+1;
            
            
            // Jetzt nächstes Bild schon laden
            var nextIdx =0;
            if (christianIMGIdx >= christianIMGArray.length-1)
            {   nextIdx = 0;
            }
            else
            {   nextIdx = christianIMGIdx+1;
            }
        
            document.getElementById("ChristianHeaderIMG2").src = "Fotos/"+christianIMGArray[nextIdx][2]
        }            
        
        fadeStep += 5;
    }
    
    var modusForward = true;   
       
    function christianIMGSwap()
    {
        if (christianFadeInterval != 0) return;
                
        if (!firstImg)
        {   transparency("ChristianHeaderIMG2",0);
            transparency("ChristianHeaderIMG",100);
        }
        
        if (christianIMGIdx >= 0)
            document.getElementById("ChristianHeaderIMG2").src = "Fotos/"+christianIMGArray[christianIMGIdx][2];
        
        if (modusForward)
        {
            if (christianIMGIdx >= christianIMGArray.length-1)
            {   christianIMGIdx = 0;
            }
            else
            {   christianIMGIdx++;
            }
        }
        else
        {   if (christianIMGIdx == 0)
            {   christianIMGIdx = christianIMGArray.length-1;
            }
            else
            {   christianIMGIdx--;
            }
        }

        document.getElementById("ChristianHeaderIMG").src = "Fotos/"+christianIMGArray[christianIMGIdx][2];

        if (!firstImg)
        {    christianFadeInterval = setInterval(christianFader, 10);
        }
        else
        {   document.getElementById("ZitatDIV").innerHTML= christianIMGArray[christianIMGIdx][1];
        }
            
        firstImg = false;    
    }
    
    
    // Bilder vorladen
    var BildArray = new Array();
    BildArray[0] = "Fotos/glossyback2_black.gif";

    function Vorladen(parBildArray)
    {
      for (i=0; i < parBildArray.length; i++) {
        var Bild = new Image();
        Bild.src = parBildArray[i];
      }
    }

    addLoadEvent(function(){Vorladen(BildArray);});
    
        
    function getURLParam(strParamName)
    {
        var strReturn = "";
        var strHref = window.location.href;

        if ( strHref.indexOf("?") > -1 )
        {
            var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
            var aQueryString = strQueryString.split("&");

            for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
            {
                if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
                {
                    var aParam = aQueryString[iParam].split("=");
                    strReturn = aParam[1];
                    break;
                }   
            }
        }
        return strReturn;
    }
    
    //Player***********************************
    
    var modusPlay = true;
    
    function klickPlayStop()
    {
        if (modusPlay)
        {   document.getElementById("IMGPlayStop").src = "Fotos/Play.gif";
            clearInterval(christianIMGSwapInterval);
            
        }
        else
        {   document.getElementById("IMGPlayStop").src = "Fotos/Stop.gif";
            klickForward();
            christianIMGSwapInterval = setInterval(christianIMGSwap,15000);
        }
        
        modusPlay = !modusPlay;
    }
    
    function klickForward()
    {   if (christianFadeInterval == 0)
            christianIMGSwap();
    }
    
    function klickReverse()
    {   if(christianFadeInterval == 0)
        {
            modusForward = false;
            christianIMGSwap();
            modusForward = true;
        }
    
    }
