$(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: 6
            });
        }

    } else if(document.getElementById('spargel_slider'))
    {
        $('#spargel_slider .carusel').jCarouselLite({
            btnNext: '.next',
            btnPrev: '.prev',
            visible: 4
        });
    }
    
    /* 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 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');
        });
    }

});

