$(document).ready(function() {

    bootstrap();


    
    $('.dropdown a.grey_round_small').click(function(){
        $(this).toggleClass('dropdown_open');
        $(this).next('.dropdown_elements').slideToggle('fast');
        return false;
    });
});

function bootstrap() {
    $("div.scrollable").scrollable().navigator();

}

var $slider;

function initStart() {
    $('.start_buttons a').click(function(){
        $('.start_buttons a').removeClass('active');
        $(this).addClass('active');
        initStartElement($(this).attr('rel'));
    });
    initStartElement(0);
}

function initStartElement($ID) {

    window.clearTimeout($slider);


    $('#start_head_element').fadeOut('fast', function(){
        $('#start_head_element').load('/index/startelement/ID/' + $ID, function(){
            $('#start_head_element').delay(300).fadeIn('fast', function(){
                fadeStartSlide(1);
            });
        });
    });
    
}

function fadeStartSlide($next_slide) {

    var $slidetime = $('.start_bg_wrapper').attr('slidetime');
    var $slideduration = $('.start_bg_wrapper').attr('slideduration');;
    var $slidecount = $('.start_slide').length;

    $('.start_slide:nth-child('+$next_slide+')').fadeIn(parseInt($slideduration));
    
    if ( $slidecount > 1 ) {
        $('.start_slide:nth-child('+$next_slide+')').delay($slidetime - $slideduration).fadeOut(parseInt($slideduration));
    }

    if ($next_slide == $slidecount) {
        $next_slide = 1;
    } else {
        $next_slide++;
    }
    if ( $slidecount > 1 ) {
        $slider = setTimeout("fadeStartSlide("+$next_slide+")", $slidetime);
    }
    
}



