var justListedPage = 1;
var maxJustListedPages = 4;

$(document).ready(function()
{
    // Clicked the "previous" arrow in "Just Listed".
    $("#just-listed-prev").click(function()
    {
        justListedPage = (justListedPage == 1 ? maxJustListedPages : justListedPage - 1);
        showJustListedPage();
    });

    // Clicked the "next" arrow in "Just Listed".
    $("#just-listed-next").click(function()
    {
        justListedPage = (justListedPage == maxJustListedPages ? 1 : justListedPage + 1);
        showJustListedPage();
    });

    // Show sub-categories when hovering a category menu.
    $("#side-categories li").hover(
        function()
        {
            var id = $('a', this).attr('href').match('([0-9]+)$')[0];

            var html = '<ul id="side-categories-hover">';

            // Make the sub-menu's HTML from sub-categories (see bottom of 'home' template).
            for (var i = 0; i < levelTwoCategories[id].length; i++)
            {
                html += '<li class="sprite"><a href="http://search.zibbet.com/search?c1=' + id
                            + '&amp;c2=' + levelTwoCategories[id][i][0] + '">'
                            + levelTwoCategories[id][i][1] + '</a></li>';
            }

            html += '</ul>';

            $(this).append(html);
        },
        function()
        {
            $('#side-categories-hover').remove();
        });
});

function showJustListedPage()
{
    var jlp = $("#just-listed-page");
    jlp.animate({opacity: 0}, 300, "linear", function()
    {
        $.get("/intl/ajax/home-just-listed-page", {page: justListedPage}, function(data)
        {
            jlp.html(data).animate({opacity: 1}, 300);
        });
    });
}

