﻿//Define Kpw object only if it's not already defined
if ("undefined" == typeof Kpw) {
    Kpw = {};
}

//Define Kpw.Cms object only if it's not already defined
if ("undefined" == typeof Kpw.Cms) {
    Kpw.Cms = {};
}

if ("undefined" == typeof Kpw.Cms.Blog) {
    Kpw.Cms.Blog = {};
}


Kpw.Cms.Blog.MonthlyControl = {
    init: function() {
        $(".monthLink").bind("click", Kpw.Cms.Blog.MonthlyControl.GetMonthlyTitles);
        $("ul.colorTags li.headlink a").bind("click", Kpw.Cms.Blog.MonthlyControl.ShowColorTags);

    },
    HideMonthlyTitles: function() {
        $("ul.monthlyPosts", $(this).parent()).addClass("hide");
        $(this).parent().removeClass("open");
        $(".monthLink").bind("click", Kpw.Cms.Blog.MonthlyControl.GetMonthlyTitles);
    },
    GetMonthlyTitles: function() {

        //if we have titles, just show em.
        if ($("ul.monthlyPosts", $(this).parent()).length > 0) {
            $("ul.monthlyPosts", $(this).parent()).removeClass("hide");
        }
        else {
            //get titles for first time.
            var bOwnerId = $('ul.archives input.blogOwnerId').val();
            var html = $.ajax({
                url: $("input.handlersPath").attr("value") + "GetMonthlyBlogTitles.ashx",
                async: false,
                data: ({ id: $(this)[0].id, ownerId: bOwnerId })
            }).responseText;

            $(this).parent().append(html);
        }

        $(this).unbind("click");
        $(this).bind("click", Kpw.Cms.Blog.MonthlyControl.HideMonthlyTitles);
        $(this).parent().addClass("open");

    },
    ShowColorTags: function() {

        $("ul.colorTags li.headlink ul").removeClass("hide");

        $(this).unbind("click");
        $(this).bind("click", Kpw.Cms.Blog.MonthlyControl.HideColorTags);
        $(this).parent().addClass("open");

    },
    HideColorTags: function() {
        $("ul.colorTags li.headlink ul").addClass("hide");
        $(this).parent().removeClass("open");
        $("ul.colorTags li.headlink a").bind("click", Kpw.Cms.Blog.MonthlyControl.ShowColorTags);
    }
}

