$(document).ready(function(){
  definevoting();
});

function definevoting() {

  $('a.vote').click(votingProcess);
  if ($("#voting").length > 0 ) {
    var votingId = $("input[@name='contentid']").attr("value");
    var votingCookie = $.cookie('wm_voteresults');
    if (votingCookie != null && votingCookie.indexOf('-' + votingId + '-') != -1) {
      var originalurl = $("input[@id='votingoriginalurl']").attr("value");
      $("#voting-container").empty();
      $("#voting-container").load(originalurl);
    }
  }
}

function votingProcess(event){
  event.preventDefault();
  value = $(this).attr("id");
  value = value.replace('option','');
  $('#vote').attr("value",value);
  document.getElementById('votingoriginalurl').value = $("input[@id='votingoriginalurl']").attr("value");
  $("#voting-container").fadeOut("slow",function(){
    $('#voting').ajaxSubmit(loadResults);
    $(this).empty();
    });
}

function loadResults(data) {
  $("#voting-container").append(data).fadeIn("slow",function(){});;
}
