/*!
 * 投票展示插件
 * @copyright (c) JSPGen.com
 * @version 1.0
 */
;(function($){$.fn.poll=function(id,options){var jspath=document.scripts;jspath=jspath[jspath.length-1].src.substring(0,jspath[jspath.length-1].src.lastIndexOf('/')+1);grapes.load([jspath+'images/poll.css']);var settings={title:null,titleCSS:'poll_title',width:'500px',speed:1000,checkbox:false,show:false,data:'',css:'poll0',colors:6};$.extend(settings,options);var dataObj=eval("("+settings.data+")");var $this=this;var total=0;$.each(dataObj,function(i,n){total+=parseInt(n.value);});$this.append("<table width='"+settings.width+"' border='0' cellpadding='0' cellspacing='0'></table>");if(null!=settings.title){$("table",this).append("<tr><td colspan='3' class='"+settings.titleCSS+"'>"+settings.title+"</span></td></tr>");}var itemDiv;$.each(dataObj,function(i,n){var index=0;var percentage=(n.value/total*100).toFixed(2);if(isNaN(percentage))percentage=0;var imgWidth=parseFloat(percentage);index=i%settings.colors;itemDiv="<div class='"+settings.css+"'><div divWidth='"+imgWidth+"' style='width:0%' class='plan"+index+"_l'><div class='plan"+index+"_r'><div class='plan"+index+"_c'></div></div></div></div>";$("table",$this).append("<tr><td width='30%' align='right'>"+n.name+"：</td><td width='60%'>"+itemDiv+"</td><td width='10%' nowrap>"+n.value+"("+percentage+"%)</td></tr>");if(settings.show){if(settings.checkbox){$("tr:last").append("<td><input type='checkbox' name='poll_"+id+"' value='"+n.id+"'/></td>");}else{$("tr:last").append("<td><input type='radio' name='poll_"+id+"' value='"+n.id+"'/></td>");}}});$("div",$this).each(function(i,n){if($(n).attr('divWidth')){$(n).animate({width:$(n).attr('divWidth')+'%'},settings.speed);$(n).removeAttr("divWidth");}});return this;};$.fn.getChecked=function(){var checked_val;return $(":checked",this);};})(jQuery);