$(document).ready(function ()
{
    $('div.rating.unrated input[type="image"]').hover(
        function ()
        {
            $(this).attr('src', '/styles/icon-bulb-on.gif');
        },
        function ()
        {
            $(this).attr('src', '/styles/icon-bulb-off.gif');
        });
    $('div.rating.unrated form ').submit(
        function (e)
        {
            e.preventDefault();
            // immediate feedback
            $('div.rating.unrated').removeClass('unrated').addClass('rated').html('<p>This story inspired you.</p>');
            var total = $('div.info div.byline div.rating p');
            if (total.length)
            {
                var cur_total = parseInt($('span', total).html());
                $('span', total).html(cur_total+1);
            }
            else
            {
                $('div.info div.byline').append('<div class="rating"><p><span>1</span> person inspired</p></div>');
            }
            $.ajax({
                type: "POST",
                url: $(this).attr("action"),
                data: 'vote=1',
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.approve').submit(
        function (e)
        {
            e.preventDefault();
            // immediate feedback
            $(this).remove();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                data: 'is_approved=1',
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.report').submit(
        function (e)
        {
            e.preventDefault();
            // immediate feedback
            $(this).replaceWith('<div class="reported">Reported for abuse</div>');
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                data: 'report=1',
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.whitelist-comment').submit(
        function (e)
        {
            e.preventDefault();
            // immediate feedback
            $(this).parents('li').slice(0,1).fadeOut();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                data: 'is_approved=1',
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.delete-comment').submit(
        function (e)
        {
            e.preventDefault();
            if (!confirm('Are you sure you want to delete this comment?'))
            {
                return;
            }
            // immediate feedback
            $(this).parents('li').slice(0,1).fadeOut();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.delete-featured-moment').submit(
        function (e)
        {
            e.preventDefault();
            if (!confirm('Are you sure you want to delete this moment?'))
            {
                return;
            }
            // immediate feedback
            $(this).parents('div.result').slice(0,1).fadeOut();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.delete-moment').submit(
        function (e)
        {
            e.preventDefault();
            if (!confirm('Are you sure you want to delete this moment?'))
            {
                return;
            }
            // immediate feedback
            $(this).parents('li').slice(0,1).fadeOut();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
    $('form.delete-hero').submit(
        function (e)
        {
            e.preventDefault();
            if (!confirm('Are you sure you want to delete this hero?'))
            {
                return;
            }
            // immediate feedback
            $(this).parents('li').slice(0,1).fadeOut();
            $.ajax({
                type: "POST",
                url: $(this).attr('action'),
                success: function(data)
                    {
                    },
                error: function(xhr, status, error)
                    {
                    }
            });
        });
});