﻿$(document).ready(function () {

    $("#container").css({ 'min-height': $(window).height() + "px" });

    $(".frontpage #rotatorMenuLine .rleft a, .frontpage #rotatorMenuLine .rright a").click(function () {
        $(this).attr("href", $(".frontpage .rotatorElement:visible").find("a").attr("href"));
    });

    /* Image slider (references) */
    if ($(".imageslider").size() > 0 && $(".imageslider").slideMe) {
        $(".imageslider").slideMe("#prev", "#next", 5, 3, function () {
            $("h1").html("<a href=\"" + $(".imageslider .selected a").attr("href") + "\">" + $(".imageslider .selected a").text() + "</a>");
            $(".topImage").html($(".imageslider .selected .image").clone().hide().fadeIn(1000));
        });

        var autoSlide = setInterval(function () {
            $("#next").click();
        }, 7000);

        $("#next, #prev").one('mouseup', function () {
            clearInterval(autoSlide);
        });
        $(document).keydown(function (e) {
            clearInterval(autoSlide);
            if (e.which == 37 || e.which == 40) $('#prev').click();
            else if (e.which == 38 || e.which == 39) $('#next').click();
        });
    }

    // effect mouseover meny l1 links
    $("header .l1 li").each(function (n, styled) {
        var isSelected = $(styled).find(".selected,.selectedwithchildren").size() > 0;
        $(styled).css({ position: "relative" });
        $(styled).append($("<span class=\"line\" />").css({
            position: "absolute",
            'background-color': "#fff",
            height: (isSelected ? 5 : 0) + "px",
            width: $(styled).width() + "px",
            bottom: $(styled).height() + "px",
            left: 0,
            right: 0
        })).hover(function () {
            if (isSelected) return;
            $(this).find(".line").animate({ height: '5px' }, 150);
        }, function () {
            if (isSelected) return;
            $(this).find(".line").animate({ height: 0 }, 150);
        });
    });
    // effect mouseover meny l2 links
    $("header .l2 li").each(function (n, styled) {
        var isSelected = $(styled).find(".selected,.selectedwithchildren").size() > 0;
        $(styled).css({ position: "relative" });
        $(styled).append($("<span class=\"line\" />").css({
            position: "absolute",
            'background-color': "#fff",
            height: (isSelected ? 5 : 0) + "px",
            width: $(styled).width() + "px",
            top: $(styled).height() + "px",
            left: 0,
            right: 0
        })).hover(function () {
            if (isSelected) return;
            $(this).find(".line").animate({ height: '5px' }, 150);
        }, function () {
            if (isSelected) return;
            $(this).find(".line").animate({ height: 0 }, 150);
        });
    });

    // border effect on links
    $(".content a").each(function (n, styled) {
        if ($(styled).find("img").size() > 0) return;
        $(styled).css({ position: "relative" });
        $(styled).append($("<span class=\"line\" />").css({
            position: "absolute",
            'background-color': "#cc0000",
            height: '1px',
            width: 0,
            bottom: 0,
            left: 0
        })).hover(function () {
            $(this).find(".line").animate({ width: $(this).width() + 'px' }, 200);
        }, function () {
            $(this).find(".line").animate({ width: 0 }, 100);
        });
    });

    // border effect on coworkers list
    $(".contentfooter li").each(function (n, styled) {
        $(styled).css({ position: "relative" });
        $(styled).append($("<span class=\"line\" />").css({
            position: "absolute",
            'background-color': "#cc0000",
            height: '1px',
            width: ($(styled).find(".selected").size() > 0 ? $(styled).width() + 'px' : 0),
            bottom: 0,
            left: 0
        })).hover(function () {
            if ($(styled).find(".selected").size() > 0) return;
            $(this).find(".line").animate({ width: $(this).width() + 'px' }, 200);
        }, function () {
            if ($(styled).find(".selected").size() > 0) return;
            $(this).find(".line").animate({ width: 0 }, 100);
        });
    });
});
