/*
	jPoll jQuery plugin version 1.0
	
	Copyright (c) 2009 Dan Wellman
  
	Dual licensed under the MIT and GPL licenses:
  http://www.opensource.org/licenses/mit-license.php
  http://www.gnu.org/licenses/gpl.html
	
*/
(function(a){a.jPoll={defaults:{ajaxOpts:{url:"poll.php"},groupName:"keuzes",groupIDs:["keuze0","keuze1","keuze2","keuze3","keuze4"],pollHeading:"Maak een selectie:",rowClass:"row",pollId:0,errors:true}};a.fn.extend({jPoll:function(c){c=a.extend({},a.jPoll.defaults,c);a("<h2>").text(c.pollHeading).appendTo(a(this));a("<form>").attr({id:"pollForm",action:c.ajaxOpts.url}).appendTo(a(this));for(var b=0;b<c.groupIDs.length;b++){a("<div>").addClass(c.rowClass).appendTo(a(this).find("form"));a("<input type='radio' name='"+c.groupName+"' id='"+c.groupIDs[b]+"'>").addClass("choice").appendTo(a(this).find("form").children(":last")).click(function(){(a(".error").length!=0)?a(".error").slideUp("slow"):null});a("<label>").text(c.groupIDs[b]).attr("for",c.groupIDs[b]).appendTo(a(this).find("form").children(":last"))}a("<div>").attr("id","buttonRow").addClass(c.rowClass).appendTo(a(this).find("form"));a("<button type='submit'>").text("Stem!").appendTo("#buttonRow").click(function(f){f.preventDefault();var d;a(".choice").each(function(){(a(this).attr("checked")==true)?d=a(this).attr("id"):null});if(c.errors==true){(d==null&&a(".error").length==0)?a("<p>").addClass("error").text("Vul je stem in!").css({display:"none"}).insertAfter("#pollForm").slideDown("slow"):null}var g={type:"post",data:"&pollId="+c.pollId+"&choice="+d,dataType:"json",success:function(i){var h=0;for(var e=0;e<i.length;e++){h+=parseInt(i[e].votes)}a("div#pollContainer").find("h2").text("Resultaten, van de "+h+" stemmen:");a("form#pollForm").slideUp("slow");a("<div>").attr("id","results").css({display:"none"}).insertAfter("#pollForm");for(var e=0;e<i.length;e++){a("<div>").addClass("row").attr("id","row"+e).appendTo("#results");a("<label>").text(c.groupIDs[e]).appendTo("#row"+e);a("<div>").attr("title",Math.round(i[e].votes/h*100)+"%").addClass("result").css({display:"none"}).appendTo("#row"+e)}a("#results").slideDown("slow",function(){a(".result").each(function(j){a(this).animate({width:Math.round(i[j].votes/h*100)},"slow")});a("<p>").attr("id","thanks").text("Bedankt voor je stem!").css({display:"none"}).insertAfter("#results").fadeIn("slow")})}};ajaxOpts=a.extend({},g,c.ajaxOpts);return(d==null)?false:a.ajax(ajaxOpts)});return this}})})(jQuery);