(function(){
$.appreciateButton=function(options){
if(!'url' in options || !'holder' in options){
return false}
var element=$(options.holder)
var currentURL=window.location.protocol+'//'+window.location.host+window.location.pathname
$.get(options.url,{url:currentURL,rand:Math.random()},function(response){
var button=$('<a>',{href:'',className:'appreciateBadge',html:'Appreciate Me'})
if(!response.voted){
button.addClass('active')}
else button.addClass('inactive')
button.click(function(){
if(button.hasClass('active')){
button.removeClass('active').addClass('inactive')
if(options.count){
$(options.count).html(1+parseInt(response.appreciated))}
$.getJSON(options.url,{url:currentURL,submit:1})}
return false
})
element.append(button)
if(options.count){
$(options.count).html(response.appreciated)}
},'json')
return element}
})(jQuery)
