$().ready(function(){
    $("#newComment").submit(function(){
        var params = $(this).serialize();
        $.ajax({
            type: "POST",
            url: $(this).attr("action") + "?ajax=true",
            data: params,
            success: function(msg){
                if ( msg.match(/contentModal/) ){
                    $("#dialog").html(msg);
                    $("#dialog").jqmShow();
                } else {
                    $("#comments").prepend(msg);
                    $("#commentCount").html( parseInt($("#commentCount").html()) + 1 );
                    $("#commentTextArea").val("");
                }
            }
        });
        return false;
    });
    $("#setFavorite").click(function(){
        var obj = $("#setFavorite");
        var href = obj.attr("href");
        if (href != "#"){
            $.ajax({
                type: "GET",
                url: href + "?ajax=true",
                beforeSend: function(){
                    obj.attr("href", "#");
                },
                success: function(msg){
                    if ( msg == "1"){
                        obj.hide();
                        $("#favoriteSet").show();
                    }
                    obj.attr("href", href);
                }
            });
        }
        return false;
    });
    $("#setFavoriteUser").click(function(){
        var obj = $("#setFavoriteUser");
        var href = obj.attr("href");
        if (href != "#"){
            $.ajax({
                type: "GET",
                url: href + "?ajax=true",
                beforeSend: function(){
                    obj.attr("href", "#");
                },
                success: function(msg){
                    if ( msg == "1"){
                        obj.hide();
                        $("#favoriteUserSet").show();
                    }
                    obj.attr("href", href);
                }
            });
        }
        return false;
    });
    $("#notAppropriate").click(function(){
        var obj = $("#notAppropriate");
        var href = obj.attr("href");
        if (href != "#"){
            $.ajax({
                type: "GET",
                url: href + "?ajax=true",
                beforeSend: function(){
                    obj.attr("href", "#");
                },
                success: function(msg){
                    if ( msg == "1"){
                        obj.hide();
                        $("#notAppropriateSet").show();
                    }
                    obj.attr("href", href);
                }
            });
        }
        return false;
    });
    $('.tip').tipsy({gravity: 's'});
});
