(function(a){a.fn.polartimer=function(c){if(b[c]){return b[c].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof c==="object"||!c){return b.init.apply(this,arguments)}else{a.error("Method "+c+" does not exist on jQuery.polartimer")}};var b={init:function(b){var c={timerSeconds:10,callback:function(){},color:"#CCC",opacity:1};c=a.extend(c,b);return this.each(function(){var b=a(this);var d=b.data("polartimer");if(!d){b.addClass("polartimer");b.height(b.width());c.timer=null;c.timerCurrent=0;c.pi2=Math.PI*2;c.piOver2=Math.PI/2;c.width=b.width();c.height=b.height();c.raphael=Raphael(b.context,c.width,c.height);b.data("polartimer",c)}})},stopWatch:function(){return this.each(function(){var b=a(this).data("polartimer");if(b){var c=(b.timerFinish-(new Date).getTime())/1e3;if(c<=0){clearInterval(b.timer);a(this).polartimer("drawTimer",100);b.callback()}else{var d=100-c/b.timerSeconds*100;a(this).polartimer("drawTimer",d)}}})},drawTimer:function(b){return this.each(function(){$this=a(this);var c=$this.data("polartimer");if(c){var d=c.width;var e=c.height;var f=d/2;c.raphael.clear();if(b==100){c.raphael.circle(f,f,f).attr({fill:c.color,stroke:"none",opacity:c.opacity})}else{var g=c.pi2*b/100-c.piOver2;var h=Math.cos(g)*f+f;var i=Math.sin(g)*f+f;var j=b<=50?0:1;var k="M"+f+","+f+" L"+f+",0 ";k+="A"+f+","+f+" 0 "+j+",1 "+h+","+i+" ";k+="L"+f+","+f+"z";var l=c.raphael.path(k);l.attr({fill:c.color,stroke:"none",opacity:c.opacity})}}})},start:function(){return this.each(function(){var b=a(this).data("polartimer");if(b){clearInterval(b.timer);b.timerFinish=(new Date).getTime()+b.timerSeconds*1e3;a(this).polartimer("drawTimer",0);b.timer=setInterval("$this.polartimer('stopWatch')",50)}})},reset:function(){return this.each(function(){var b=a(this).data("polartimer");if(b){clearInterval(b.timer);a(this).polartimer("drawTimer",0)}})},destroy:function(){return this.each(function(){var b=a(this);var c=b.data("polartimer");if(c){clearInterval(c.timer);c.raphael.remove();b.removeData("polartimer")}})}}})(jQuery)

