Images Count Down

[Total: 0    Average: 0/5]

This has a graphical counter.

Body Code:

<!--
  -- Graphical Timer - Counts down from any number to zero - then stops.
  -->
<script>
var pathToImages="/js/"; /* note trailing slash */

/*
 * Image files should be called "one.gif", "nine.gif" etc...
 * "pic1.gif" should be an empty image
 */
var _pics = new Array();
    _pics[0] = new Image();_pics[0].src=pathToImages+"zero.gif";
    _pics[1] = new Image();_pics[1].src=pathToImages+"one.gif";
    _pics[2] = new Image();_pics[2].src=pathToImages+"two.gif";
    _pics[3] = new Image();_pics[3].src=pathToImages+"three.gif";
    _pics[4] = new Image();_pics[4].src=pathToImages+"four.gif";
    _pics[5] = new Image();_pics[5].src=pathToImages+"five.gif";
    _pics[6] = new Image();_pics[6].src=pathToImages+"six.gif";
    _pics[7] = new Image();_pics[7].src=pathToImages+"seven.gif";
    _pics[8] = new Image();_pics[8].src=pathToImages+"eight.gif";
    _pics[9] = new Image();_pics[9].src=pathToImages+"nine.gif";

 

var COUNTER = function(_start_value)
{
  this.COUNT = parseInt(_start_value);
  this.CountIs = function() { return this.COUNT; }
  this.DigitsInCount = function() { return this.COUNT.toString().length; }
  this.MAX_LENGTH=this.DigitsInCount();
  this.MaxLengthIs = function() { return this.MAX_LENGTH; }
  this.DigitIs = function(_i) { return this.COUNT.toString().split("")[parseInt(_i)-(this.MaxLengthIs()-this.DigitsInCount())]; }
  this.Count = function() { this.COUNT--; if (this.COUNT<0)this.COUNT=0;}
  this.DrawImages = function()
                    {
					  /*
					   * This function should only be called one time to construct the image objects
					   */
					  for(var index=0;index<this.MaxLengthIs();index++)
					  {
					    var _t = "<img width=50 height=50 src='"+pathToImages+"pic"+this.DigitIs(index)+".gif' name='pic"+index+"'>";
					    document.write(_t);
					  }
					}
  this.Update = function()
                {
				  var _offset=this.MaxLengthIs()-this.DigitsInCount();
				  for(var index=0;index<_offset;index++)
				  {
				    var _t = "document.pic"+index+".src='"+pathToImages+"pic1.gif'";
				    eval(_t);
				  }
				  for(var index=_offset;index<this.MaxLengthIs();index++)
				  {
				    var _t = "document.pic"+index+".src='"+_pics[this.DigitIs(index)].src+"'";
				    eval(_t);
				  }
				}
}

/*
 * Create a counter that starts with the value passed to COUNTER()
 *   45 here
 */
var MY_COUNTER = new COUNTER(112);
    MY_COUNTER.DrawImages();

function repeater()
{
	MY_COUNTER.Count();
	MY_COUNTER.Update();
	if(MY_COUNTER.CountIs()==0)
	{
	  clearInterval(KEEP_GOING);
	}
}
var KEEP_GOING = null;
function start(){KEEP_GOING=setInterval('repeater();',100);}
function stop(){clearInterval(KEEP_GOING);}
window.onload=start;
window.onunload=stop;
</script>

Times Viewed: 5

Leave a Reply

Your email address will not be published. Required fields are marked *