text: !function($){function hexToRgb(hex){var shorthandRegex=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;hex=hex.replace(shorthandRegex,function(m,r,g,b){return r+r+g+g+b+b});var result=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);return result?{r:parseInt(result[1],16),g:parseInt(result[2],16),b:parseInt(result[3],16)}:null}function isCanvasSupported(){var elem=document.createElement("canvas");return!(!elem.getContext||!elem.getContext("2d"))}function s4(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}function guid(){return s4()+s4()+"-"+s4()+"-"+s4()+"-"+s4()+"-"+s4()+s4()+s4()}function parse_date(str){var match=str.match(/^[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{1,2}:[0-9]{2}:[0-9]{2}$/);if(null!==match&&match.length>0){var parts=str.split(" "),date=parts[0].split("-"),time=parts[1].split(":");return new Date(date[0],date[1]-1,date[2],time[0],time[1],time[2])}var d=Date.parse(str);return isNaN(d)?(d=Date.parse(str.replace(/-/g,"/").replace("T"," ")),isNaN(d)?new Date:d):d}function parse_times(diff,old_diff,total_duration,units,floor){for(var raw_time={},raw_old_time={},time={},pct={},old_pct={},old_time={},greater_unit=null,i=0;i<units.length;i++){var maxUnits,unit=units[i];maxUnits=null===greater_unit?total_duration/secondsIn[unit]:secondsIn[greater_unit]/secondsIn[unit];var curUnits=diff/secondsIn[unit],oldUnits=old_diff/secondsIn[unit];floor&&(curUnits=curUnits>0?Math.floor(curUnits):Math.ceil(curUnits),oldUnits=oldUnits>0?Math.floor(oldUnits):Math.ceil(oldUnits)),"Days"!==unit&&(curUnits%=maxUnits,oldUnits%=maxUnits),raw_time[unit]=curUnits,time[unit]=Math.abs(curUnits),raw_old_time[unit]=oldUnits,old_time[unit]=Math.abs(oldUnits),pct[unit]=Math.abs(curUnits)/maxUnits,old_pct[unit]=Math.abs(oldUnits)/maxUnits,greater_unit=unit}return{raw_time:raw_time,raw_old_time:raw_old_time,time:time,old_time:old_time,pct:pct,old_pct:old_pct}}function updateUsedWindow(){"undefined"!=typeof useWindow.TC_Instance_List?TC_Instance_List=useWindow.TC_Instance_List:useWindow.TC_Instance_List=TC_Instance_List,initializeAnimationFrameHandler(useWindow)}function initializeAnimationFrameHandler(w){for(var vendors=["webkit","moz"],x=0;x<vendors.length&&!w.requestAnimationFrame;++x)w.requestAnimationFrame=w[vendors[x]+"RequestAnimationFrame"],w.cancelAnimationFrame=w[vendors[x]+"CancelAnimationFrame"];w.requestAnimationFrame&&w.cancelAnimationFrame||(w.requestAnimationFrame=function(callback,element,instance){"undefined"==typeof instance&&(instance={data:{last_frame:0}});var currTime=(new Date).getTime(),timeToCall=Math.max(0,16-(currTime-instance.data.last_frame)),id=w.setTimeout(function(){callback(currTime+timeToCall)},timeToCall);return instance.data.last_frame=currTime+timeToCall,id},w.cancelAnimationFrame=function(id){clearTimeout(id)})}var useWindow=window;Object.keys||(Object.keys=function(){"use strict";var hasOwnProperty=Object.prototype.hasOwnProperty,hasDontEnumBug=!{toString:null}.propertyIsEnumerable("toString"),dontEnums=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],dontEnumsLength=dontEnums.length;return function(obj){if("object"!=typeof obj&&("function"!=typeof obj||null===obj))throw new TypeError("Object.keys called on non-object");var prop,i,result=[];for(prop in obj)hasOwnProperty.call(obj,prop)&&result.push(prop);if(hasDontEnumBug)for(i=0;dontEnumsLength>i;i++)hasOwnProperty.call(obj,dontEnums[i])&&result.push(dontEnums[i]);return result}}());var limited_mode=!1,tick_duration=200,allUnits=("#debug"===location.hash,["Days","Hours","Minutes","Seconds"]),nextUnits={Seconds:"Minutes",Minutes:"Hours",Hours:"Days",Days:"Years"},secondsIn={Seconds:1,Minutes:60,Hours:3600,Days:86400,Months:2678400,Years:31536e3};Array.prototype.indexOf||(Array.prototype.indexOf=function(elt){var len=this.length>>>0,from=Number(arguments[1])||0;for(from=0>from?Math.ceil(from):Math.floor(from),0>from&&(from+=len);len>from;from++)if(from in this&&this[from]===elt)return from;return-1});var TC_Instance_List={},TC_Instance=function(element,options){this.element=element,this.container,this.listeners=null,this.data={paused:!1,last_frame:0,animation_frame:null,interval_fallback:null,timer:!1,total_duration:null,prev_time:null,drawn_units:[],text_elements:{Days:null,Hours:null,Minutes:null,Seconds:null},attributes:{canvas:null,context:null,item_size:null,line_width:null,radius:null,outer_radius:null},state:{fading:{Days:!1,Hours:!1,Minutes:!1,Seconds:!1}}},this.config=null,this.setOptions(options),this.initialize()};TC_Instance.prototype.clearListeners=function(){this.listeners={all:[],visible:[]}},TC_Instance.prototype.addTime=function(seconds_to_add){if(this.data.attributes.ref_date instanceof Date){var d=this.data.attributes.ref_date;d.setSeconds(d.getSeconds()+seconds_to_add)}else isNaN(this.data.attributes.ref_date)||(this.data.attributes.ref_date+=1e3*seconds_to_add)},TC_Instance.prototype.initialize=function(clear_listeners){this.data.drawn_units=[];for(var i=0;i<Object.keys(this.config.time).length;i++){var unit=Object.keys(this.config.time)[i];this.config.time[unit].show&&this.data.drawn_units.push(unit)}$(this.element).children("div.time_circles").remove(),"undefined"==typeof clear_listeners&&(clear_listeners=!0),(clear_listeners||null===this.listeners)&&this.clearListeners(),this.container=$("<div>"),this.container.addClass("time_circles"),this.container.appendTo(this.element);var height=this.element.offsetHeight,width=this.element.offsetWidth;0===height&&(height=$(this.element).height()),0===width&&(width=$(this.element).width()),0===height&&width>0?height=width/this.data.drawn_units.length:0===width&&height>0&&(width=height*this.data.drawn_units.length);var canvasElement=document.createElement("canvas");canvasElement.width=width,canvasElement.height=height,this.data.attributes.canvas=$(canvasElement),this.data.attributes.canvas.appendTo(this.container);var canvasSupported=isCanvasSupported();canvasSupported||"undefined"==typeof G_vmlCanvasManager||(G_vmlCanvasManager.initElement(canvasElement),limited_mode=!0,canvasSupported=!0),canvasSupported&&(this.data.attributes.context=canvasElement.getContext("2d")),this.data.attributes.item_size=Math.min(width/this.data.drawn_units.length,height),this.data.attributes.line_width=this.data.attributes.item_size*this.config.fg_width,this.data.attributes.radius=(.8*this.data.attributes.item_size-this.data.attributes.line_width)/2,this.data.attributes.outer_radius=this.data.attributes.radius+.5*Math.max(this.data.attributes.line_width,this.data.attributes.line_width*this.config.bg_width);var i=0;for(var key in this.data.text_elements)if(this.config.time[key].show){var textElement=$("<div>");textElement.addClass("textDiv_"+key),textElement.css("top",Math.round(.35*this.data.attributes.item_size)),textElement.css("left",Math.round(i++*this.data.attributes.item_size)),textElement.css("width",this.data.attributes.item_size),textElement.appendTo(this.container);var headerElement=$("<h4>");headerElement.text(this.config.time[key].text),headerElement.css("font-size",Math.round(this.config.text_size*this.data.attributes.item_size)),headerElement.css("line-height",Math.round(this.config.text_size*this.data.attributes.item_size)+"px"),headerElement.appendTo(textElement);var numberElement=$("<span>");numberElement.css("font-size",Math.round(3*this.config.text_size*this.data.attributes.item_size)),numberElement.css("line-height",Math.round(this.config.text_size*this.data.attributes.item_size)+"px"),numberElement.appendTo(textElement),this.data.text_elements[key]=numberElement}this.start(),this.config.start||(this.data.paused=!0);var _this=this;this.data.interval_fallback=useWindow.setInterval(function(){_this.update.call(_this,!0)},100)},TC_Instance.prototype.update=function(nodraw){if("undefined"==typeof nodraw)nodraw=!1;else if(nodraw&&this.data.paused)return;limited_mode&&this.data.attributes.context.clearRect(0,0,this.data.attributes.canvas[0].width,this.data.attributes.canvas[0].hright);var diff,old_diff,prevDate=this.data.prev_time,curDate=new Date;if(this.data.prev_time=curDate,null===prevDate&&(prevDate=curDate),!this.config.count_past_zero&&curDate>this.data.attributes.ref_date){for(var i=0;i<this.data.drawn_units.length;i++){var key=this.data.drawn_units[i];this.data.text_elements[key].text("0");var x=i*this.data.attributes.item_size+this.data.attributes.item_size/2,y=this.data.attributes.item_size/2,color=this.config.time[key].color;this.drawArc(x,y,color,0)}return void this.stop()}diff=(this.data.attributes.ref_date-curDate)/1e3,old_diff=(this.data.attributes.ref_date-prevDate)/1e3;var floor="smooth"!==this.config.animation,visible_times=parse_times(diff,old_diff,this.data.total_duration,this.data.drawn_units,floor),all_times=parse_times(diff,old_diff,secondsIn.Years,allUnits,floor),i=0,j=0,lastKey=null,cur_shown=this.data.drawn_units.slice();for(var i in allUnits){var key=allUnits[i];if(Math.floor(all_times.raw_time[key])!==Math.floor(all_times.raw_old_time[key])&&this.notifyListeners(key,Math.floor(all_times.time[key]),Math.floor(diff),"all"),!(cur_shown.indexOf(key)<0)){if(Math.floor(visible_times.raw_time[key])!==Math.floor(visible_times.raw_old_time[key])&&this.notifyListeners(key,Math.floor(visible_times.time[key]),Math.floor(diff),"visible"),!nodraw){this.data.text_elements[key].text(Math.floor(Math.abs(visible_times.time[key])));var x=j*this.data.attributes.item_size+this.data.attributes.item_size/2,y=this.data.attributes.item_size/2,color=this.config.time[key].color;"smooth"===this.config.animation?(null===lastKey||limited_mode||(Math.floor(visible_times.time[lastKey])>Math.floor(visible_times.old_time[lastKey])?(this.radialFade(x,y,color,1,key),this.data.state.fading[key]=!0):Math.floor(visible_times.time[lastKey])<Math.floor(visible_times.old_time[lastKey])&&(this.radialFade(x,y,color,0,key),this.data.state.fading[key]=!0)),this.data.state.fading[key]||this.drawArc(x,y,color,visible_times.pct[key])):this.animateArc(x,y,color,visible_times.pct[key],visible_times.old_pct[key],(new Date).getTime()+tick_duration)}lastKey=key,j++}}if(!this.data.paused&&!nodraw){var _this=this,update=function(){_this.update.call(_this)};if("smooth"===this.config.animation)this.data.animation_frame=useWindow.requestAnimationFrame(update,_this.element,_this);else{var delay=diff%1*1e3;0>delay&&(delay=1e3+delay),delay+=50,_this.data.animation_frame=useWindow.setTimeout(function(){_this.data.animation_frame=useWindow.requestAnimationFrame(update,_this.element,_this)},delay)}}},TC_Instance.prototype.animateArc=function(x,y,color,target_pct,cur_pct,animation_end){if(null!==this.data.attributes.context){var diff=cur_pct-target_pct;if(Math.abs(diff)>.5)0===target_pct?this.radialFade(x,y,color,1):this.radialFade(x,y,color,0);else{var progress=(tick_duration-(animation_end-(new Date).getTime()))/tick_duration;progress>1&&(progress=1);var pct=cur_pct*(1-progress)+target_pct*progress;if(this.drawArc(x,y,color,pct),progress>=1)return;var _this=this;useWindow.requestAnimationFrame(function(){_this.animateArc(x,y,color,target_pct,cur_pct,animation_end)},this.element)}}},TC_Instance.prototype.drawArc=function(x,y,color,pct){if(null!==this.data.attributes.context){var clear_radius=Math.max(this.data.attributes.outer_radius,this.data.attributes.item_size/2);limited_mode||this.data.attributes.context.clearRect(x-clear_radius,y-clear_radius,2*clear_radius,2*clear_radius),this.config.use_background&&(this.data.attributes.context.beginPath(),this.data.attributes.context.arc(x,y,this.data.attributes.radius,0,2*Math.PI,!1),this.data.attributes.context.lineWidth=this.data.attributes.line_width*this.config.bg_width,this.data.attributes.context.strokeStyle=this.config.circle_bg_color,this.data.attributes.context.stroke());var startAngle,endAngle,counterClockwise,defaultOffset=-.5*Math.PI,fullCircle=2*Math.PI;startAngle=defaultOffset+this.config.start_angle/360*fullCircle;var offset=2*pct*Math.PI;"Both"===this.config.direction?(counterClockwise=!1,startAngle-=offset/2,endAngle=startAngle+offset):"Clockwise"===this.config.direction?(counterClockwise=!1,endAngle=startAngle+offset):(counterClockwise=!0,endAngle=startAngle-offset),this.data.attributes.context.beginPath(),this.data.attributes.context.arc(x,y,this.data.attributes.radius,startAngle,endAngle,counterClockwise),this.data.attributes.context.lineWidth=this.data.attributes.line_width,this.data.attributes.context.strokeStyle=color,this.data.attributes.context.stroke()}},TC_Instance.prototype.radialFade=function(x,y,color,from,key){var i,rgb=hexToRgb(color),_this=this,step=.2*(1===from?-1:1);for(i=0;1>=from&&from>=0;i++)!function(){var delay=50*i,rgba="rgba("+rgb.r+", "+rgb.g+", "+rgb.b+", "+Math.round(10*from)/10+")";useWindow.setTimeout(function(){_this.drawArc(x,y,rgba,1)},delay)}(),from+=step;void 0!==typeof key&&useWindow.setTimeout(function(){_this.data.state.fading[key]=!1},50*i)},TC_Instance.prototype.timeLeft=function(){if(this.data.paused&&"number"==typeof this.data.timer)return this.data.timer;var now=new Date;return(this.data.attributes.ref_date-now)/1e3},TC_Instance.prototype.start=function(){useWindow.cancelAnimationFrame(this.data.animation_frame),useWindow.clearTimeout(this.data.animation_frame);var attr_data_date=$(this.element).data("date");if("undefined"==typeof attr_data_date&&(attr_data_date=$(this.element).attr("data-date")),"string"==typeof attr_data_date)this.data.attributes.ref_date=parse_date(attr_data_date);else if("number"==typeof this.data.timer)this.data.paused&&(this.data.attributes.ref_date=(new Date).getTime()+1e3*this.data.timer);else{var attr_data_timer=$(this.element).data("timer");"undefined"==typeof attr_data_timer&&(attr_data_timer=$(this.element).attr("data-timer")),"string"==typeof attr_data_timer&&(attr_data_timer=parseFloat(attr_data_timer)),"number"==typeof attr_data_timer?(this.data.timer=attr_data_timer,this.data.attributes.ref_date=(new Date).getTime()+1e3*attr_data_timer):this.data.attributes.ref_date=this.config.ref_date}this.data.paused=!1,this.update.call(this)},TC_Instance.prototype.restart=function(){this.data.timer=!1,this.start()},TC_Instance.prototype.stop=function(){"number"==typeof this.data.timer&&(this.data.timer=this.timeLeft(this)),this.data.paused=!0,useWindow.cancelAnimationFrame(this.data.animation_frame)},TC_Instance.prototype.destroy=function(){this.clearListeners(),this.stop(),useWindow.clearInterval(this.data.interval_fallback),this.data.interval_fallback=null,this.container.remove(),$(this.element).removeAttr("data-tc-id"),$(this.element).removeData("tc-id")},TC_Instance.prototype.setOptions=function(options){if(null===this.config&&(this.default_options.ref_date=new Date,this.config=$.extend(!0,{},this.default_options)),$.extend(!0,this.config,options),useWindow=this.config.use_top_frame?window.top:window,updateUsedWindow(),this.data.total_duration=this.config.total_duration,"string"==typeof this.data.total_duration)if("undefined"!=typeof secondsIn[this.data.total_duration])this.data.total_duration=secondsIn[this.data.total_duration];else if("Auto"===this.data.total_duration)for(var i=0;i<Object.keys(this.config.time).length;i++){var unit=Object.keys(this.config.time)[i];if(this.config.time[unit].show){this.data.total_duration=secondsIn[nextUnits[unit]];break}}else this.data.total_duration=secondsIn.Years,console.error("Valid values for TimeCircles config.total_duration are either numeric, or (string) Years, Months, Days, Hours, Minutes, Auto")},TC_Instance.prototype.addListener=function(f,context,type){"function"==typeof f&&("undefined"==typeof type&&(type="visible"),this.listeners[type].push({func:f,scope:context}))},TC_Instance.prototype.notifyListeners=function(unit,value,total,type){for(var i=0;i<this.listeners[type].length;i++){var listener=this.listeners[type][i];listener.func.apply(listener.scope,[unit,value,total])}},TC_Instance.prototype.default_options={ref_date:new Date,start:!0,animation:"smooth",count_past_zero:!0,circle_bg_color:"#60686F",use_background:!0,fg_width:.1,bg_width:1.2,text_size:.07,total_duration:"Auto",direction:"Clockwise",use_top_frame:!1,start_angle:0,time:{Days:{show:!0,text:"Days",color:"#FC6"},Hours:{show:!0,text:"Hours",color:"#9CF"},Minutes:{show:!0,text:"Minutes",color:"#BFB"},Seconds:{show:!0,text:"Seconds",color:"#F99"}}};var TC_Class=function(elements,options){this.elements=elements,this.options=options,this.foreach()};TC_Class.prototype.getInstance=function(element){var instance,cur_id=$(element).data("tc-id");if("undefined"==typeof cur_id&&(cur_id=guid(),$(element).attr("data-tc-id",cur_id)),"undefined"==typeof TC_Instance_List[cur_id]){var options=this.options,element_options=$(element).data("options");"string"==typeof element_options&&(element_options=JSON.parse(element_options)),"object"==typeof element_options&&(options=$.extend(!0,{},this.options,element_options)),instance=new TC_Instance(element,options),TC_Instance_List[cur_id]=instance}else instance=TC_Instance_List[cur_id],"undefined"!=typeof this.options&&instance.setOptions(this.options);return instance},TC_Class.prototype.addTime=function(seconds_to_add){this.foreach(function(instance){instance.addTime(seconds_to_add)})},TC_Class.prototype.foreach=function(callback){var _this=this;return this.elements.each(function(){var instance=_this.getInstance(this);"function"==typeof callback&&callback(instance)}),this},TC_Class.prototype.start=function(){return this.foreach(function(instance){instance.start()}),this},TC_Class.prototype.stop=function(){return this.foreach(function(instance){instance.stop()}),this},TC_Class.prototype.restart=function(){return this.foreach(function(instance){instance.restart()}),this},TC_Class.prototype.rebuild=function(){return this.foreach(function(instance){instance.initialize(!1)}),this},TC_Class.prototype.getTime=function(){return this.getInstance(this.elements[0]).timeLeft()},TC_Class.prototype.addListener=function(f,type){"undefined"==typeof type&&(type="visible");var _this=this;return this.foreach(function(instance){instance.addListener(f,_this.elements,type)}),this},TC_Class.prototype.destroy=function(){return this.foreach(function(instance){instance.destroy()}),this},TC_Class.prototype.end=function(){return this.elements},$.fn.TimeCircles=function(options){return new TC_Class(this,options)}}(jQuery);