
// initializes some variables and arrays..
var i = 0;
var arrMenuTO = new Array();
var arrMenuDown = new Array();

$(document).ready(function(){

	$(".hideWhenJS").hide();
	$(".removeWhenJS").remove();

    //initializing for some functionality
    scaling();
    initializeFaq();
    initializeBranchenkompetenzen();
    initializeSlideContent();
    initializeMiscElements();
    
    
	/**
	 *  helper functions for MAFO
	 */
    $("#sectionCheckboxes :checkbox").click(function(){
    
        if ($("#sectionCheckboxes :checked").length > 3) {
            return false;
        }
        
        if ($("#questionInput_" + $(this).attr("name")).hasClass("hidden")) {
            $("#questionInput_" + $(this).attr("name")).fadeIn();
            $("#questionInput_" + $(this).attr("name")).removeClass("hidden");
        }
        else {
            $("#questionInput_" + $(this).attr("name")).fadeOut();
            $("#questionInput_" + $(this).attr("name")).addClass("hidden");
        }
    })
    
    
    if (typeof soundWindow == 'object') {
        $('#soundControl').attr('src', 'fileadmin/images/basic/ic_soundbutton.png');
    }
    
    
    /**
     * what's new fader
     * whatsNewArray is delivered by an extension which writes the content to the html header directly
     */
    if (typeof(whatsNewArray) == 'object') {
        whatsNewArrayLength = whatsNewArray.length;
        whatsNewAnimation();
    }
    
    
	//sets the overlay div to the current browserheight
    $("#overlay").css({
        height: $(document).height()
    });
    
    
    $("#errorMsgButton").click(function(){
        removeErrorBox();
        return false;
    });
    
    $("#errorOverlay").css({
        height: $(document).height(),
        opacity: 0.8
    });
	
    $("#overlay").css({
        height: $(document).height(),
        opacity: 0.8
    });
	
    $("#errorMsgOuterBox").css({
        width: $(document).width()
    });
    
    
    /* sIFR */
    if (typeof sIFR == "function") {
        window.setTimeout("sifrReplacement();", 300);
    };

	// calls the function for resizing the content areas..
    $(window).resize(function(){
        //resizeMe();
        scaling();
    });
    
    
    /**
     *  management rollover and fadein / fadeout functionality for the heads
     */
    $(".managementImage img").mouseover(function(){
        $(".headsAnimation #" + $(this).attr("id") + "_ro").fadeIn(200);
    }).mouseout(function(){
        $(".headsAnimation .peopleBox").fadeOut(200);
    });
    
    
	
	/************
	 * what's new
	 **********/
	
    /**
     *  gets the news jumpbuttons running
     */
    $("#previousNews").click(function(){
        var previousId = eval($("#counter").html() + "- 1");
        if (newsEntries[previousId] != undefined) {
            $.get(newsRequestLink + "&tx_ttnews[tt_news]=" + newsEntries[previousId], function(data){
                fillInContent(data);
                
            });
            //	doRequest(newsRequestLink + "&tx_ttnews[tt_news]=" + newsEntries[previousId])
            $("#counter").html(previousId);
            
        }
        
        makeJumpButtons();
        
        return false;
    });
	
    
    $("#nextNews").click(function(){
        var nextId = eval($("#counter").html() + "+ 1");
        
        if (newsEntries[nextId] != undefined) {
            $.get(newsRequestLink + "&tx_ttnews[tt_news]=" + newsEntries[nextId], function(data){
                fillInContent(data);
                
            });
            //	doRequest(newsRequestLink + "&tx_ttnews[tt_news]=" + newsEntries[nextId])
            $("#counter").html(nextId);
            
        }
        
        makeJumpButtons();
        
        return false;
    });
    
    
    $("#username").click(function(){
        removeInput('username', false);
    })
    
    $("#password").click(function(){
        removeInput('password', false);
    })
    
    $("#searchInput").click(function(){
        removeInput('searchInput', false);
        return false;
    });
    
	
    //initializes the contentscrolling
    window.setTimeout("ivMakeScrollable();", 200);
    
	
    //initializes the menu
    var u = 0;
    $("li.mainmenu").each(function(i){
        if ($(this).attr('id') == '') {
            $(this).attr('id', 'mainmenuli_' + u);
            arrMenuTO['mainmenuli_' + u] = '';
            arrMenuDown['mainmenuli_' + u] = false;
            u++;
        }
    });
    
    
});


/**
 *  helper function
 */
function str_replace(search, replace, subject){
    return subject.split(search).join(replace);
}


/**
 *  displays the click2call popup
 */
function click2callPopup(){

    //set the height of the black background layer again.. measurements may have changed
    $("#overlay").css({
        height: $(document).height(),
        opacity: 0.8
    });
    
    //we don't need that this time..
    //$("#errorMsgOuterBox").css({ width: $(document).width()});
    
    //hide all selectboxes..
    $("select").hide();
    
    var html = $('#click2call').html();
    
    html = str_replace('MaTelSoC2CHTML', 'c2cF', html);
    html = str_replace('GesamtNummer', 'c2cGn', html);
    html = str_replace('PartnerID', 'c2cPid', html);
    html = str_replace('Land', 'c2cL', html);
    
    $("#errorMsgText").html(html);
    
    $("#errorMsgOuterBox").css({
        top: ($(document).scrollTop() + 200)
    });
    
    //display the errorbox
    $("#overlay").fadeIn(350, function(){
        $("#errorMsgOuterBox").fadeIn(200);
        $("#errorFieldID").attr("value", 'click2call');
    });
    
    //bind the click event on the overlay div
    $("#overlay").click(function(){
        removeErrorBox();
    });
    
    return false;
}


/**
 *  TO DO.. check if this is obsolote because it is already given in the specific pages.. if not.. take it there
 */
function initializeMiscElements(){
    $(".futureOpened #back").click(function(){
        $(".futureOpened").fadeOut("slow", function(){
            $(".future").fadeIn("slow")
        });
        
        return false;
    })
    
    
}


/**
 *  initializes functionality for branchenkompetenzen
 */
function initializeBranchenkompetenzen(){

    $("#branchenkompetenzen a").click(function(){
    
        if ($("#" + $(this).attr("id") + "_ro").hasClass("open")) {
            $("#branchenkompetenzen .open").slideUp();
            $("#branchenkompetenzen .open").removeClass("open");
            $("#branchenkompetenzen a").removeClass("openBranchenLink");
            
            return false;
        }
        
        $("#branchenkompetenzen .open").slideUp();
        
        $("#branchenkompetenzen .open").removeClass("open");
        $("#branchenkompetenzen a").removeClass("openBranchenLink");
        
        $("#" + $(this).attr("id") + "_ro").addClass("open");
        $(this).addClass("openBranchenLink");
        $("#branchenkompetenzen #" + $(this).attr("id") + "_ro").slideDown();
        
        return false;
    })
    
}


/**
 *  removes the values from an inputfield if it is clicked
 */
function removeInput(id, strReplace){
    if (strReplace) {
        $('#' + id).val(strReplace);
        window.setTimeout("removeInput('" + id + "');", 1800);
    }
    else {
        var arrStr = $('#' + id).val().split('');
        void arrStr.shift();
        $('#' + id).val(arrStr.join(''));
        if ($('#' + id).val().length > 0) {
            window.setTimeout("removeInput('" + id + "');", 100);
        }
    }
}


/**
 * helper function for the menu
 */
var currWidth = 85;
var menuSpeed = 200; // the higher the slower
function slideDown(id){

    window.clearTimeout(arrMenuTO[id]);
    
    if (arrMenuDown[id]) {
        return;
    }
    
    arrMenuDown[id] = true;
    
    for (var i in arrMenuDown) {
        if (i != id && $("#" + i + " ul").attr('style') != undefined) {
            if (slideUp(i)) {
                continue;
            }
        }
    }
    
    var parentListItemWidth = '155';
    
    if (id == "iconShark") {
        var parentListItemWidth = '85';
    }
    
    $("#" + id).animate({
        width: parentListItemWidth
    }, menuSpeed, function(){
    
        $("#" + id + " ul").hide();
        
        if (arrMenuDown[id]) {
        
            $("#" + id + " iframe").css('height', $("#" + id + " ul").height() + 'px');
            $("#" + id + " ul").slideDown(menuSpeed, function(){
                $("#" + id + " iframe").show();
            });
            
        }
        else {
        
            $("#" + id + " ul").hide();
            $("#" + id + " ul").removeAttr("style");
            $("#" + id + " iframe").hide();
            $("#" + id + " iframe").removeAttr("style");
            
        }
        
    });
    
}


/**
 * helper function for the menu
 */
function slideUp(id){

    arrMenuDown[id] = false;
    window.clearTimeout(arrMenuTO[id]);
    
    $("#" + id + " iframe").hide();
    $("#" + id + " ul").slideUp(menuSpeed, function(){
    
        if (id == "iconShark") {
            currWidth = '25';
        }
        else {
            currWidth = 85;
        }
        
        $("#" + id).animate({
            width: currWidth + "px"
        }, menuSpeed, function(){
            $("#" + id + " ul").hide();
            $("#" + id + " ul").removeAttr("style");
            $("#" + id + " iframe").hide();
            return true
        });
    });
}


/**
 * helper function for the menu
 */
function mouseOut(id){
    window.clearTimeout(arrMenuTO[id]);
    arrMenuTO[id] = window.setTimeout("slideUp('" + id + "');", 100);
}


/**
 * helper function for the menu
 */
function mouseOver(id){
    window.clearTimeout(arrMenuTO[id]);
}


/**
 *  helper function for scaling the contentareas
 */
var TO;
function scaling(){
    window.clearTimeout(TO);
    TO = window.setTimeout("resizeDynamicDivs();", 50);
}


/** this resizes the content areas if browser width is changed
 * 
 */
function resizeDynamicDivs(){
    var startWidth = 1000; // 1000
    var dynamicLeft = 10; // 10
    var dynamicMiddle = 0; // 0
    var dynamicRight = 0; // 0
    var maxLeftWidth = 280; // 280
    var maxMiddleWidth = 378; // 378
    var maxRightWidth = 280; // 280
    var resizeFactor = (maxLeftWidth + maxRightWidth) / maxMiddleWidth;
    var percentLeft = (resizeFactor * 100) / (resizeFactor + 1);
    var percentMiddle = (1 * 100) / (resizeFactor + 1);
    percentLeft = percentLeft / 2;
    var percentRight = percentLeft;
    var documentWidth = $(window).width();
    var widthDifference = documentWidth - startWidth;
    
    if (documentWidth <= startWidth) {
        var newDynamicLeftWidth = dynamicLeft;
        var newDynamicMiddleWidth = dynamicMiddle;
        var newDynamicRightWidth = dynamicRight;
    }
    else {
        var newDynamicLeftWidth = ((widthDifference / 100) * percentLeft);
        var newDynamicMiddleWidth = ((widthDifference / 100) * percentMiddle);
        var newDynamicRightWidth = newDynamicLeftWidth;
        if (newDynamicLeftWidth >= maxLeftWidth) {
            newDynamicLeftWidth = maxLeftWidth;
            newDynamicMiddleWidth = maxMiddleWidth;
            newDynamicRightWidth = maxRightWidth;
        }
    }
    
    var absWidth = newDynamicLeftWidth + 770 + newDynamicMiddleWidth + 212 + newDynamicRightWidth;
    $('#main').css({
        width: ($('#main').width() + 20) + 'px'
    });
    
    if ($.cookie('resize') == null || $.cookie('resize') != $(window).width()) {
    
        if (navigator.userAgent.indexOf('MSIE 7') != -1 ||
        (navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('MSIE 6') == -1)) {
            $('#main').animate({
                width: absWidth + 'px'
            });
            $('#dynamicLeft').animate({
                width: newDynamicLeftWidth + 'px'
            });
            $('#dynamicMiddle').animate({
                width: newDynamicMiddleWidth + 'px'
            });
        }
        else 
            if (navigator.userAgent.indexOf('MSIE 6') != -1) {
                $('#dynamicLeft').css({
                    width: newDynamicLeftWidth + 'px'
                });
                $('#dynamicMiddle').css({
                    width: newDynamicMiddleWidth + 'px'
                });
                $('#main').css({
                    width: absWidth + 'px'
                });
            }
            else {
                $('#main').animate({
                    width: absWidth + 'px'
                }, {
                    duration: 1000,
                    easing: 'easein'
                });
                $('#dynamicLeft').animate({
                    width: newDynamicLeftWidth + 'px'
                }, {
                    duration: 1000,
                    easing: 'easein'
                });
                $('#dynamicMiddle').animate({
                    width: newDynamicMiddleWidth + 'px'
                }, {
                    duration: 1000,
                    easing: 'easein'
                });
            }
        
    }
    else {
    
        $('#dynamicLeft').css({
            width: newDynamicLeftWidth + 'px'
        });
        $('#dynamicMiddle').css({
            width: newDynamicMiddleWidth + 'px'
        });
        $('#main').css({
            width: absWidth + 'px'
        });
        
    }
    
    $.cookie('resize', $(window).width(), {
        expires: 7,
        path: '/'
    });
    
}


/**
 *  we need that for replacing the headline on an initial page request and when some content is loaded via AJAX or the content is placed into a scrollable area
 */
function sifrReplacement(){
    
    sIFR.replaceElement("h1.normal", named({
        sFlashSrc: "fileadmin/fonts/franklin_book.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    sIFR.replaceElement("h1.bold", named({
        sFlashSrc: "fileadmin/fonts/franklin_demi.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    sIFR.replaceElement("h2.normal", named({
        sFlashSrc: "fileadmin/fonts/franklin_book.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    sIFR.replaceElement("h2.bold", named({
        sFlashSrc: "fileadmin/fonts/franklin_demi.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    
    sIFR.replaceElement("h3.normal", named({
        sFlashSrc: "fileadmin/fonts/franklin_book.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    sIFR.replaceElement("h3.bold", named({
        sFlashSrc: "fileadmin/fonts/franklin_demi.swf",
        sColor: "#000000",
        sWmode: "transparent"
    }));
    
    sIFR.replaceElement("h3.boldWhite", named({
        sFlashSrc: "fileadmin/fonts/franklin_demi.swf",
        sColor: "#FFFFFF",
        sWmode: "transparent"
    }));
    sIFR.replaceElement("h3.demiWhite", named({
        sFlashSrc: "fileadmin/fonts/franklin_book.swf",
        sColor: "#FFFFFF",
        sWmode: "transparent"
    }));
}


/**
 *  make the jumpbuttons which offers the opportunity to switch between the news entries via AJAX
 */
function makeJumpButtons(){

    var nextPotentialId = eval($("#counter").html() + "+ 1");
    if (newsEntries[nextPotentialId] == undefined) {
        $("#nextNews").fadeOut("fast");
    }
    else {
        $("#nextNews").fadeIn("fast");
    }
    
    var previousPotentialId = eval($("#counter").html() - 1);
    
    
    if (newsEntries[previousPotentialId] == undefined) {
        $("#previousNews").fadeOut("fast");
    }
    else {
        $("#previousNews").fadeIn("fast");
    }
    
}


/**
 *  what's new animation.. takes the whatsNewArray with all latest entries as an JSON Object and displays them in a loop
 */
function whatsNewAnimation(){

    if (whatsNewArrayLength == i) {
        i = 0;
    }
    
    $("#whatsNewText").fadeOut(350, function(){
        $("#whatsNewText").html(whatsNewArray[i]);
        $(".whatsNewTitle a").attr("href", whatsNewLinksArray[i]);
        $("#whatsNewText").fadeIn(350);
        i = i + 1;
    })
    
    window.setTimeout('whatsNewAnimation()', 5000);
    
}


/**
 * helper function which fills the response values to the contentarea on the what's new page
 */
function fillInContent(data){
    $("#newsContent").fadeOut("slow", function(){
        $("#newsContent").hide();
        $("#newsContent").html(data);
        $("#newsContent").fadeIn("slow");
        
        makeJumpButtons();
        sifrReplacement();
        
		initializeLightbox();

        window.setTimeout("ivMakeScrollable();", 200);
    });
}


function initializeLightbox() {
	jQuery.noConflict();
		(function($) { 
			$(function() {$(".lightbox").lightbox( {navbarOnTop: 0 , resizeSpeed: 300 , overlayOpacity: 0.8, strings : { prevLinkTitle: "vorheriges Bild", nextLinkTitle: "nächstes Bild", prevLinkText:  "&laquo;&nbsp;&nbsp;", nextLinkText:  "&nbsp;&nbsp;&raquo;",closeTitle: "schließen", image: "Bild", of: "von"}});});
	})(jQuery);
}



/***************************************************
 * functions for displaying error messageboxes
 **********************************************/

/**
 * removes the errorBox and focuses the given element
 */
function removeErrorBox(){
    $("#errorMsgOuterBox").hide();
    $("#overlay").fadeOut("fast");
    $("select").show();
    $("#" + $("#errorFieldID").attr("value")).focus();
    
    return false;
}


/**
 * displays the errorbox with the given text
 * @argument_1 = text for the messagebox
 * @argument_2 = element which we want to focus when the errorbox disappears..
 */
function displayErrorBox(errorText, element){

    //set the height of the black background layer again.. measurements may have changed
    $("#overlay").css({
        height: $(document).height(),
        opacity: 0.8
    });
    
    //hide all selectboxes..
    $("select").hide();
    
    $("#errorMsgText").html(errorText);
    
    $("#errorMsgOuterBox").css({
        top: ($(document).scrollTop() + 200)
    });
    
    //display the errorbox
    $("#overlay").fadeIn(350, function(){
        $("#errorMsgOuterBox").fadeIn(200);
        $("#errorFieldID").attr("value", element);
    });
    
    //bind the click event on the overlay div
    $("#overlay").click(function(){
        removeErrorBox();
    })
    
    return false;
}


/**
 *  display the soundButton Popup
 */
var soundWindow = true;
function popitup(){

    if (typeof soundWindow != 'object') {
        $('#soundControl').attr('src', 'fileadmin/images/basic/ic_soundbutton.png');
        soundWindow = window.open('/sound.html', 'soundWin', 'dependent=yes,width=400,height=150,scrollbars=yes');
        soundWindow.blur();
    }
    else {
        stopSound();
    }
    
}


function letsPlayMusic(file) {
    if (typeof soundWindow != 'object') {
		
        soundWindow = window.open('/music.html?file=' + file, "soundwin", 'dependent=yes,width=400,height=150,scrollbars=yes');
		
    } else {
		
	    if (typeof soundWindow == 'object') {
	        soundWindow.close();
	    }
	    soundWindow = false;
		
    }
	
	return false;
}



/**
 *  stops the played sound..
 */
function stopSound(){

    if (typeof soundWindow == 'object') {
        soundWindow.close();
    }
    soundWindow = false;
    $('#soundControl').attr('src', 'fileadmin/images/basic/ic_soundbuttonSilence.png');
    
}


/**
 *  because we have some scrollbars in the FAQ we need to initializes it again..
 *  this function is being used for initialize other functionalities, too
 */
function initializeFaq(){

    /* FAQ */
    $(".tx-irfaq-pi1 dt a").click(function(){
        return openFaq(this, 'faq');
    });
    
    // Why Us
    $(".whyUsTeasertext dt a").click(function(){
        return openFaq(this, 'whyus');
    });
    
    initializeBranchenkompetenzen();
    initializeMafo();
    initializeSubpages();
    initializeMiscElements();
}


/**
 *  opens the FAQ
 */
var whyUsDisplayImage = true;
function openFaq(obj, type){

    $("#answer_" + $(obj).attr("id") + " div.ivScContent").addClass('ivScContent_2');
    $("#answer_" + $(obj).attr("id") + " div.ivScContent").removeClass('ivScContent');
    
    $("dd").slideUp("slow");
    $("dt a").removeClass("open");
    
    openId = "#answer_" + $(obj).attr("id");
    
    if ($("#answer_" + $(obj).attr("id") + " div.ivScContent_2").attr("id") != undefined) {
        $("#answer_" + $(obj).attr("id") + " div").css('overflow', 'hidden');
        var html = $("#answer_" + $(obj).attr("id") + " div.ivScContent_2").html();
        $("#answer_" + $(obj).attr("id")).empty();
        $("#answer_" + $(obj).attr("id")).html(html);
    }
    
    $('#whyUs dd.ivScrollable').removeClass('ivScrollable');
    
    if (type == 'whyus' && whyUsDisplayImage) {
    
        $('.celebrateSuccess').fadeOut();
        $('.image').fadeOut(function(){
            $("#answer_" + $(obj).attr("id")).slideDown("slow", function(){
            
                if (type == 'whyus') {
                
                    $("#answer_" + $(obj).attr("id")).css('width', '620px');
                    
                    var answerHeight = $("#answer_" + $(obj).attr("id")).height();
                    var availableHeight = 219;
                    
                    if (answerHeight > availableHeight) {
                        $("#answer_" + $(obj).attr("id")).addClass('ivScrollable');
                        ivMakeScrollable();
                    }
                }
                
            });
            $(obj).addClass("open");
        });
        whyUsDisplayImage = false;
        
    }
    else {
    
        $("#answer_" + $(obj).attr("id")).slideDown("slow", function(){
        
            if (type == 'whyus') {
            
                $("#answer_" + $(obj).attr("id")).css('width', '620px');
                
                var answerHeight = $("#answer_" + $(obj).attr("id")).height();
                var availableHeight = 219;
                
                if (answerHeight > availableHeight) {
                    $("#answer_" + $(obj).attr("id")).addClass('ivScrollable');
                    ivMakeScrollable();
                }
            }
            
        });
        $(obj).addClass("open");
    }
    
    if (type == 'faq') {
        $(".tx-irfaq-pi1 dt a").unbind("click");
        $(".tx-irfaq-pi1 dt a").click(function(){
            return openFaq(this, type);
        });
    }
    
    if (type == 'whyus') {
        $(".whyUsTeasertext dt a").unbind("click");
        $(".whyUsTeasertext dt a").click(function(){
            return openFaq(this, type);
        });
    }
    
    $(obj).unbind("click");
    
    $(obj).click(function(){
        return closeFaq(this, type);
    });
    
    return false;
    
}


/**
 * closes the FAQ
 */
function closeFaq(obj, type){

    if ($("#answer_" + $(obj).attr("id") + " div.ivScContent").attr("id") != undefined) {
        var html = $("#answer_" + $(obj).attr("id") + " div.ivScContent").html();
        $("#answer_" + $(obj).attr("id")).empty();
        $("#answer_" + $(obj).attr("id")).html(html);
    }
    
    $('#whyUs dd.ivScrollable').removeClass('ivScrollable');
    
    $("#answer_" + $(obj).attr("id")).slideUp("slow", function(){
        $('.celebrateSuccess').fadeIn();
        $('.image').fadeIn();
        whyUsDisplayImage = true;
    });
    
    $(obj).removeClass("open");
    
    if (type == 'faq') {
        $(".tx-irfaq-pi1 dt a").unbind("click");
        $(".tx-irfaq-pi1 dt a").click(function(){
            return openFaq(this, type);
        });
    }
    
    if (type == 'whyus') {
        $(".whyUsTeasertext dt a").unbind("click");
        $(".whyUsTeasertext dt a").click(function(){
            return openFaq(this, type);
        });
    }
    
    return false;
}


/**
 *  initializes the helper function for fading in / fading out or slideDown and SlideUp
 */
function initializeSlideContent(){

    $(".boxDynamicContent a").click(function(){
    
        var id = $(this).attr("id");
        
        if ($(".boxDynamicContent .open").length == 0) {
        
            hideImages()
			hideFiveSystemImage();
			
            setTimeout("boxDynamicContentSlider('" + id + "');", 550);
            return false;
            
        } else {
        
            boxDynamicContentSlider(id);
			showFiveSystemImage();
            return false;
            
        }
    })
	

}


function hideFiveSystemImage() {
	$("#fiveSystemImage").fadeOut(500);
}


function showFiveSystemImage() {
	setTimeout('$("#fiveSystemImage").fadeIn(600);', 650);
}


/**
 * helper function for fading in / fading out or slideDown and SlideUp
 */
function boxDynamicContentSlider(id){

    if ($(".boxDynamicContent #" + id + "_ro").hasClass("open")) {
        $(".boxDynamicContent .open").slideUp("slow", function(){
            setTimeout("showImages()", 300);
            $(".boxDynamicContent .open").removeClass("open");
            $(".boxDynamicContent a").removeClass("openSubpageLink");
            
            $(".boxDynamicContent .ivScButton").fadeOut();
            $(".boxDynamicContent .ivScButton").hide();
        });
        
        return false;
    }
    
    
    $(".boxDynamicContent .slideContent").slideUp("slow");
    $(".boxDynamicContent .open").removeClass("open");
    $(".boxDynamicContent a.openSubpageLink").removeClass("openSubpageLink");
    
    $(".boxDynamicContent #" + id + "_ro").slideDown("slow", function(){
    
        //hide all ScrollTools, so if a block is re-opened it can faded in again..
        $(".boxDynamicContent .ivScButton").fadeOut();
        $(".boxDynamicContent .ivScButton").hide();
        
        //delete the scrollTools if not needed. We need to do this because the scrollTools are initialized when the page loads
        var parentHeight = $(".boxDynamicContent #" + id + "_ro").height();
        
        if (!($(".boxDynamicContent #" + id + "_ro .ivScContent").height() > parentHeight)) {
            $(".boxDynamicContent #" + id + "_ro .ivScButton").html('');
			$(".boxDynamicContent #" + id + "_ro .ivScContent").unbind('mousewheel');
        }
        else {
            $(".boxDynamicContent #" + id + "_ro .ivScButton").fadeIn();
        }
        
    });
    
    $(".boxDynamicContent #" + id + "_ro").removeClass("hidden");
    $("#" + id).addClass("openSubpageLink");
    $(".boxDynamicContent #" + id + "_ro").addClass("open");
    
    return false;
}


/**
 *  helper function to hide images
 */
function hideImages(){
    $(".image").fadeOut();
    $("#astra").fadeOut();
    $("#treppe").fadeOut();
}


/**
 *  helper function to show images
 */
function showImages(){
    $(".image").fadeIn();
    $("#astra").fadeIn();
    $("#treppe").fadeIn();
}


/**
 *  functionality which handles the freecall feature
 */
function c2c_submit(){

    var c2cLink = $('#c2cF').attr('action') + '?GesamtNummer=' + $('#c2cGn').val() + '&PartnerID=' + $('#c2cPid').val() + '&Land=' + $('#c2cL').val();
    
    $('body').append('<iframe width="0" height="0" frameborder="0" src="' + c2cLink + '" scrolling="no" style="display:none;"></iframe>');
    
    $("#errorMsgText").empty();
    $('#errorMsgText').html('<p style="text-align:center;"><img src="fileadmin/images/loader/ajax-loader.gif" alt="Loading..." /></p>');
    
    window.setTimeout("$('#errorMsgText').empty(); $('#errorMsgText').html('<p>Na, klingelt es?</p>');", 1500);
    
    return false;
    
}


/**
 *  initializes the mafo functionality
 */
function initializeMafo(){

    $(".mafoCategory a.mafoCategoryLink").click(function(){
        if ($("#" + $(this).attr("id") + "_ro").hasClass("open")) {
            $(".mafoCategory .open").slideUp();
            $(".mafoCategory .open").removeClass("open");
            $(".mafoCategory a").removeClass("openMafoLink");
            
            return false;
        }
        $(".mafoCategory .open").slideUp();
        
        $(".mafoCategory .open").removeClass("open");
        $(".mafoCategory a").removeClass("openMafoLink");
        
        $("#" + $(this).attr("id") + "_ro").addClass("open");
        $(this).addClass("openMafoLink");
        $("#" + $(this).attr("id") + "_ro").slideDown();
        
        return false;
    })
    
}



/**
 * brings the darkness for the radio.. 
 * 
 * @param {Object} int true or false
 */

function sleepMode(value){
	
	var radioOverlay = '<div id="radioSleepOverlay"></div>';
 
	if(value == 1) {
  
		$("body").append(radioOverlay);
		$("#radioSleepOverlay").css({
			height: $(document).height(),
			opacity: 0.8
		});
		
		$('#radioSleepOverlay').bind('click', function() {
			$('#radioSleepOverlay').unbind('click');
			$("#radioSleepOverlay").fadeOut(350);
			wakeUp();
		});
		
		$("#radioSleepOverlay").fadeIn(350);
	 
	}
	
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
    	return window[movieName];
	} else {
    	return document[movieName];
	}
}

function wakeUp() {
	thisMovie("radioPlayer").wakeUp();
}
