$(function() {
    // -------------- MENU functions ----------------
    // ----- active nav underline -----
    $(".navigation").click(function()
    {
        $(".navigation").css("text-decoration", "none");
        $(this).css("text-decoration", "underline");
    });

    $('select[name="language"]').hide();
    var $select = $('select[name="language"] option').html();
    $('#language').hide().before("<a id='set_lang' href=''>" + $select + "</a>");
    $('#set_lang').click(function()
    {
        $('#i18n').submit();
        return false;
    });

    // ----------------- TECH functions -------------
    // ----- show #django -----
    $("#django_link").click(function()
    {
        $(".tech_content").fadeOut(75);
        $("#django").delay(75).fadeIn(200);
        return false;
    });

    // ----- show #php -----
    $("#php_link").click(function()
    {
        $(".tech_content").fadeOut(75);
        $("#php").delay(75).fadeIn(200);
        return false;
    });


    // ----- active tech underline -----
    $(".tech_link").click(function()
    {
        $(".tech_link").css("text-decoration", "none");
        $(this).css("text-decoration", "underline");
    });


    // ----------------- REFERENCES functions -------------
    // ----- show #tieto -----
    $("#tieto_logo").click(function()
    {
        $(".ref_content").fadeOut(75);
        $("#tieto").delay(75).fadeIn(200);
        return false;
    });

    // ----- show #aklinikka -----
    $("#aklinikka_logo").click(function()
    {
        $(".ref_content").fadeOut(75);
        $("#aklinikka").delay(75).fadeIn(200);
        return false;
    });

    // ----- active ref border -----
    $(".ref_logo").click(function()
    {
        $(".ref_logo").css("border", "none");
        $(".ref_logo").css("background-position", "0");
        $(".ref_logo").removeClass("selected");
        $(this).css("border", "solid 3px #FFCC33");
        $(this).css("background-position", "-" + $(this).width() + "px 0");
        $(this).addClass("selected");
    });

    $(".ref_logo").hover(
        function() {
            $(this).css("background-position", "-" + $(this).width() + "px 0");
        },
        function() {
            if (!$(this).hasClass("selected")) {
                $(this).css("background-position", "0");
            }
        }
    );


    // ------------------ BLOG functions -------------------
    // ----- show #comment -----
    $("#open_comments").click(function()
    {
        $("#open_comments").hide(0);
        $("#close_comments").delay(0).show(0);
        $("#comment").delay(0).fadeIn(200);
        return false;
    });

    // ----- hide #comment -----
    $("#close_comments").click(function()
    {
        $("#close_comments").hide(0);
        $("#comment").fadeOut(75);
        $("#open_comments").delay(0).show(0);
        return false;
    });


    // ----------- slideshows ---------------
    $('#slideshow_django').cycle({timeout: 5000});
    $('#slideshow_php').cycle({timeout: 5000});
    $('#slideshow_tieto').cycle({timeout: 5000});
    $('#slideshow_aklinikka').cycle({timeout: 5000});
    $('#slideshow_blog').cycle({timeout: 5000});

});

