/* Author:

*/


jQuery(function ($) {

    /*
    Replace path by hash
    */
    if (location.hash.indexOf("#/") == 0)
        location.href = location.hash.substr(1);


    /*
    Main nav hover fade
    */
    if ($.browser.msie && $.browser.version == "6.0") {

    } else {
        $('#globalMainNav ul li a:not(.selected)').hover(function () {
            $(this).stop().animate({ 'backgroundColor': '#cfdd8a' });
        }, function () {
            $(this).stop().animate({ 'backgroundColor': '#fff' }, 200);
        });
    }

    /*
    Sub nav hover fade
    */
    if ($.browser.msie && $.browser.version == "6.0") {

    } else {
        $('#globalSubNav li:not(.on) a').hover(function () {
            $(this).stop().animate({ 'backgroundColor': '#cfdd8a' });
        }, function () {
            $(this).stop().animate({ 'backgroundColor': '#e4e4e4' }, 200);
        });
    }

    /*
    Föreläsare slideshow
    */

    $("#startForelasare .slideshow").cycle({
        fx: 'fade',
        timeout: 5000,
        speed: 2000
    });
    $("#startForelasare .arrow-left").click(function () { $("#startForelasare .slideshow").cycle("prev"); $("#startForelasare .slideshow").cycle("pause"); });
    $("#startForelasare .arrow-right").click(function () { $("#startForelasare .slideshow").cycle("next"); $("#startForelasare .slideshow").cycle("pause"); });

    /*
    Föreläsare links
    */

    $(".peopleblobs a").click(function () {
        location.href = location.pathname + "#" + $(this).attr("href");
        var linkID = $(this).attr("class").substr(4);
        $(".forelasare-content:not(#forelasareContent_" + linkID + ")").fadeOut("fast", function () {
            $("#forelasareContent_" + linkID).fadeIn("fast");
            $("html,body").animate({ scrollTop: $("#scrollbar1").offset().top }, 100);
        });
        return false;
    });

    $(".forelasare-content").first().fadeIn("slow");

    if (location.pathname != "/vara-forelasare" && location.pathname.indexOf("/vara-forelasare") == 0)
        $("html,body").animate({ scrollTop: $("#scrollbar1").offset().top }, 100);

    var h = 0;
    $(".list-content-wrapper").children().each(function () {
        if ($(this).outerHeight() > h) {
            h = $(this).outerHeight();
        }
    });
    $(".list-content-wrapper").css("height", h + "px");

    /*
    Referenser links
    */

    $(".referenceblobs a").click(function () {
        location.href = location.pathname + "#" + $(this).attr("href");
        var linkID = $(this).attr("class").substr(4);
        var link = $(".referenser-content:not(#referenserContent_" + linkID + ")");
        link.fadeOut("slow", function () {
            $("#referenserContent_" + linkID).fadeIn("slow");
            $("html,body").animate({ scrollTop: $("#scrollbar1").offset().top }, 100);
        });
        return false;
    });

    $(".referenceblobs a .image").hover(function () {
        $(this).stop().animate({ border: 'solid 6px #a5c120' });
    }, function () {
        $(this).stop().animate({ border: 'solid 6px transparent' });
    });

    $(".referenser-content").first().fadeIn("slow");

    if (location.pathname != "/referenser" && location.pathname.indexOf("/referenser") == 0)
        $("html,body").animate({ scrollTop: $("#scrollbar1").offset().top }, 100);

    /*
        Set wrapper height for animated lists
    */
    var h = 0;
    $(".list-content-wrapper").children().each(function () {
        if ($(this).outerHeight() > h) {
            h = $(this).outerHeight();
        }
    });
    $(".list-content-wrapper").css("height", h + "px");

});
