﻿$(document).ready(function () {
    $('#spotlight-scrollable').tinyscrollbar();

    var scrolllock = false; //wheel fix
    $("#spotlight-scrollable").hover(
                function () {
                    scrolllock = true;
                    $("#spotlight-scrollable .scrollbar").fadeIn("fast");
                },
                function () {
                    scrolllock = false;
                }
            );
    $("body").not("spotlight-scrollable").mousemove(
        function () {
            if (!scrolllock && $("#spotlight-scrollable .scrollbar").css("display") != "none") {
                $("#spotlight-scrollable .scrollbar").fadeOut("fast");
            }
        }
    );

    var spotlightlock = true;
    $("table.chrome-main tbody li a").hoverIntent({
        interval: 300,
        over: function () {
            spotlightlock = false;
            var i = ((($(this).parent().parent().parent().index()) / 2) * 10) + $(this).parent().index() + 1;
            $("#spotlight table").fadeOut("fast");
            setTimeout(function () {
                $("#spotlight .title").html(spotlightArray[i][0]);
                $("#spotlight img").attr("src", spotlightArray[i][1]);
                $("#spotlight .overview").html(spotlightArray[i][2]);
                setTimeout(function () { $("#spotlight table").fadeIn("fast"); }, 150);
            }, 200);
        },
        out: function () { /*Do nothing*/ }
    });
    $("table.chrome-main").mouseleave(
        function () {
            if (!spotlightlock) {
                $("#spotlight table").fadeOut("fast");
                setTimeout(function () {
                    $("#spotlight .title").html(spotlightArray[0][0]);
                    $("#spotlight img").attr("src", spotlightArray[0][1]);
                    $("#spotlight .overview").html(spotlightArray[0][2]);
                    setTimeout(function () { $("#spotlight table").fadeIn("fast"); }, 150);
                }, 200);
                spotlightlock = true;
            }
        }
    );

    $.ajax({
        url: '/scripts/ajax/twitter/',
        success: function (data) {
            $("#tweet-data").html(data);
            var i = 0;
            $("#tweet-data li").each(function () {
                if (i > 4) $(this).remove();
                i++;
            });
            $("#tweet-data a").attr("target", "_blank");
            $("#twitter-data").fadeIn();
        }
    });

    $("#updates table tr td a").each(function () {
        var t = $(this).html();
        $(this).html("");
        var i = 1;
        while ($(this).height() < 20 && i < t.length) {
            $(this).html(t.substr(0, i) + "...");
            i++;
        }
        if ($(this).height() < 20) $(this).html(t);
        else { i = i - 2; $(this).html(t.substr(0, i) + "..."); }
    });
});
