/*
 *******
 * Var *
 *******
 */
var speed = 15;

//HOME
var curspeed = 20;
var fadeintObj = {};
var curactpositionObj = {
    1: 0,
    2: 0,
    3: 0
};
var curactvisibleObj = {
    1: 90,
    2: 90,
    3: 90
};
var curvisibleend = 70;
var curvisiblestart = 90;
var curtainstart = 0;
var curtainend = 360;

//TEXT
var fadeint;

//SLIDESHOW
var delay = 5000;
var delayS = 650;
var actImageNumber = 0;
var imgPositionEnd = 725;
var allImageDivsLength;
var positionend = 0;
var dlobj;
var actvis = 0;
var visibleend = 90;
var visiblestart = 0;
var contentheight = 360;

/*
 **********************************
 * Vorhang Home Trigger Animation *
 **********************************
 Name		Typ			Beschreibung
 ------------------------------------
 objEvent	Object		Event-Objekt, welches vom Listener übergeben wird
 objParams	Object		Parameter des Ziel-Elements (HTML-Objekt und Aktion)
 */
function FadeThisHome(objEvent, objParams){

    var tempId = this.id;
    var num = tempId.substring(6);
    
    switch (objParams.direction) {
        case "FadeIn":
            window.clearInterval(fadeintObj[num]);
            fadeintObj[num] = window.setInterval("doFadeHomeIn(" + num + ")", speed);
            break;
        case "FadeOut":
            window.clearInterval(fadeintObj[num]);
            fadeintObj[num] = window.setInterval("doFadeHomeOut(" + num + ")", speed);
            break;
    }
    
}

/*
 **************************
 * Text Trigger Animation *
 **************************
 Name		Typ			Beschreibung
 ------------------------------------
 objEvent	Object		Event-Objekt, welches vom Listener übergeben wird
 objParams	Object		Parameter des Ziel-Elements (HTML-Objekt und Aktion)
 */
function FadeThisText(objEvent, objParams){

    var tempId = this.id;
    var num = tempId.substring(6);
    
    switch (objParams.direction) {
        case "FadeIn":
            window.clearInterval(fadeint);
            num = actImageNumber;
            if (num == allImageDivsLength) {
                num = 0;
            }
            if (!allImageDivsLength) {
                allImageDivsLength = 1;
                num = 0;
            }
            
            if (dlobj[num] && dlobj[num].getElementsByTagName("dd")[0]) {
                var height = dlobj[num].getElementsByTagName("dd")[0].offsetHeight;
                positionstart1 = -height;
                actposition1 = -height;
            }
            
            fadeint = window.setInterval("doFadeTextIn()", speed);
            break;
        case "FadeOut":
            window.clearInterval(fadeint);
            fadeint = window.setInterval("doFadeTextOut()", speed);
            break;
    }
    
}

/*
 ****************************************************
 * Registrierung der Mouse-Events für Home Elemente *
 ****************************************************
 Name				Typ			Beschreibung
 --------------------------------------------
 objTar			Object		Ziel-Element (HTML-Objekt)
 */
function RegisterHomeListeners(objTar){

    // Hinzufügen der Listener zur YUI DOM für die Events "mouseOver" und "mouseOut" mit den jeweiligen Aktionen
    YAHOO.util.Event.addListener(objTar, "mouseover", FadeThisHome, {
        direction: "FadeIn"
    });
    YAHOO.util.Event.addListener(objTar, "mouseout", FadeThisHome, {
        direction: "FadeOut"
    });
    
}

/*
 ******************************************************
 * Registrierung der Mouse-Events für Header Elemente *
 ******************************************************
 Name				Typ			Beschreibung
 --------------------------------------------
 objTar			Object		Ziel-Element (HTML-Objekt)
 */
function RegisterHeaderListeners(objTar){

    // Hinzufügen der Listener zur YUI DOM für die Events "mouseOver" und "mouseOut" mit den jeweiligen Aktionen
    YAHOO.util.Event.addListener(objTar, "mouseover", FadeThisText, {
        direction: "FadeIn"
    });
    YAHOO.util.Event.addListener(objTar, "mouseout", FadeThisText, {
        direction: "FadeOut"
    });
    
    YAHOO.util.Event.addListener(objTar, "click", FadeThisText, true);
    
}

/*
 ************************************
 * Animation der HTML-Elemente Home *
 ************************************
 */
function doFadeHomeIn(num){

    var curactposition = curactpositionObj[num];
    var curactvisible = curactvisibleObj[num];
    
    if (curactvisible > curvisibleend) {
        //Fade Schrift
        curopacity = curactvisible - 4 - Math.ceil((curactposition / 25));
        var textobj = document.getElementById("claim" + num);
        textobj.style.opacity = (curopacity / 100);
        textobj.style.MozOpacity = (curopacity / 100);
        textobj.style.KhtmlOpacity = (curopacity / 100);
        textobj.style.filter = "alpha(opacity=" + curopacity + ")";
        curactvisible = curopacity;
        //Neu setzen des Parameter
        curactvisibleObj[num] = curactvisible;
    }
    else 
        if (curactvisible <= curvisibleend) {
            if (curactposition < curtainend) {
                //nach oben fahren Vorhang
                curposition = curactposition + curspeed - Math.ceil((curactposition / 25));
                var curtainobj = document.getElementById("curtain" + num);
                curtainobj.style.bottom = curposition + "px";
                curactposition = curposition;
                //Neu setzen des Parameter
                curactpositionObj[num] = curactposition;
            }
            else 
                if (curactposition >= curtainend) {
                    return false;
                }
        }
        else {
            return false;
        }
}

function doFadeHomeOut(num){

    var curactposition = curactpositionObj[num];
    var curactvisible = curactvisibleObj[num];
    
    if (curactposition > curtainstart) {
        //nach unten fahren Vorhang
        curposition = curactposition - curspeed + Math.ceil((curactposition / 25));
        var curtainobj = document.getElementById("curtain" + num);
        if (curposition < curtainstart) {
            curposition = curtainstart;
        }
        curtainobj.style.bottom = curposition + "px";
        curactposition = curposition;
        //Neu setzen des Parameter
        curactpositionObj[num] = curactposition;
    }
    else 
        if (curactposition <= curtainstart) {
            if (curactvisible < curvisiblestart) {
                //Fade Schrift
                curopacity = curactvisible + 4 + Math.ceil((curactposition / 25));
                var textobj = document.getElementById("claim" + num);
                textobj.style.opacity = (curopacity / 100);
                textobj.style.MozOpacity = (curopacity / 100);
                textobj.style.KhtmlOpacity = (curopacity / 100);
                textobj.style.filter = "alpha(opacity=" + curopacity + ")";
                curactvisible = curopacity;
                //Neu setzen des Parameter
                curactvisibleObj[num] = curactvisible;
            }
        }
        else {
            return false;
        }
}

/*
 ***********************
 * Animation Slideshow *
 ***********************
 */
function initSlideshow(){

    var actImage;
    var actText;
    
    //Animation Bild
    var animateImg = function(){
        actImage = document.getElementById(actImageNumber);
        animImg = new YAHOO.util.Anim(actImage);
        animImg.attributes.bottom = {
            to: imgPositionEnd
        };
        animImg.duration = 1;
        animImg.method = YAHOO.util.Easing.easeOut;
        animImg.animate();
        animImg.onComplete.subscribe(changeZIndex);
    };
    
    //Animation Text
    var animateText = function(){
        actImage = document.getElementById(actImageNumber);
        actText = actImage.getElementsByTagName("dd");
        animText = new YAHOO.util.Anim(actText);
        animText.attributes.opacity = {
            to: 1
        };
        animText.duration = 1;
        animText.method = YAHOO.util.Easing.easeOut;
        animText.animate();
        animText.onComplete.subscribe(delayCallbackImg);
    };
    
    //Timeout Text
    var delayCallbackTxt = function(){
        window.setTimeout(animateText, delayS);
    };
    
    //Timeout Img
    var delayCallbackImg = function(){
        window.setTimeout(animateImg, delay);
    };
    
    //Setzen des Z-Index
    var changeZIndex = function(){
    
        for (i = 0; i < dlobj.length; i++) {
            //if (dlobj[i].className == 'csc-textpic-image csc-textpic-firstcol csc-textpic-lastcol') {
                if (dlobj[i].id == actImageNumber) {
                    dlobj[i].style.zIndex -= (allImageDivsLength - 1);
                    
                    var textObj = dlobj[i].getElementsByTagName("dd")[0];
                    textObj.style.opacity = 0;
                    textObj.style.MozOpacity = 0;
                    textObj.style.KhtmlOpacity = 0;
                    textObj.style.filter = "alpha(opacity=0)";
                    
                }
                else {
                    var newZIndex = (parseInt(dlobj[i].style.zIndex)) + 1;
                    dlobj[i].style.zIndex = newZIndex;
                }
                
                dlobj[i].style.bottom = 360 + "px";
            //}
        }
        actImageNumber++;
        
        if (actImageNumber == allImageDivsLength) {
            actImageNumber = 0;
        }
        delayCallbackTxt();
    };
    
    delayCallbackTxt();
    
}



/*
 ******************
 * Animation Text *
 ******************
 */
function doFadeTextIn(){
    for (num = 0; num < allImageDivsLength; num++) {
        var actposition = actposition1;
        var positionstart = positionstart1;
        if (actposition < (positionend - 1)) {
            position = actposition + 3;
            for (numi = 0; numi < allImageDivsLength; numi++) {
                dlobj[numi].getElementsByTagName("dd")[0].style.bottom = position + "px";
            }
            actposition = position;
            actposition1 = actposition;
        }
        else 
            if (actposition >= (positionend - 1)) {
                for (numi = 0; numi < allImageDivsLength; numi++) {
                    dlobj[numi].getElementsByTagName("dd")[0].style.bottom = positionend + "px";
                }
                actposition = positionend;
                var actvisible = actvis;
                if (actvisible < visibleend) {
                    opacity = actvisible + 3;
                    var textobj = dlobj[num].getElementsByTagName("dd")[1];
                    textobj.style.opacity = (opacity / 100);
                    textobj.style.MozOpacity = (opacity / 100);
                    textobj.style.KhtmlOpacity = (opacity / 100);
                    textobj.style.filter = "alpha(opacity=" + opacity + ")";
                    actvisible = opacity;
                    actvis = actvisible;
                }
                else 
                    if (actvisible >= visibleend) {
                        return false;
                    }
            }
            else {
                return false;
            }
    }
}

function doFadeTextOut(){
    for (num = 0; num < allImageDivsLength; num++) {
        var backgroundobj = dlobj[num].getElementsByTagName("dd")[0];
        
        var actvisible = actvis;
        if (actvisible > visiblestart) {
            opacity = actvisible - 3;
            var textobj = dlobj[num].getElementsByTagName("dd")[1];
            textobj.style.opacity = (opacity / 100);
            textobj.style.MozOpacity = (opacity / 100);
            textobj.style.KhtmlOpacity = (opacity / 100);
            textobj.style.filter = "alpha(opacity=" + opacity + ")";
            actvisible = opacity;
            actvis = actvisible;
        }
        else 
            if (actvisible <= visiblestart) {
                var actposition = actposition1;
                var positionstart = positionstart1;
                if (actposition > positionstart) {
                    position = actposition - 2;
                    for (numi = 0; numi < allImageDivsLength; numi++) {
                        dlobj[numi].getElementsByTagName("dd")[0].style.bottom = position + "px";
                    }
                    actposition = position;
                    actposition1 = actposition;
                }
                else 
                    if (actposition <= positionstart) {
                        for (numi = 0; numi < allImageDivsLength; numi++) {
                            dlobj[numi].getElementsByTagName("dd")[0].style.bottom = positionstart + "px";
                        }
                        return false;
                    }
            }
            else {
                return false;
            }
    }
    
}

//////////////////////////////////////////////////////////////////////////////////////////////
/*
 ***********************************
 * Registrierung der HTML-Elemente *
 ***********************************
 */
WWIA_header_init = function(){

    flashcontentobj = document.getElementById("flashcontent");
    
    header1Obj = document.getElementById("header1");
    header2Obj = document.getElementById("header2");
    header3Obj = document.getElementById("header3");
    
    if (header1Obj || header2Obj || header3Obj) {
        //STARTSEITE
        flashcontentobj.style.height = 360 + "px";
        
        RegisterHomeListeners(header1Obj);
        RegisterHomeListeners(header2Obj);
        RegisterHomeListeners(header3Obj);
    }
    else {
        dlobj = flashcontentobj.getElementsByTagName("dl");
        if (dlobj.length > 1) {
            //SLIDESHOW
            allImageDivsLength = 0;
            for (i = 0; i < dlobj.length; i++) {
                var ddobj = dlobj[i].getElementsByTagName("dd");
                var ddobjlength = ddobj.length;
                //if (dlobj[i].className == 'csc-textpic-image csc-textpic-firstcol csc-textpic-lastcol') {
                    //console.log("csc-textpic-imagerow");
                    allImageDivsLength++;
                    dlobj[i].style.zIndex = 100 - i;
                    dlobj[i].style.position = "absolute";
                    dlobj[i].id = allImageDivsLength - 1;
					dlobj[i].style.display = "block";
                    for (j = 0; j < ddobjlength; j++) {
                        if (ddobj[j].className == 'csc-textpic-caption') {
                            var thisddobj = ddobj[j];
                            thisddobj.style.fontFamily = "'Times New Roman',Times,Georgia,serif";
                            thisddobj.style.fontSize = "45px";
                            thisddobj.style.lineHeight = "0.88em";
                            thisddobj.style.letterSpacing = "0.02em";
                            thisddobj.style.bottom = -contentheight + 16 + "px";
                            thisddobj.style.left = 28 + "px";
                            thisddobj.style.width = 900 + "px";
                        }
                    }
                //}
            }
            initSlideshow();
        }
        else {
            //MOUSEOVER TEXT
            for (i = 0; i < dlobj.length; i++) {
			dlobj[i].style.display = "block";
                var ddobj = dlobj[i].getElementsByTagName("dd");
                var ddobjlength = ddobj.length;
                for (j = 0; j < ddobjlength; j++) {
                    if (ddobj[j].className == 'csc-textpic-caption') {
                        var backgroundobj = document.createElement("dd");
                        var thisdlobj = dlobj[i];
                        var thisddobj = ddobj[j];
                        var height = thisddobj.offsetHeight + 3;
                        
                        var mouseoverobj = document.createElement("div");
                        mouseoverobj.className = "mouseover";
                        mouseoverobj.style.height = 360 + "px";
                        thisdlobj.insertBefore(mouseoverobj, thisddobj);
                        
                        backgroundobj.className = "background";
                        backgroundobj.style.height = height + "px";
                        backgroundobj.style.bottom = -height + "px";
                        thisdlobj.insertBefore(backgroundobj, thisddobj);
                        
                        var ddheight = ddobj[j].offsetHeight;
                    }
                }
                
                divobj = flashcontentobj.getElementsByTagName("div");
                var divobjlength = divobj.length;
                for (j = 0; j < divobjlength; j++) {
                    if ((divobj[j].className == 'csc-textpic-imagewrap') && (divobj[j].getElementsByTagName("a").length >= 1)) {
                        ahref = divobj[j].getElementsByTagName("a")[0].href;
                        isLink = true;
                    }
                }
            }
            
            if (dlobj[0] && dlobj[0].getElementsByTagName("dd")[0]) {
                RegisterHeaderListeners(dlobj[0].getElementsByTagName("div")[0]);
            }
        }
    }
};
