/**
 * Provides binding for the AJAX voting form (for example vote/result-and-voting-form.jsp)
 *
 * @author Jens Askengren
 */


jQuery(document).ready(function(){
	
	// We don't use the cancel option for this rating.
	jQuery(".rater .cancel").hide();
	
	jQuery(".rater .star").click(function(){		

		var rater = jQuery(this).closest('.rater');
		if (rater.attr('hasvoted') != undefined)
		{
			return false;
		}
		
		rater.attr('hasvoted', true);
						
		// Disable the rater after clicked
		rater.find('.star').unbind('hover');		
		rater.find('.star a').unbind('click');
		
		// Submit rating
		jQuery('#thank_you').show();
		rater.find('form').hide();
		
		rater.find('form').ajaxSubmit({ 
	        target:        '#xcapRating',   // target element(s) to be updated with server response 
	        success : function (responseText, textStatus) {
			var html = "<div id='voteConfirmation'><p>" + xcap.getText("general", "thank_you_for_voting") + "</p></div>";
				jQuery("#ratingBox").append(html);
				$('input[type=radio].star').rating();
			}
	    }); 
		return true;
	});

	// Like
	jQuery("#addLike").submit(function(){		
		jQuery("#addLike").ajaxSubmit({ 
	        target:        '#xcapRating'
		});
		return false;
	});
});


