var PostRating =
{
    ratedIconSrc: "http://static.ezermester.hu/images/forum/icons/thumb_up.png",
    unratedIconSrc: "http://static.ezermester.hu/images/forum/icons/thumb_up_gray.png",
    getImageId: function(post_id)
    {
        return "#postRating" + post_id;
    },
    toggle: function(post_id)
    {
        var imgId = this.getImageId(post_id);
        if($(imgId).hasClass('rated'))
        {
            $(imgId).removeClass('rated');
            $(imgId).attr('src', this.unratedIconSrc);
            $(imgId).attr('title', 'Kedvencnek jelölöm');
        }
        else
        {
            $(imgId).addClass("rated");
            $(imgId).attr('src', this.ratedIconSrc);
            $(imgId).attr('title', 'Kijelölés megszüntetése');
        }
        $.get("ajax.php",
        {act: "togglePostRating", post_id: post_id},
            //handler for create Article_post
            // autogenerated, remove this if edited
            function(response, textStatus)
            {
                if(ResponseMan.isSuccessful(response, textStatus))
                {
                    if(response.highestRankedPostAfter==null)
                    {
                        $('.highestRanked').html("");
                        return;
                    }
                    
                    if(response.highestRankedPostBefore==null || response.highestRankedPostBefore.id != response.highestRankedPostAfter.id)
                    {
                        $('.highestRanked').html("");
                        $('#postHighestRanked'+response.highestRankedPostAfter.id).html("<img alt='' src='http://static.ezermester.hu/images/forum/icons/highestranked.png' title='Legnépszerűbb hozzászólás' />");
                    }                    
                }
            },
            "json");
    },
    mouseover: function(post_id)
    {
        var imgId = this.getImageId(post_id);
        if($(imgId).hasClass('rated'))
        {
            $(imgId).attr('src', this.unratedIconSrc);
        }
        else $(imgId).attr('src', this.ratedIconSrc);
    },
    mouseout: function(post_id)
    {
        var imgId = this.getImageId(post_id);
        if($(imgId).hasClass('rated'))
        {
            $(imgId).attr('src', this.ratedIconSrc);
        }
        else $(imgId).attr('src', this.unratedIconSrc);
    }
}
