
Drupal.behaviors.usefulornot = function (context) {

	// hide label text
	$("#usefulornot-voting-form .radio_label").hide();
	
  $('input#edit-vote-1:radio').checkbox({cls:'jquery-yes-checkbox', empty: '/sites/all/themes/yf/images/spacer.gif'});
	$('input#edit-vote--1:radio').checkbox({cls:'jquery-no-checkbox', empty: '/sites/all/themes/yf/images/spacer.gif'});
  
  // hide everything except radio, as long as "no" isn't already selected
  // (meaning the form returned a validation error because no reason was given)
  
  var vote_value = $("input#edit-vote--1:checked").val();  
  
  if(vote_value == undefined){
    
    $("#usefulornot-voting-form #edit-reason-wrapper").hide();
    $("#usefulornot-voting-form #edit-mail-wrapper").hide();
    $("#usefulornot-voting-form input[type=submit]").hide();
    
  }
  
  $('input#edit-vote--1:radio').bind("check", function (){
  
    // show other parts of form if no is chosen
   
    $("#usefulornot-voting-form #edit-reason-wrapper").show();
    $("#usefulornot-voting-form #edit-mail-wrapper").show();
    $("#usefulornot-voting-form input[type=submit]").show();
   
  });
  
  $('input#edit-vote-1:radio').bind("check", function (){
     
    // auto submit if yes is chosen
    $(this).parents("form").submit();
     
  });
  
  
}; 