(function($) {  
$.fn.vote = function(settings) { 
	options = {
		url:'',
		spinner:'<img src="http://vm-dev-web/web/ws/tropjouer/public/images/spinner.gif"/>'
	};
	var options = $.extend(options, settings);

    return this.each(function(){
    	var voteFct = function(type) {
       		// show the spinner
       		$$.html(options.spinner);
        		
       		//the main ajax request
    		$.ajax({
     				type: "POST",
       				data: "type="+type+"&id="+id,
       				url: options.url,
       				success: function(msg)
       				{
       					$$.hide();
       					$$.html(msg);
       					$$.fadeIn();
       				}
       			});
        		return false
        };	
        
    	var $$ = $(this);
    	var voteUp = $$.find('.vote_up');
    	var voteDown = $$.find('.vote_down');
    	var id = $$.attr('id');
    	
    	voteUp.click(function(){
    		voteFct('up');    	
    	});
    	
    	voteDown.click(function(){
    		voteFct('down');    	
    	});
    });
};	
})(jQuery); 