﻿$(function() {
    $("#username").watermark("Användarnamn", "#82c0d1");
    $("#password-text").focus(function() {
        $(this).hide();
        $("#password").show().get(0).focus();
    });
    $("#password").hide().blur(function() {
        if ($(this).val().length == 0) {
            $(this).hide();
            $("#password-text").show();
        }
    }).keypress(function(e) {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;
        if (keycode == 13) {
            e.target.form.submit();
            return false;
        } else {
            return true;
        }
    });

    $("#login-control .signup a").popup();
    $(".large, .small").children().click(function() {
        var href = $(this).parents(".large, .small").children("h3").children("a").attr("href");
        location = href;
        return false;
    });
    $(".blurb").click(function() {
        var href = $("h3 a", this).attr("href");
        location = href;
    });
});

$(function() {
    if ($(".promotion").length == 0) return;

    var activeImage = 1;
    var promotionIndex = 1;
    var promotions = $(".promotion ul li");

    setInterval(function() {
        if (promotionIndex == promotions.length) {
            promotionIndex = 0;
        }

        if (activeImage == 1) {
            $(".promotion .image2")
                .css("background-image", 
                     "url('" + $(promotions.get(promotionIndex)).text() + "')");
            $(".promotion .image1").fadeOut(2000);
            activeImage = 2;
        } else if (activeImage == 2) {
            $(".promotion .image1")
                .css("background-image",
                     "url('" + $(promotions.get(promotionIndex)).text() + "')")
                .fadeIn(2000);
            activeImage = 1;
        }

        promotionIndex++;
    }, 5000);
    setTimeout(function() {
        $(".home-index .main .promotion p").fadeOut("slow");
    }, 10000);
});
