/**
 * Apple-Style Flip Counter
 * Version 0.5.3 - May 7, 2011 
 *
 * Copyright (c) 2010 Chris Nanney
 * http://cnanney.com/journal/code/apple-style-counter-revisited/
 *
 * Licensed under MIT
 * http://www.opensource.org/licenses/mit-license.php
 */
var flipCounter=function(y,C){function v(){m=a.value;a.value+=a.inc;h=a.value;s(m,h);a.auto===!0&&(o=setTimeout(v,a.pace))}function z(d,f,b){var c=a.value,e=typeof f=="undefined"?!1:f,g=typeof b=="undefined"?1:b;e===!0&&g--;c!=d?(m=a.value,a.auto=!0,c+a.inc<=d&&g!=0?c+=a.inc:c=d,a.value=c,h=a.value,s(m,h),o=setTimeout(function(){z(d,e,g)},a.pace)):a.auto=!1}function s(d,f){w=d.toString().split("").reverse();t=f.toString().split("").reverse();var b,c=w.length,e=t.length;if(e>c)for(b=e-c;b>0;){var g=
t[e-b],n=Number(e-b+1)-1;i=k.createElement("ul");i.className="cd";i.id=j+"_d"+n;i.innerHTML='<li class="t" id="'+j+"_t_d"+n+'"></li><li class="b" id="'+j+"_b_d"+n+'"></li>';if(n%3==0)p=k.createElement("ul"),p.className="cd",p.innerHTML='<li class="s"></li>',l.insertBefore(p,l.firstChild);l.insertBefore(i,l.firstChild);k.getElementById(j+"_t_d"+n).style.backgroundPosition="0 -"+g*a.tFH+"px";k.getElementById(j+"_b_d"+n).style.backgroundPosition="0 -"+(g*a.bFH+a.bOffset)+"px";b--}if(e<c)for(b=c-e;b>
0;){e=k.getElementById(j+"_d"+(c-b));l.removeChild(e);e=l.firstChild.firstChild;if((" "+e.className+" ").indexOf(" s ")>-1)e=e.parentNode,l.removeChild(e);b--}for(b=0;b<c;b++)t[b]!=w[b]&&D(b,w[b],t[b])}function D(d,f,b){function c(){if(g<7){n=g<3?"t":"b";if(h=k.getElementById(j+"_"+n+"_d"+d))h.style.backgroundPosition=i[g];g++;g!=3?setTimeout(c,e):c()}}var e,g=0,n,h,i=["-"+a.fW+"px -"+f*a.tFH+"px",a.fW*-2+"px -"+f*a.tFH+"px","0 -"+b*a.tFH+"px","-"+a.fW+"px -"+(f*a.bFH+a.bOffset)+"px",a.fW*-2+"px -"+
(b*a.bFH+a.bOffset)+"px",a.fW*-3+"px -"+(b*a.bFH+a.bOffset)+"px","0 -"+(b*a.bFH+a.bOffset)+"px"];if(a.auto===!0&&a.pace<=300)switch(d){case 0:e=a.pace/6;break;case 1:e=a.pace/5;break;case 2:e=a.pace/4;break;case 3:e=a.pace/3;break;default:e=a.pace/1.5}else e=80;e=e>80?80:e;c()}function B(a,f,b,c,e){var g={result:!0};g.cond1=a/f>=1?!0:!1;g.cond2=f*b<=a?!0:!1;g.cond3=Math.abs(f*b-a)<=10?!0:!1;g.cond4=Math.abs(f*c-e)<=100?!0:!1;g.cond5=f*c<=e?!0:!1;if(g.cond1&&g.cond2&&g.cond4&&g.cond5){a=Math.abs(a-
f*b)+Math.abs(f*c-e);if(q.q===null)q.q=a;if(a<=q.q)q.pace=c,q.inc=b}for(b=1;b<=5;b++)if(g["cond"+b]===!1)g.result=!1;return g}function r(a){return!isNaN(parseFloat(a))&&isFinite(a)}function A(){clearTimeout(o);o=null}var x={value:0,inc:1,pace:1E3,auto:!0,tFH:39,bFH:64,fW:53,bOffset:390},a=C||{},k=window.document,j=typeof y!=="undefined"&&y!==""?y:"flip-counter",l=k.getElementById(j),u;for(u in x)a[u]=u in a?a[u]:x[u];var w=[],t=[],m,h,o=null,i,p,q={q:null,pace:0,inc:0};this.setValue=function(d){if(r(d))m=
a.value,h=d,a.value=d,s(m,h);return this};this.setIncrement=function(d){a.inc=r(d)?d:x.inc;return this};this.setPace=function(d){a.pace=r(d)?d:x.pace;return this};this.setAuto=function(d){if(d&&!a.atuo)a.auto=!0,v();if(!d&&a.auto)o&&A(),a.auto=!1;return this};this.step=function(){a.auto||v();return this};this.add=function(d){if(r(d))m=a.value,a.value+=d,h=a.value,s(m,h);return this};this.subtract=function(d){if(r(d))m=a.value,a.value-=d,a.value>=0?h=a.value:(h="0",a.value=0),s(m,h);return this};this.incrementTo=
function(d,f,b){o&&A();if(typeof f!="undefined"){var f=r(f)?f*1E3:1E4,b=typeof b!="undefined"&&r(b)?b:a.pace,c=typeof d!="undefined"&&r(d)?d-a.value:0,e,g,h,i=0;q.q=null;b=f/c>b?Math.round(f/c/10)*10:b;e=Math.floor(f/b);g=Math.floor(c/e);h=B(c,e,g,b,f);if(c>0){for(;h.result===!1&&i<100;)b+=10,e=Math.floor(f/b),g=Math.floor(c/e),h=B(c,e,g,b,f),i++;i==100?(a.inc=q.inc,a.pace=q.pace):(a.inc=g,a.pace=b);z(d,!0,e)}}else z(d)};this.getValue=function(){return a.value};this.stop=function(){o&&A();return this};
(function(d){var f=d.toString(),d=f.length,b=1,c;for(c=0;c<d;c++){i=k.createElement("ul");i.className="cd";i.id=j+"_d"+c;i.innerHTML=i.innerHTML='<li class="t" id="'+j+"_t_d"+c+'"></li><li class="b" id="'+j+"_b_d"+c+'"></li>';l.insertBefore(i,l.firstChild);if(b!=d&&b%3==0)p=k.createElement("ul"),p.className="cd",p.innerHTML='<li class="s"></li>',l.insertBefore(p,l.firstChild);b++}f=f.toString().split("").reverse();for(c=0;c<d;c++)k.getElementById(j+"_t_d"+c).style.backgroundPosition="0 -"+f[c]*a.tFH+
"px",k.getElementById(j+"_b_d"+c).style.backgroundPosition="0 -"+(f[c]*a.bFH+a.bOffset)+"px";a.auto===!0&&(o=setTimeout(v,a.pace))})(a.value)};
