jQuery(document).ready(function() {

    if(typeof(Shadowbox) != "undefined") {
        Shadowbox.init();
    }

    if(typeof(LoadingIndicator) != "undefined") {
        LoadingIndicator.init(0);
    }

    // Akkordeon (FCE)
    $('.accordion-header:eq(0)').addClass("ui-state-active");
    $('.accordion-header:gt(0)').addClass("ui-state-default");
    $('.accordion-content:gt(0)').css("display", "none");
    $('.accordion-header').toggle(function () {
        $('.accordion-header-seo-sitmap').removeClass("ui-state-active").addClass("ui-state-default");
        $('.accordion-header-seo-sitmap').next().hide();

        if ($(this).hasClass("ui-state-default")) {
            $(this).removeClass("ui-state-default");
            $(this).addClass("ui-state-active");
        } else {
            $(this).removeClass("ui-state-active");
            $(this).addClass("ui-state-default");
        }
        $(this).next().toggle();
    }, function () {
        $('.accordion-header-seo-sitmap').removeClass("ui-state-active").addClass("ui-state-default");
        $('.accordion-header-seo-sitmap').next().hide();

        if ($(this).hasClass("ui-state-default")) {
            $(this).removeClass("ui-state-default");
            $(this).addClass("ui-state-active");
        } else {
            $(this).removeClass("ui-state-active");
            $(this).addClass("ui-state-default");
        }
        $(this).next().toggle();
    });
    

    //Buehne AJOB
    var initHeight = 0;
    var initTop = 0;
    jQuery(".aidajobs_teaser").hover(
      function () {
        jQuery(".arrow-active").removeClass("arrow-active");
        jQuery(".job-links").hide();
        jQuery(".job-links-additional").hide();
        jQuery(this).find(".overlay").find(".free-jobs").hide();
        
        initHeight = jQuery(this).find(".overlay").height();
        if(initHeight < 150){//small
            initHeight += 53;
            initTop = -26;
        }else{//big
            initHeight += 85;
            initTop = -43;
        }

        jQuery(this).find("img").animate({
            top:initTop
        }, 300 );
        
        jQuery(this).find(".overlay").animate({
            height: initHeight + "px"
        }, 300 ).find("ul").show();
        jQuery(this).find(".overlay").find(".arrow-inactive").addClass("arrow-active");
      }, 
      function () {
        jQuery(".job-links").hide();
        jQuery(".job-links-additional").hide();
         jQuery(this).find(".overlay").find(".free-jobs").show();
        var hoehe = "199px";
        if(jQuery(this).find(".overlay").hasClass("overlay-typ1")){hoehe = "92px";}
        if(jQuery(this).find(".overlay").hasClass("overlay-typ2")){hoehe = "133px";}

        jQuery(this).find("img").stop(true, true).animate({
            top:"0px"
        }, 300 );
        
        jQuery(this).find(".overlay").stop(true, true).animate({
            height:hoehe
        }, 300 );
        jQuery(".arrow-active").removeClass("arrow-active");
      }
      
    );
    jQuery(".job-links").hide();
    jQuery(".job-links-additional").hide();
        
        
        
        
    // FCE Tabbox special Definitions
    // reconfig anchor-link    
    $("a.tabanchor").each(function() {
        var anchorname = $(this).attr("href");
        anchorname = anchorname.substring(anchorname.indexOf('#'));
        $(this).attr("href",anchorname);
    });
    // initialize tabbox
    $(".tabbox_fce").tabs();
    // add classes .first and .last to tabnavigation
    $(".tabbox_fce").each(function() {
        $(this).find('.tabnavi li.tab:first').addClass('first');
        $(this).find('.tabnavi li.tab:last').addClass('last');        
    });
});

/**
 * @var LoadingIndicator Manages the loading indicator for aida pages.
 */
var LoadingIndicator = {};

/**
 * Function to initialize the loading indicator system which is done some lines
 * above if doom tree is ready.
 */
LoadingIndicator.init = function()
{
    LoadingIndicator.hide(0);

    // global ajax handler - hide load animation
    $('#loadingdiv').bind('ajaxStop', function(){
        LoadingIndicator.hide();
    });

    // global ajax handler - show load animation
    $('#loadingdiv').bind('ajaxStart', function(){
        LoadingIndicator.show();
    });

    // global submit handler - show load animation
    $('form').live('submit', function(){
        LoadingIndicator.show(0);
    });

    // global unload handler - hide load animation
    $(window).unload(function () {
        LoadingIndicator.hide();
    });
};

/**
 * Sets the text inside the loading indicator.
 *
 * @param string text Text to set over default value.
 */
LoadingIndicator.setText = function(text)
{
    $('#preloader-text').html(text);
};

/**
 * Shows the loading indicator.
 *
 * @param integer delay  Time to wait before loading indicator will be shown.
 *                       Default 1000ms.
 * @param integer fadein Time for the fadein effect. Default 1000ms.
 */
LoadingIndicator.show = function(delay, fadein)
{
    delay = delay || 1000;
    fadein = fadein || 1000;
    $('#loadingdiv').delay(delay).fadeIn(fadein);
};


/**
 * Hides the loading indicator.
 *
 * @param integer fadeout Time for the fadeout effect. Default 500ms.
 */
LoadingIndicator.hide = function(fadeout)
{
    fadeout = fadeout || 500;
    $('#loadingdiv').stop(true);
    $('#loadingdiv').fadeOut(fadeout);
};

