$(document).ready(function() {

  // check to see if they've voted, hide buttons if they have
  if ($.cookie('voted') == 'true') {
    // $('.poll-vote').hide();
    // $('.poll-submit').append('<em>You have already voted</em>');
  }

  $('.poll-vote').bind("click", function() {
  
    // get the node id
    var nid = this.id.replace('vote-', '');
    
    // hide the button
    $('.poll-vote').hide();
    //$('#poll-submit-'+nid).attr('clear', 'left');
    thanks = ($('#thankyou-message').attr('value'));
    //$('#poll-submit-'+nid).fadeIn('slow').append('<div class="poll-thanks">'+thanks+'</div>');
    $('#poll-submit-'+nid).parent().fadeIn('slow').append('<div class="poll-thanks">'+thanks+'</div>');
    
    
    // get the current values
    var barwidth = parseFloat($('#poll-votes-'+nid).attr('width'))+2;
    $('#poll-votes-'+nid).attr('width', barwidth);
    barwidth = parseFloat($('#poll-remainder-'+nid).attr('width'))-2;
    $('#poll-remainder-'+nid).attr('width', barwidth);    
    
    var other = ($('#other').length > 0) ? $('#other').attr('value') : false;
    if (other) {
      $('#other').attr('disabled','true');
    }
    
    // update the db count
    $.post('/poll-vote.php', {
    nid: nid,
    jcall: 'true',
    other: other
    });
    
    // 
    var currentTotal = parseFloat($('.poll-total-count').html());
    currentTotal++;
    $("div").children(".poll-total-count").html(currentTotal);
    
    var votedOptionTotal = parseFloat($('#poll-vote-count-'+nid).html());
    votedOptionTotal++;
    $('#poll-vote-count-'+nid).html(votedOptionTotal);
    
    
    //$.cookie('voted', 'true');  
    
    return false;
  });
  
  


});
