/*!
 * FlipCounter jQuery JavaScript Library v1.0
 * http://nickpettazzoni.com/flipcounter
 *
 * Copyright 2010, Nick Pettazzoni
 * Licensed under the Apache Version 2.0 License.
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Includes: jQuery JavaScript Library
 * http://jquery.com
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Date: Wed Oct 6 12:00:00 2010 -0500
 */
(function(b){var a={init:function(d){settings={myself:this,value:parseInt(this.html()),digits:5,speed:150,updating:false,pathToImages:"/images/numbers/"};if(d){b.extend(settings,d)}b(this).data("digits",[]);b(this).data("settings",settings);var c;for(var e=0;e<=9;e++){c=new Image(100,100);c.src=settings.pathToImages+e+"_bottom.png";c=new Image(100,100);c.src=settings.pathToImages+e+"_top.png"}c=new Image(100,100);c.src=settings.pathToImages+"-_bottom.png";c=new Image(100,100);c.src=settings.pathToImages+"-_top.png";this.each(function(){b(this).flipCounter("blankScreen");b(this).flipCounter("updateValue")})},getValue:function(){return b(this).data("settings").value},getDigitsArray:function(){return b(this).data("digits")},getDigitEl:function(c){return b(this).data("settings").myself.flipCounter("getDigitsArray")[c]},getDigitValue:function(c){return b(this).data("settings").myself.flipCounter("getDigitEl",c).data("number")},getDigitTopEl:function(c){return b(this).data("digits")[c].children("img.flipCounter_digit_top").not("img.flipCounter_newguy")},getDigitBottomEl:function(c){return b(this).data("digits")[c].children("img.flipCounter_digit_bottom").not("img.flipCounter_newguy")},blankScreen:function(){var e="";for(var c=1;c<=b(this).data("settings").digits;c++){e+='<div class="flipCounter_digit"></div>'}b(this).data("settings").myself.html(e);var d=b(this);b(this).data("settings").myself.children().css({position:"relative",width:"35px",height:"55px","float":"left"}).each(function(g,f){b(this).html('<img class="flipCounter_digit_top" src="'+d.data("settings").pathToImages+'0_top.png"/> <img class="flipCounter_digit_bottom" src="'+d.data("settings").pathToImages+'0_bottom.png"/>');b(this).children(".flipCounter_digit_top").css({position:"absolute",bottom:"28px",left:"0px",width:"35px",height:"26px"});b(this).children(".flipCounter_digit_bottom").css({position:"absolute",top:"29px",left:"0px",width:"35px",height:"26px"});d.data("digits")[g+1]=b(this);d.data("digits")[g+1].data("number",0)})},updateDigitTo:function(g,i,h){var e=b(this).data("settings").myself;var f=e.flipCounter("getDigitEl",g);f.data("number",i);b('<img class="flipCounter_digit_top flipCounter_newguy" />').insertBefore(e.flipCounter("getDigitTopEl",g)).attr("src",e.data("settings").pathToImages+i+"_top.png").css({position:"absolute",bottom:"28px",left:"0px",width:"35px",height:"26px"});e.flipCounter("getDigitTopEl",g).animate({height:"0px"},e.data("settings").speed,"linear",function(){b(this).siblings("img.flipCounter_newguy").removeClass("flipCounter_newguy");b(this).remove();b('<img class="flipCounter_digit_bottom flipCounter_newguy"/>').insertAfter(e.flipCounter("getDigitBottomEl",g)).attr("src",e.data("settings").pathToImages+i+"_bottom.png").css({position:"absolute",top:"29px",left:"0px",width:"35px",height:"0px"}).animate({height:"26px"},e.data("settings").speed,"linear",function(){e.flipCounter("getDigitBottomEl",g).remove();b(this).removeClass("flipCounter_newguy");h()})})},updateValue:function(){var h=b(this);var e=b(this).data("settings");e.updating=true;var j=""+e.value;for(var c=j.length;c<b(this).data("digits").length-1;c++){j="0"+j}var g=new Array();var d=0;for(var f=0;f<j.length;f++){if(b(this).data("settings").myself.flipCounter("getDigitEl",b(this).data("settings").digits-f).data("number")!=j[(j.length-1-f)]){g[d]={digit:b(this).data("settings").digits-f,value:j.charAt(j.length-1-f)};d++}}if(g.length==0){e.updating=false;h.dequeue("qvalueUpdates")}else{for(y in g){var k;if(y==g.length-1){k=function(){e.updating=false;h.dequeue("qvalueUpdates")}}else{k=function(){b.noop()}}b(this).flipCounter("updateDigitTo",g[y].digit,g[y].value,k)}}},updateValueBy:function(d){if(!b(this).data("settings").updating){b(this).data("settings").value=b(this).data("settings").value+d;b(this).flipCounter("updateValue")}else{var c=b(this);c.queue("qvalueUpdates",function(){c.data("settings").value=c.data("settings").value+d;c.flipCounter("updateValue")})}},updateValueTo:function(d){if(!b(this).data("settings").updating){b(this).data("settings").value=d;b(this).flipCounter("updateValue")}else{var c=b(this);c.queue("qvalueUpdates",function(){c.data("settings").value=d;c.flipCounter("updateValue")})}}};b.fn.flipCounter=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.flipCounter")}}}})(jQuery);
