/*
 * Glig standard widgets
 *
 * Copyright (c) 2010, glig.com All Rights Reserved
 */

var glig    = (glig ? glig : function() {});
glig.ui     = (glig.ui ? glig.ui : function() {});

$(document).ready(function()
{
    glig.ui.activate_help_panels();

    glig.ui.activate_delete_links();
});

glig.ui.activate_help_panels = function()
{
    $(".help_button").hover(
        function()
        {
            glig.ui.show_help_panel(this.id);
        });
}

glig.ui.show_help_panel = function(id)
{
    var text = help_texts[id];

    str = "<div class='help_panel ui-corner-all' id=" + id + "_help_panel>";
    str += text;
    str += "</div>";

    $(document.body).append(str);

    var offset = $("#" + id).offset();

    $("#" + id + "_help_panel")
        .hide().fadeIn(200)
        .css
        ({
            "top": (offset.top - 8) + "px",
            "left": (offset.left - 8) + "px"
        })
        .mouseleave(function()
        {
            $(".help_panel")
                .fadeOut(200, function() { $(this).remove(); });
        });
}

glig.ui.activate_delete_links = function()
{
    $(".delete_comment").click(function(event)
    {
        event.preventDefault();

        var c = confirm("Are you sure you want to delete this comment?");

        if(c)
        {
            $(this).html("deleting...").css("color", "black");

            var commentID = this.id.substr(1);

            $.post(
                "/ajax/forum?mode=delete",
                { "action": "delete", commentID: commentID },
                function(data, textStatus)
                {
                    if(textStatus == "success")
                        window.location.reload();
                });
        }
    });
}
