/*!
 * jQuery Final Countdown
 *
 * @author Pragmatic Mates, http://pragmaticmates.com
 * @version 1.1.1
 * @license GPL 2
 * @link https://github.com/PragmaticMates/jquery-final-countdown
 */
!function(e){var o,s,r,t,a,n,d,i,c,h,l,u;function w(){d.draw(),i.draw(),c.draw(),h.draw()}function v(e){return Math.PI/180*e-Math.PI/180*90}e.fn.final_countdown=function(b,f){if((l=e(this)).is(":visible")){var y,_=e.extend({start:void 0,end:void 0,now:void 0,selectors:{value_seconds:".clock-seconds .val",canvas_seconds:"canvas-seconds",value_minutes:".clock-minutes .val",canvas_minutes:"canvas-minutes",value_hours:".clock-hours .val",canvas_hours:"canvas-hours",value_days:".clock-days .val",canvas_days:"canvas-days"},seconds:{borderColor:"#7995D5",borderWidth:"6"},minutes:{borderColor:"#ACC742",borderWidth:"6"},hours:{borderColor:"#ECEFCB",borderWidth:"6"},days:{borderColor:"#FF9900",borderWidth:"6"}},b);void 0===(o=e.extend({},_,b)).start&&(o.start=l.data("start")),void 0===o.end&&(o.end=l.data("end")),void 0===o.now&&(o.now=l.data("now")),l.data("border-color")&&(o.seconds.borderColor=o.minutes.borderColor=o.hours.borderColor=o.days.borderColor=l.data("border-color")),o.now<o.start&&(o.start=o.now,o.end=o.now),o.now>o.end&&(o.start=o.now,o.end=o.now),"function"==typeof f&&(u=f),e(window).load(w),e(window).on("redraw",function(){switched=!1,w()}),e(window).on("resize",w),s={total:Math.floor((o.end-o.start)/86400),days:Math.floor((o.end-o.now)/86400),hours:24-Math.floor((o.end-o.now)%86400/3600),minutes:60-Math.floor((o.end-o.now)%86400%3600/60),seconds:60-Math.floor((o.end-o.now)%86400%3600%60)},function(){var l=e("#"+o.selectors.canvas_seconds).width(),u=new Kinetic.Stage({container:o.selectors.canvas_seconds,width:l,height:l});r=new Kinetic.Shape({drawFunc:function(r){var t=e("#"+o.selectors.canvas_seconds).width(),a=t/2-o.seconds.borderWidth/2,n=t/2,d=t/2;r.beginPath(),r.arc(n,d,a,v(0),v(6*s.seconds)),r.fillStrokeShape(this),e(o.selectors.value_seconds).html(60-s.seconds)},stroke:o.seconds.borderColor,strokeWidth:o.seconds.borderWidth}),(d=new Kinetic.Layer).add(r),u.add(d);var w=e("#"+o.selectors.canvas_minutes).width(),b=new Kinetic.Stage({container:o.selectors.canvas_minutes,width:w,height:w});t=new Kinetic.Shape({drawFunc:function(r){var t=e("#"+o.selectors.canvas_minutes).width(),a=t/2-o.minutes.borderWidth/2,n=t/2,d=t/2;r.beginPath(),r.arc(n,d,a,v(0),v(6*s.minutes)),r.fillStrokeShape(this),e(o.selectors.value_minutes).html(60-s.minutes)},stroke:o.minutes.borderColor,strokeWidth:o.minutes.borderWidth}),(i=new Kinetic.Layer).add(t),b.add(i);var f=e("#"+o.selectors.canvas_hours).width(),y=new Kinetic.Stage({container:o.selectors.canvas_hours,width:f,height:f});a=new Kinetic.Shape({drawFunc:function(r){var t=e("#"+o.selectors.canvas_hours).width(),a=t/2-o.hours.borderWidth/2,n=t/2,d=t/2;r.beginPath(),r.arc(n,d,a,v(0),v(360*s.hours/24)),r.fillStrokeShape(this),e(o.selectors.value_hours).html(24-s.hours)},stroke:o.hours.borderColor,strokeWidth:o.hours.borderWidth}),(c=new Kinetic.Layer).add(a),y.add(c);var _=e("#"+o.selectors.canvas_days).width(),m=new Kinetic.Stage({container:o.selectors.canvas_days,width:_,height:_});n=new Kinetic.Shape({drawFunc:function(r){var t=e("#"+o.selectors.canvas_days).width(),a=t/2-o.days.borderWidth/2,n=t/2,d=t/2;r.beginPath(),0==s.total?r.arc(n,d,a,v(0),v(360)):r.arc(n,d,a,v(0),v(360/s.total*(s.total-s.days))),r.fillStrokeShape(this),e(o.selectors.value_days).html(s.days)},stroke:o.days.borderColor,strokeWidth:o.days.borderWidth}),(h=new Kinetic.Layer).add(n),m.add(h)}(),y=setInterval(function(){if(s.seconds>59){if(60-s.minutes==0&&24-s.hours==0&&0==s.days)return clearInterval(y),void(void 0!==u&&u.call(this));s.seconds=1,s.minutes>59?(s.minutes=1,i.draw(),s.hours>23?(s.hours=1,s.days>0&&(s.days--,h.draw())):s.hours++,c.draw()):s.minutes++,i.draw()}else s.seconds++;d.draw()},1e3)}}}(jQuery);