﻿registerNS("Tegud.Blog");

Tegud.Blog.Init = function () {
    $("#BlogContainer")
        .delegate(".BlogLocationInformationMarker", "click", function () {
            Tegud.Mapping.Show($(this));
        })
        .delegate(".BlogCommentIcon", "click", function () { Tegud.Comments.Show($(this).closest(".BlogItemFooter").next()); })
        .delegate(".RetryComments", "click", function () { Tegud.Comments.Load($(this).closest(".BlogComments")); })
        .delegate(".BlogCommentsClose", "click", function () { Tegud.Comments.Hide($(this).closest(".BlogComments")); })
        .delegate(".BlogCommentCatchpaCodeRefresh", "click", function () { Tegud.Comments.GetNewAuthToken($(this).closest(".BlogCommentCatchpaHolder")); })
        .delegate(".BlogCommentAdd_AddComment", "click", function () { Tegud.Comments.AddNew($(this).closest(".AddComment")); });


    $(".ExpandableHeader:not(.MonthHeader)", "#BlogArchive")
            .mouseover(function () {
                $(this).children(".ExpanderToggle").addClass("Hover");
            })
            .mouseout(function () {
                $(this).children(".ExpanderToggle").removeClass("Hover");
            })
            .click(function () {
                if ($(this).hasClass("Expanded")) {
                    $(this).removeClass("Expanded");
                    $(this).parent().children(".ExpandableSubItems").slideUp(500);
                }
                else {
                    $(this).addClass("Expanded");
                    $(this).parent().children(".ExpandableSubItems").slideDown(500);
                }
            });

    $(".MonthHeader", "#BlogArchive").click(function () {
        $(document).attr("location",
                "/" + $(this).closest(".YearHeader").children(".ExpandableHeader").children(".ExpanderLabel").text() + "/"
                + Tegud.Utilities.GetMonthNumber($(this).children(".ExpanderLabel").children(".MonthName").text()));
    });

    $(".TagCloudItem").live("click", function () {
        Tegud.Blog.GoToTag($(this).text());
    });

    $(".BlogTag").live("click", function () {
        Tegud.Blog.GoToTag($(this).children(".BlogTagLabel").text());
    });
}
Tegud.Blog.GoToTag = function (tag) {
    $(document).attr("location", "/Tags/" + tag.replace("#", "%23"));
}

