/******************************************************************************/
/* scripts by basbas                                                          */
/******************************************************************************/


/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
// Global Vars
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/	


// sprachunterscheidung
// lang: speichert die sprache abgekuerzt zur spaeteren verwendung in den
// button image pfadangaben
var lang = "de";

// isEnglish: speichert ob man auf der englischen oder deutschen seite ist

////////////////////////////////////////////////////////////////////////////////
// INFO BUTTONS und INFO DIVS
////////////////////////////////////////////////////////////////////////////////
// infoButtons array (2): Vita, und Kontakt Buttons 
var infoButtons = new Array(2);

// infoLen: Gibt an wieviele Info Buttons es gibt  
var infoLen = infoButtons.length;

// infoDivs: ist ein Array in den spŠter (in init()) die InhaltsDivs hineingeladen werden
var infoDivs = new Array(infoLen);

// activeSection: hier wird gespeicher welcher bereich gerade aktiv ist
// ist kein bereich aktiv ist der wert -1
var activeInfoSection = -1;

// InfoButtons array (1): Hier wird der InfoButtons Array gefŸllt: d.h. die image objekte erzeugt und ein .src Wert zugewiesen                           
for (var i=0; i<infoLen; i++){ 
infoButtons[i]= new Array(3)
}


////////////////////////////////////////////////////////////////////////////////
// PORTFOLIO BUTTONS und PORTFOLIO DIVS
////////////////////////////////////////////////////////////////////////////////

// Buttons array (0): Portfolio Buttons: Hier wird der Buttons Array erzeugt, kommt ein neuer button hinzu, muss der array um eins lŠnger werden 
var buttons = new Array(12);

// projLen: Gibt an wieviele Buttons bzw. Projekte es gibt (steht fŸr projektsLenght) 
var projLen = buttons.length;

// contentDivs: ist ein Array in den spŠter (in init()) die InhaltsDivs hineingeladen werden
var contentDivs = new Array(projLen);

// activeSection: hier wird gespeicher welcher bereich gerade aktiv ist
// ist kein bereich aktiv ist der wert -1
var activeSection = -1;

// Buttons array (1):  Hier wird der Buttons Array gefŸllt: d.h. die image objekte erzeugt und ein .src Wert zugewiesen                           
for (var i=0; i<projLen; i++){ 
buttons[i]= new Array(3)
}




/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/	
// Functions
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*---------------------------------------------------------------------*/
// function init() wird bei <body onload="init()"> geladen
/*---------------------------------------------------------------------*/        

function init(){
    // contentDivs und infoDivs array // hier werden die Ebenen gespeichert, auf denen der inhalt dargestellt wird
    for (var i=0; i<contentDivs.length; i++){
        contentDivs[i] = getElement("id", "testPlain"+i);    
    }
    for (var i=0; i<infoDivs.length; i++){
        infoDivs[i] = getElement("id", "infoPlain"+i);    
    }    

    // hier wird bestimmt ob die seite auf english oder deutsch geladen wird
    isEnglish = getElement("id", "english");    
    if (isEnglish){
        lang = "en";
    }else{
        lang = "de";
    }
    
    ////////////////////////////////////////////////////////////////////
    // hier wird der info buttons array mit den bilddaten verknŸpft          
    for (var i=0; i<infoLen; i++){
        for(var j=0; j<3; j++){
            // j steht fŸr die button zustŠnde also: 0 fŸr over, 1 fŸr down, 2 fŸr up/out(haben selbes bild) 
            infoButtons[i][j] = new Image();            
            switch (j){
                case 0:
                    infoButtons[i][j].src = "_images/_"+lang+"_buttons/infoButton_over"+i+".gif";
                    break;                                                                                
                case 1:
                    infoButtons[i][j].src = "_images/_"+lang+"_buttons/infoButton_down"+i+".gif";                    
                    break;                                                                                
                case 2:
                    infoButtons[i][j].src = "_images/_"+lang+"_buttons/infoButton_up"+i+".gif";
                    break;                                                                                
                default:
                    alert("InfoButton Array-switch doesnt work");
                    break;                                                            
            }
        }
    }        
    ////////////////////////////////////////////////////////////////////
    // hier wird der portfolio buttons array mit den bilddaten verknŸpft      
    for (var i=0; i<projLen; i++){
        for(var j=0; j<3; j++){
            // j steht fŸr die button zustŠnde also: 0 fŸr over, 1 fŸr down, 2 fŸr up/out(haben selbes bild) 
            buttons[i][j] = new Image();            
            switch (j){
                case 0:
                    buttons[i][j].src = "_images/_"+lang+"_buttons/button_over"+i+".gif";
                    break;                                                                                
                case 1:
                    buttons[i][j].src = "_images/_"+lang+"_buttons/button_down"+i+".gif";                    
                    break;                                                                                
                case 2:
                    buttons[i][j].src = "_images/_"+lang+"_buttons/button_up"+i+".gif";
                    break;                                                                                
                default:
                    alert("Button Array-switch doesnt work");
                    break;                                                            
            }
        }
    } 
    
}

/*---------------------------------------------------------------------*/
// function updateInfo(id, state)
// Sorgt fŸr das Austauschen der Info buttons, und gibt mit 
// upDateInfoSection den Befehl zum ein- bzw ausblenden der richtigen 
// Info Ebene 
/*---------------------------------------------------------------------*/        

function updateInfo(aId, aState){
    if(aId != activeInfoSection && aState == 1){
        
        var tempActiveInfoSection = activeInfoSection;
        activeInfoSection = aId;
        
        window.document.images["infoButton"+aId].src = infoButtons[aId][1].src;        
        window.document.images["infoButton"+tempActiveInfoSection].src = infoButtons[tempActiveInfoSection][2].src;                               
    }else if(aId == activeInfoSection && aState == 1){
        window.document.images["infoButton"+aId].src = infoButtons[aId][2].src;        
        activeInfoSection = -1;                   
    }
    if(aId == activeInfoSection && aState != 1){
       window.document.images["infoButton"+aId].src = infoButtons[aId][0].src;
    }
    if(aState == 0){
       window.document.images["infoButton"+aId].src = infoButtons[aId][0].src;
    }
    if(aId != activeInfoSection && aState == 2){
       window.document.images["infoButton"+aId].src = infoButtons[aId][2].src;
    }    
    upDateInfoSection();            
}

/*---------------------------------------------------------------------*/
// function upDateInfoSection(aActiveInfoSection)
/*---------------------------------------------------------------------*/        
function upDateInfoSection(){
    for(var i=0; i<infoLen; i++){
        if (i == activeInfoSection){
            infoDivs[i].style.display ="block";
            //blendet, falls eine content ebene aktiv ist, diese aus
            // und tauscht das button bild aus            
            if(activeSection != -1){
                window.document.images["button"+activeSection].src = buttons[activeSection][2].src;           
                activeSection = -1;                
                upDateSection();
            }             
        }else{
            infoDivs[i].style.display ="none";            
        }
    }
}


/*---------------------------------------------------------------------*/
// function updateMenu(id, state), 
// Sorgt fŸr das Austauschen der portfolio buttons, und gibt mit 
// upDateSection den Befehl zum ein- bzw ausblenden der richtigen 
// Portfolio Ebene
// Bekommt die nummer und den zustand des gedrŸckten buttons als argument
/*---------------------------------------------------------------------*/        

function updateMenu(aId, aState){
    if(aId != activeSection && aState == 1){
        scrollWindow(aId);    
        var tempActiveSection = activeSection;
        activeSection = aId;
        window.document.images["button"+aId].src = buttons[aId][1].src;        
        window.document.images["button"+tempActiveSection].src = buttons[tempActiveSection][2].src;                               
    }else if(aId == activeSection && aState == 1){
        window.document.images["button"+aId].src = buttons[aId][2].src;        
        activeSection = -1;
        window.scroll(0, 0);                    
    }
    if(aId == activeSection && aState != 1){
       window.document.images["button"+aId].src = buttons[aId][0].src;
    }
    if(aState == 0){
       window.document.images["button"+aId].src = buttons[aId][0].src;
    }
    if(aId != activeSection && aState == 2){
       window.document.images["button"+aId].src = buttons[aId][2].src;
    }        
    //outputText();    
    upDateSection();      
}

/*---------------------------------------------------------------------*/
// function upDateSection(aActiveSection)
/*---------------------------------------------------------------------*/        
function upDateSection(){
    for(var i=0; i<projLen; i++){
        if (i == activeSection){
            contentDivs[i].style.display ="block";
            //blendet, falls eine info ebene aktiv ist, diese aus 
            // und tauscht das info button bild aus         
            if(activeInfoSection != -1){
                window.document.images["infoButton"+activeInfoSection].src = infoButtons[activeInfoSection][2].src;            
                activeInfoSection = -1;                
                upDateInfoSection();      
            }      
        }else{
            contentDivs[i].style.display ="none";            
        }
    }
}

/*---------------------------------------------------------------------*/
// function scrollWindow() verschiebt den Scrollbalken, so dass man den
// aufgerufenen Inhalt gut sehen kann
/*---------------------------------------------------------------------*/     
function scrollWindow(aId){
    if(aId>=0 && aId <5){
        window.scroll(0, 77);                  
    }else if(aId>=5 && aId <10){
        window.scroll(0, 257);         
    }else if (aId>=10 && aId <15){
        window.scroll(0, 439);
    }
}        

/*---------------------------------------------------------------------*/
// function pop_up_small() šffnet das Fenster mit dem videoclip
/*---------------------------------------------------------------------*/
function pop_up_small(pop_up_url, aW, aH) {
	w = aW;
	h = aH;
	// Fenster positionieren
	LeftPosition = 100;
	TopPosition = 100;	
	// Unnoetige Elemente verstecken (Scrollbars etc.)
	settings ='width='+w+', height='+h+', top='+TopPosition+', left='+LeftPosition+', scrollbars=no, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=no';
    // Neues Fenster oeffnen
	window.open(pop_up_url, 'pop_up', settings);
}


/*---------------------------------------------------------------------*/
// function outputText() gibt die activeSection aus
/*---------------------------------------------------------------------*/     
function outputText(){
    var textField = getElement("id", "textOutput");
    textField.innerHTML = activeSection;      
}
