var backgroundInterval = self.setInterval("loadBackground()", 30000);

function resizeWindow()
{
    var height = $(window).height() - 450;
    $("div.wrapper div.contentBox").css("height", height + "px");
}

function loadBackground()
{
    var maxValue = $(".switch").length - 1;
    var currentId = $(".switch.active").index();
    var newId = currentId + 1;
    if (newId > maxValue) {
        newId = 0;
    }
    var background_image = "image-" + newId;
    $("body").attr("style", "background-image: url('/img/background/" + background_image + ".jpg');");
    $(".switch").removeClass("active");
    $(".switch:eq(" + newId + ")").addClass("active");
}

$(document).ready(function(){
    $(document).pngFix(); 
    resizeWindow();
	
    $(window).resize(function() {
    	resizeWindow();
    });
    
    $(".menuLogin").click(function () {
        $(this).toggleClass("active");
        $(".menuRegister").toggleClass("active");
        $("#login").css("display", "block");
        $("#register").css("display", "none");
    });
    
    $(".menuRegister").click(function () {
        $(this).toggleClass("active");
        $(".menuLogin").toggleClass("active");
        $("#login").css("display", "none");
        $("#register").css("display", "block");
    });
    
    $(".switch").click(function () {
        if (!$(this).hasClass("active")) {
            var background_image = "image-" + $(".switch").index(this);  
            $("body").attr("style", "background-image: url('/img/background/" + background_image + ".jpg');");
            $(".switch").removeClass("active");
            $(this).addClass("active");
            
            window.clearInterval(backgroundInterval);
            backgroundInterval = self.setInterval("loadBackground()", 30000);
        }
    });
    
    $("#bubble-GalaxyNews .logo").show().effect("bounce", { times: 2 }, 400, function () {
        $("#bubble-GalaxyNews .bubble").fadeIn("slow", function() {
            $("#bubble-ComputerBild .logo").show().effect("bounce", { times: 2 }, 400, function () {
                $("#bubble-ComputerBild .bubble").fadeIn("slow");
            });  
        });
    });
});
