
var RecaptchaOptions = {
		theme: 'clean'
		};


var JSON = JSON || {}; 

	JSON.parse = JSON.parse || function (str) { 
		    if (str === "") str = '""'; 
		    eval("var p=" + str + ";"); 
		    return p; 
		}; 

		
function addScore(id){
		
 	id = parseInt(id);
 	
 	$.ajax({
 	  type: "POST",
 	  url: '/ajax.php',
 	  data: "bubble="+bubbleId+"&score="+id,
 	  success: function(data) {
 	
 		response = JSON.parse(data);
 		if(!response.error){
     		$('.status').hide();
     		$('#rate').prepend(response.html);
     		$('#rateCount').text(parseInt($('#rateCount').text())+1);
     		if(response.averageRating > 0 ){
	        		$('#starAverage').css('width', response.averageRating+'%');
     		}
 		}
 	  }
 	});
 	
 }
	
 
 
 function addComment(){
 	
 	$.ajax({
     	type: "POST",
     	url: '/ajax.php',
     	data: $('#comment_form').serialize()+"&bubble="+bubbleId,
     	success: function(data) {
 		
 		  response = JSON.parse(data);
				if(!response.error){
					$('#recaptchaError').hide();
					$('#commentError').hide();
					$('#noComment').hide();
					$('#addCommentContainer').hide();
					$('html, body').animate({scrollTop:0});
					$('#commentContainer').prepend(response.html);
					$('#commentCount').text(parseInt($('#commentCount').text())+1);
				}else{
					if(response.recaptcha){
						$('#recaptchaError').hide();
						$('#recaptchaError').fadeIn();
					}
				}
 	  }
 	});
 	
 }

 function showExtraComments(el){
		$(el).hide();
		$('#extraComments').show();
 }
 
 $(document).ready(function() {

	 $('#comment_form').submit(function() {

			if($('#mce-NAME').val()==''){
				$('#mce-NAME').val('Anonymous');
			}

			$('#commentError').hide();
			if($('#mce-MESSAGE').val()==''){
				$('#commentError').fadeIn();	
	       	}else{
	    	   addComment();
		  	}

			return false;
     });
 });
