/*** jPoll jQuery plugin version 1.0 Copyright (c) 2009 Dan Wellman */
(function($){$.jPoll={defaults:{ajaxOpts:{url:"http://www.intersectie.com/ht2009/inc/jq/poll.php"},groupName:"choices",groupIDs:["choice0","choice1","choice2","choice3","choice4"],pollHeading:"Please select out of the following:",rowClass:"row",errors:true}};$.fn.extend({jPoll:function(config){config=$.extend({},$.jPoll.defaults,config);$("<h3 class='mb10'>").text(config.pollHeading).appendTo($(this));$("<form class='voteForm'>").attr({id:"pollForm",action:config.ajaxOpts.url,method:config.ajaxOpts.type}).appendTo($(this));for(var x=0;x<config.groupIDs.length;x++){$("<div>").addClass(config.rowClass).appendTo($(this).find("form"));$("<input type='radio' name='"+config.groupName+"' id='"+config.groupIDs[x]+"'>").addClass("choice").appendTo($(this).find("form").children(":last")).click(function(){($(".error").length!=0)?$(".error").slideUp("slow"):null});$("<label>").text(config.groupIDs[x]).attr("for",config.groupIDs[x]).appendTo($(this).find("form").children(":last"))}$("<div>").attr("id","buttonRow").addClass(config.rowClass).appendTo($(this).find("form"));$("<button type='submit' class='voteButton'>").text("Vote!").appendTo("#buttonRow").click(function(e){e.preventDefault();var selected;$(".choice").each(function(){($(this).attr("checked")==true)?selected=$(this).attr("id"):null});if(config.errors==true){(selected==null&&$(".error").length==0)?$("<p>").addClass("error").text("Please make a selection!").css({display:"none"}).insertAfter("#pollForm").slideDown("slow"):null}var addOpts={type:"post",data:"&choice="+selected,dataType:"json",success:function(data){var total=0;for(var x=0;x<data.length;x++){total+=parseInt(data[x].votes)}$("div#pollContainer").find("h2").text("Results, out of "+total+" votes:");$("form#pollForm").slideUp("slow");$("<div>").attr("id","results").css({display:"none"}).insertAfter("#pollForm");for(var x=0;x<data.length;x++){$("<div>").addClass("row").attr("id","row"+x).appendTo("#results");$("<label>").text(config.groupIDs[x]).appendTo("#row"+x);$("<div>").attr("title",Math.round(data[x].votes/total*100)+"%").addClass("result").css({display:"none"}).appendTo("#row"+x)}$("#results").slideDown("slow",function(){$(".result").each(function(i){$(this).animate({width:Math.round(data[i].votes/total*100)},"slow")});$("<p>").attr("id","thanks").text("Thanks for voting!").css({display:"none"}).insertAfter("#results").fadeIn("slow")})}};ajaxOpts=$.extend({},addOpts,config.ajaxOpts);return(selected==null)?false:$.ajax(ajaxOpts)});return this}})})(jQuery);