function initMenu(){
    $('#RovBuilder')
    .addClass('visible')
    .slideDown('slow')
    $('.script').each(function()
    {
        $(this)
        .click(function()
        {
            var href=$(this).attr('href');
            $('.visible')
            .removeClass('visible')
            .slideUp('slow', function()
            {
                $(href)
                .addClass('visible')
                .slideDown('slow')
            })
            return false;
        });
    });
}

function slideSwitch() {
    var active = $('#slideshow img.active');
    if ( active.length == 0 )
        active = $('#slideshow img:last');

    var next =  active.next().length ?
        active.next()
        : $('#slideshow img:first');

    active.animate({opacity: 0.0}, 1000, function() {
        active.removeClass("active");
        next
            .addClass('active')
            .animate({opacity: 1.0}, 1000)
            ;
        });
}

function initImageOpenInNewWindow() {
    $("a img").each( function() {
        var href=$(this).parent().attr('href');
        if (href != '') {
            $(this).click(
                function()
                {
                    var win = window.open(href,'');
                    return false;
                });
            }
        });
}

function initSubChapters() {
    $('.next_subchapter').each(function()
    {
        var link = $(this);
        
        link.click(function()
        {
            var href=link.attr('href');
            link.parent().slideUp('slow', function()
            {
                $(href).slideDown('slow')
            })
            return false;
        });
    });
}

function setLoop() {  
    setInterval( "slideSwitch()", 5000 );
}

$(document).ready(initMenu);
$(document).ready(slideSwitch);
$(document).ready(initSubChapters);
$(document).ready(initImageOpenInNewWindow);
$(setLoop);


