﻿/// <reference path="jquery-1.2.6.js" />
/// <reference path="core.js" />

Forums.Categories =
{
    decorateCategory: function()
    {
        $(this).addClass("expcol");
        $(this).children("h2").prepend(Forums.Constants.ExpandCollapseLink);

        var cat = $(this);
        $(cat).addClass("expanded");
        $(this).children("h2").mouseover(function()
        {
            $(cat).addClass("hover");
        });

        $(this).children("h2").mouseout(function()
        {
            $(cat).removeClass("hover");
        });

        $(this).children("h2").click(function(evt)
        {
            if (evt.target.nodeName.toLowerCase() === "a")
            {
                if (evt.target.className !== "expcol")
                {
                    return;
                }
            }

            $(cat).toggleClass("expanded");
            $(cat).children("ul").slideToggle("fast");
        });
    },

    decorateExpColAll: function()
    {
        $(this).show();

        $("a[name='expall']", this).click(function()
        {
            $("li.category > ul").show()
            $("li.category").addClass("expanded");
        });

        $("a[name='colall']", this).click(function()
        {
            $("li.category > ul").hide()
            $("li.category").removeClass("expanded");
        });
    },

    loaded: function()
    {
        $("div.leaderboards", this).each(Forums.Leaderboards.init);
    }
}

$(function()
{
    $.addToRail(railItems, Forums.Categories.loaded)
    $("li.category").each(Forums.Categories.decorateCategory);
    $("div.expcol").each(Forums.Categories.decorateExpColAll);
    $("a.popup").popup();
});

