(function ($){$.fn.milenClock=function (options){var defaults={width:250,timezone:"",label:"",labelFont:"",labelFontSIze:"0.8em",labelColor:"#000",backgroundImage:"",backgroundColor:"",fontColor:"black",showDigits:true,showDigitsDots:true,digitsOffset:25,digitsFont:"20px Arial",showRing:true,ringColor:"black",ringWidth:3,handsSize:"medium",handSecWidth:2,handMinWidth:3,handHourWidth:5,handHourColor:"black",handMinuteColor:"black",handSecondColor:"red",handsType:"normal",movement:"normal"};,defaults,options);var canvas=this[0];var that=this;canvas.width=options.width;canvas.height=options.width;var ctx=canvas.getContext('2d');var clockWidth=options.width;var centerX=options.width / 2;var centerY=options.width / 2;var date,hours,minutes,seconds,miliSeconds,drawMinutes,drawHours,drawSeconds,minHandLen,hourHandLen,secHandLen;var serpentineH=new Image();//serpentineH.src="milen-clock-js/images/serpentine-hours.png";var serpentineM=new Image();//serpentineM.src="milen-clock-js/images/serpentine-minutes.png";var spadeH=new Image();//spadeH.src="milen-clock-js/images/spade-hours.png";var spadeM=new Image();//spadeM.src="milen-clock-js/images/spade-minutes.png";var background=new Image();background.src=options.backgroundImage;function drawLabel(label){if (options.label !==""){var style='text-align:center;color:'+options.labelColor+';font-size:'+options.labelFontSIze+';font-family:'+options.labelFont+';width:'+options.width+'px;';that.after('<div style="'+style+'">'+label+'</div)')}}switch (options.handsSize){case "small":hourHandLen=clockWidth / 4.5;minHandLen=hourHandLen*1.59;secHandLen=clockWidth / 2.8;break;case "large":hourHandLen=clockWidth / 3.5;minHandLen=hourHandLen*1.59;secHandLen=clockWidth / 2;break;default:hourHandLen=clockWidth / 4;minHandLen=hourHandLen*1.59;secHandLen=clockWidth / 2.5;break}Math.easeInOutQuad=function (t,b,c,d){t /=d / 2;if (t < 1) return c / 2 * t * t+b;t--;return -c / 2 * (t * (t - 2) - 1)+b};Date.prototype.stdTimezoneOffset=function(){var jan=new Date(this.getFullYear(),0,1);var jul=new Date(this.getFullYear(),6,1);return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset())}Date.prototype.dst=function(){return this.getTimezoneOffset() < this.stdTimezoneOffset()}switch (options.handsType){case "serpentine" :drawHours=function(length,angle){ctx.save();ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-90 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.drawImage(serpentineH,-length/9.17,-length/4.88,length,length/2.44);ctx.restore()};drawMinutes=function(length,angle){ctx.save();ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-90 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.drawImage(serpentineM,-length/13.04,-length/14.63,length,length/6.59);ctx.restore()};drawSeconds=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.handSecondColor;ctx.lineWidth=options.handSecWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handSecWidth/2,-length/5);ctx.lineTo(0,length-(length/10));ctx.lineTo(-options.handSecWidth/2,-length/5);ctx.lineTo(options.handSecWidth/2,-length/5);ctx.fill();ctx.closePath();ctx.restore();ctx.beginPath();ctx.arc(centerX,centerY,options.handSecWidth+1,0,2 * Math.PI,false);ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.ringColor;ctx.fill();ctx.stroke();ctx.closePath()};break;case "spade" :drawHours=function(length,angle){ctx.save();ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-90 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.drawImage(spadeH,-length/10.39,-length/10.39,length,length/5.05);ctx.restore()};drawMinutes=function(length,angle){ctx.save();ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-90 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.drawImage(spadeM,-length/17.14,-length/17.14,length,length/8.45);ctx.restore()};drawSeconds=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.handSecondColor;ctx.lineWidth=options.handSecWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handSecWidth/2,-length/5);ctx.lineTo(0,length-(length/10));ctx.lineTo(-options.handSecWidth/2,-length/5);ctx.lineTo(options.handSecWidth/2,-length/5);ctx.fill();ctx.closePath();ctx.restore();ctx.beginPath();ctx.arc(centerX,centerY,options.handSecWidth+1,0,2 * Math.PI,false);ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.ringColor;ctx.fill();ctx.stroke();ctx.closePath()};break;case "sword" :drawHours=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handHourColor;ctx.fillStyle=options.handHourColor;ctx.lineWidth=options.handHourWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handHourWidth/6,0);ctx.lineTo(options.handHourWidth/2,-length/5);ctx.lineTo(-options.handHourWidth/2,-length/5);ctx.lineTo(-options.handHourWidth/6,0);ctx.lineTo(-options.handHourWidth/2,2*length/3);ctx.lineTo(0,length-(length/10));ctx.lineTo(options.handHourWidth/2,2*length/3);ctx.lineTo(options.handHourWidth/6,0);ctx.fill();ctx.closePath();ctx.restore()};drawMinutes=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handMinuteColor;ctx.fillStyle=options.handMinuteColor;ctx.lineWidth=options.handMinWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handMinWidth/6,0);ctx.lineTo(options.handMinWidth/2,-length/5);ctx.lineTo(-options.handMinWidth/2,-length/5);ctx.lineTo(-options.handMinWidth/6,0);ctx.lineTo(-options.handMinWidth/2,2*length/3);ctx.lineTo(0,length-(length/10));ctx.lineTo(options.handMinWidth/2,2*length/3);ctx.lineTo(options.handMinWidth/6,0);ctx.fill();ctx.closePath();ctx.restore()};drawSeconds=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.handSecondColor;ctx.lineWidth=options.handSecWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handSecWidth/2,-length/5);ctx.lineTo(0,length-(length/10));ctx.lineTo(-options.handSecWidth/2,-length/5);ctx.lineTo(options.handSecWidth/2,-length/5);ctx.fill();ctx.closePath();ctx.restore();ctx.beginPath();ctx.arc(centerX,centerY,options.handSecWidth+1,0,2 * Math.PI,false);ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.ringColor;ctx.fill();ctx.stroke();ctx.closePath()};break;case "euroshaft" :drawHours=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handHourColor;ctx.fillStyle=options.handHourColor;ctx.lineWidth=options.handHourWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handHourWidth/2,0);ctx.lineTo(options.handHourWidth/2,length-(length/10));ctx.lineTo(-options.handHourWidth/2,length-(length/10));ctx.lineTo(-options.handHourWidth/2,0);ctx.fill();ctx.closePath();ctx.beginPath();ctx.arc(0,length-(length/10),options.handHourWidth/2,0,2*Math.PI);ctx.arc(0,0,options.handHourWidth/2,0,2*Math.PI);ctx.fill();ctx.closePath();ctx.restore()};drawMinutes=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handMinuteColor;ctx.fillStyle=options.handMinuteColor;ctx.lineWidth=options.handMinWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handMinWidth/2,0);ctx.lineTo(options.handMinWidth/2,length-(length/10));ctx.lineTo(-options.handMinWidth/2,length-(length/10));ctx.lineTo(-options.handMinWidth/2,0);ctx.fill();ctx.closePath();ctx.beginPath();ctx.arc(0,length-(length/10),options.handMinWidth/2,0,2*Math.PI);ctx.arc(0,0,options.handMinWidth/2,0,2*Math.PI);ctx.fill();ctx.closePath();ctx.restore()};drawSeconds=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.handSecondColor;ctx.lineWidth=options.handSecWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(0,-length/5);ctx.lineTo(0,length-(length/3));ctx.stroke();ctx.closePath();ctx.beginPath();ctx.arc(0,length-(length/3)+2.5*options.handSecWidth,2.5*options.handSecWidth,0,2 * Math.PI);ctx.stroke();ctx.closePath();ctx.beginPath();ctx.moveTo(0,length-(length/3)+5.5*options.handSecWidth);ctx.lineTo(0,length-(length/10));ctx.stroke();ctx.closePath();ctx.restore();ctx.beginPath();ctx.arc(centerX,centerY,options.handSecWidth+1,0,2 * Math.PI,false);ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.ringColor;ctx.fill();ctx.stroke();ctx.closePath()};break;default :drawHours=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handHourColor;ctx.fillStyle=options.handHourColor;ctx.lineWidth=options.handHourWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handHourWidth/2,-length/5);ctx.lineTo(-options.handHourWidth/2,-length/5);ctx.lineTo(-options.handHourWidth/2,length-(length/10));ctx.lineTo(options.handHourWidth/2,length-(length/10));ctx.lineTo(options.handHourWidth/2,-length/5);ctx.fill();ctx.closePath();ctx.restore()};drawMinutes=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handMinuteColor;ctx.fillStyle=options.handMinuteColor;ctx.lineWidth=options.handMinWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(options.handMinWidth/2,-length/5);ctx.lineTo(-options.handMinWidth/2,-length/5);ctx.lineTo(-options.handMinWidth/2,length-(length/10));ctx.lineTo(options.handMinWidth/2,length-(length/10));ctx.lineTo(options.handMinWidth/2,-length/5);ctx.fill();ctx.closePath();ctx.restore()};drawSeconds=function(length,angle){ctx.save();ctx.beginPath();ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.handSecondColor;ctx.lineWidth=options.handSecWidth;ctx.translate(centerX+0.5,centerY+0.5);ctx.rotate(-180 * Math.PI / 180);// Correct for top left origin ctx.rotate(angle * Math.PI / 180);ctx.moveTo(0,-length/5);ctx.lineTo(0,length-(length/10));ctx.stroke();ctx.closePath();ctx.restore();ctx.beginPath();ctx.arc(centerX,centerY,options.handSecWidth+1,0,2 * Math.PI,false);ctx.strokeStyle=options.handSecondColor;ctx.fillStyle=options.ringColor;ctx.fill();ctx.stroke();ctx.closePath()};break}function drawNumbers(){if (options.showDigitsDots || options.showDigits){var i=12;ctx.strokeStyle=options.ringColor;ctx.lineWidth=options.ringWidth;while (i>0){ctx.save();ctx.beginPath();ctx.textAlign='center';ctx.textBaseline='middle';ctx.translate(centerX+0.5,centerY+0.5);var angle=(i * 30) * Math.PI / 180;ctx.rotate(angle);ctx.translate(0,((-clockWidth / 2)+options.ringWidth));if (options.showDigits){ctx.save();ctx.fillStyle=options.fontColor;ctx.font=options.digitsFont;ctx.translate(0,options.digitsOffset);ctx.scale(1,1);ctx.rotate(-angle);ctx.fillText(i,0,0);ctx.restore()}if (options.showDigitsDots){ctx.moveTo(0,0);ctx.lineTo(0,10);ctx.stroke()}ctx.closePath();ctx.restore();i--}}}function drawFace(){if (options.backgroundColor){ctx.fillStyle=options.backgroundColor;ctx.fillRect(0,0,canvas.width,canvas.height);ctx.fill}if(options.backgroundImage){ctx.drawImage(background,0,0,canvas.width,canvas.height)}if (options.showRing){ctx.beginPath();ctx.arc(centerX,centerY,clockWidth / 2 - options.ringWidth,0,2 * Math.PI,false);ctx.strokeStyle=options.ringColor;ctx.lineWidth=options.ringWidth;ctx.stroke();ctx.closePath()}ctx.beginPath();ctx.arc(centerX,centerY,2,0,2 * Math.PI,false);ctx.fillStyle=options.ringColor;ctx.fill();ctx.closePath();drawNumbers()}var startValue=0;function tick(){canvas.width=canvas.width;drawFace();date=new Date();hours=date.getHours();minutes=date.getMinutes();seconds=date.getSeconds();miliSeconds=date.getMilliseconds();if (options.timezone !==""){var now=moment();hours=parseInt(now.tz(options.timezone).format('h'));minutes=parseInt(now.tz(options.timezone).format('m'));seconds=parseInt(now.tz(options.timezone).format('s'));miliSeconds=parseInt(now.tz(options.timezone).format('SSS'))};drawHours(hourHandLen,(hours+(minutes / 60)) * 30);drawMinutes(minHandLen,minutes * 6);if (options.movement==="normal"){drawSeconds(secHandLen,seconds * 6)}else if (options.movement==="smooth"){drawSeconds(secHandLen,(seconds+(miliSeconds / 1000)) * 6)}else{var animatedSeconds=seconds+1;if (miliSeconds>10){if (!startValue){startValue=miliSeconds}if (miliSeconds - startValue <=100){animatedSeconds -=-0.5+Math.easeInOutQuad(miliSeconds - startValue,startValue,1000 - startValue,125) / 1000}}else{startValue=0}var rotationAngle=animatedSeconds * 6;var percentFilled=animatedSeconds / 60;drawSeconds(secHandLen,(rotationAngle - 2 * Math.PI)+2 * Math.PI * percentFilled)}}drawLabel(options.label);window.setInterval(tick,10)}}(jQuery));