
function badge(options) {
	
	if(!'url' in options || !'holder' in options) return false;
	var qString = options.qstring;
	var element = $(options.holder);
	var currentURL = window.location.protocol+'//'+window.location.host+window.location.pathname;
	if(options.qstring) {
	 currentURL += '?' + options.qstring;	
	}
	
	$.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;
			
		});

		if(options.count) {
			$(options.count).html(response.appreciated);
		}
		element.append(button);
	
	});
		
}

