$(document).ready(function() 
{
    
    /**
     * Build the Navigation Effect
     */
    $('#nav > li').each(function(index, li){
        $(li).mouseenter(function(){
            var ul = $('ul', $(this));
            if (0 < ul.length) {
                var li = ul.children();
                ul.height(0);
                ul.stop(true).animate({
                    height: (li.length * 21) + 'px'
                }, 250, function(){$(this).height('auto');});
            }
        }); 
    });

    $('#nav > li > ul > li').each(function(index, li){
        $(li).hover(function(){
            var div = $('div', $(this));
            if (0 < div.length) {
                div.height(0);
                div.stop(true).animate({
                    height: '67px'
                }, 500, function(){$(this).height('auto');});
            }
        },
        function(){
            var div = $('div', $(this));
            if (0 < div.length) {
                div.stop(true).animate({
                    height: '0px'
                }, 500);
            }
        }); 
    });
    
    /* Activate Product Slider */
    if(document.getElementById('product_slider'))
    {
        if (document.getElementById('history_carusel'))
        {
            var history_items = $('#history_carusel ul li');
            history_items.each(function(i){
                if (i !== 2){
                  $(this).fadeTo('fast',0.5);
                }
            });
            var btnGo_array = [];
            for (var i = 0; i < history_items.length; i++){
                btnGo_array[i] = '#history_carusel li.car_'+(i+2);
            }
            $('#history_carusel').jCarouselLite({
                btnNext: '.next',
                btnPrev: '.prev',
                visible: 6,
                circular: false,
                beforeStart: function(a){
                   $(a[2]).fadeTo('fast',0.5);
                },
                afterEnd: function(a){
                    for (var i=0; i < a.length; i++)
                    {
                        $(a[i]).fadeTo('fast',0.5);
                    }
                    var li = $(a[2]);
                    li.fadeTo('fast',1);
                    var content = $('#'+li.attr('rel'));
                    $('div[id^=timeline_]').each(function(){
                        $(this).addClass('hideme');
                    });
                    content.removeClass('hideme');
                },
                btnGo: btnGo_array
            });
        }
        else
        {
            $('#product_slider .carusel').jCarouselLite({
                btnNext: '.next',
                btnPrev: '.prev',
                visible: 3,
                circular: false
            });
        }
    }
    
    /* Activate History Slider */
    if(document.getElementById('history_slider'))
    {
        if (document.getElementById('history_carusel'))
        {
            var history_items = $('#history_carusel ul li');
            history_items.each(function(i){
                if (i !== 2){
                  $(this).fadeTo('fast',0.5);
                }
            });
            var btnGo_array = [];
            for (var i = 0; i < history_items.length; i++){
                btnGo_array[i] = '#history_carusel li.car_'+(i+2);
            }
            $('#history_carusel').jCarouselLite({
                btnNext: '.next',
                btnPrev: '.prev',
                visible: 6,
                circular: false,
                beforeStart: function(a){
                   $(a[2]).fadeTo('fast',0.5);
                },
                afterEnd: function(a){
                    for (var i=0; i < a.length; i++)
                    {
                        $(a[i]).fadeTo('fast',0.5);
                    }
                    var li = $(a[2]);
                    li.fadeTo('fast',1);
                    var content = $('#'+li.attr('rel'));
                    $('div[id^=timeline_]').each(function(){
                        $(this).addClass('hideme');
                    });
                    content.removeClass('hideme');
                },
                btnGo: btnGo_array
            });
        }
    }
    
    /* Activate Newsticker */
    if(document.getElementById('ticker'))
    {
        $('#ticker ul').liScroll();
    }
    
    /* Activate FAQ */
    if(document.getElementById('faq'))
    {
        // hide anwsers
        $('#faq dd').each(function(index)
        {
            if (index !== 0){
                $(this).hide();
            }
            else
            {
                $(this).addClass('open');
            }
        });
        
        // click handeler
        $('#faq > dt > a').live('click',function(e)
        {
            e.preventDefault();
            e.stopPropagation();
            var target = $($(this).attr('href'));
            if (target.hasClass('open')) 
            {
                target.slideUp().removeClass('open');
                return false;
            }
            $('#faq .open').slideUp().removeClass('open');
            target.slideDown();
            target.addClass('open');
        });
    }
    
    /* Activate Recept */
    if(document.getElementById('recept'))
    {
        // hide anwsers
        $('#recept dd').each(function(index)
        {
          $(this).hide();
        });
        
        // click handeler
        $('#recept > dt > a').live('click',function(e)
        {
            e.preventDefault();
            e.stopPropagation();
            var target = $($(this).attr('href'));
            if (target.hasClass('open')) 
            {
                target.slideUp().removeClass('open');
                return false;
            }
            $('#recept .open').slideUp().removeClass('open');
            target.slideDown();
            target.addClass('open');
        });
    }

    /* Hide all recept */
    if(document.getElementById('recept_content'))
    {
      // hide recepts
      $('#recept_content div').each(function(index)
      {
        $(this).hide();
      });
      
      // show first
      $('#recept_content div:first').show();        
      $('#recept_content div:first').addClass('show');
      $('#recept_titles a:first').addClass('active');
    }
    
    /* Recept change */
    if(document.getElementById('recept_titles'))
    {
      $('#recept_titles a').click(function() {
        recept=$(this).attr('rel');
        $('#recept_titles a').removeClass('active');
        $(this).addClass('active');
        if(document.getElementById('recept_content')) {
          if ( ! $('#recept_content div.'+recept).hasClass('show')) {          
            $('#recept_content div.show').fadeOut(300, function(){
              $(this).removeClass('show');
              $('#recept_content div.'+recept).addClass('show');
              $('#recept_content div.'+recept).fadeIn(300);   
            });
          }  
        }        
      });
              
    }

    /* Activate Accordion fuer Presse */
    if(document.getElementById('press_archive'))
    {
        // hide anwsers
        $('#press_archive ul.acc > li > div').each(function(index)
        {
            $(this).hide();
        });

        // click handeler
        $('#press_archive ul.acc > li > h4 > a').live('click',function(e)
        {
            e.preventDefault();
            e.stopPropagation();
            var target = $($(this).attr('href'));
            if (target.hasClass('open'))
            {
                target.slideUp().removeClass('open');
                return false;
            }
            $('#press_archive .open').slideUp().removeClass('open');
            target.slideDown();
            target.addClass('open');
        });
    }

});

