var RbBagCounter;
if (typeof(RbBagCounter)=="undefined")
   RbBagCounter=function(Interval)
   {
      this.Register();
      if (typeof(Interval)!="undefined")
         this.Interval=Interval;
      else
         this.Interval=RbBagCounter.DefaultUpdateInterval;
      this.TimerHandle=0;
      var d=new Date();
      d=new Date(2008,0,1);
      this.BaseSeconds=Date.parse(d)/1000;
      this.BaseTicks=null;
   }
RbBagCounter.NumBagsPerSecond=15855;
RbBagCounter.DefaultUpdateInterval=100;
RbBagCounter.Add=function(Interval)
{
   var bc=new RbBagCounter(Interval);
   document.write(bc.Html());
   bc.Start();
   return bc;
}
RbBagCounter.prototype.Register=function()
{
   if (typeof(RbBagCounter.Registry)=="undefined")
      RbBagCounter.Registry=new Array();
   this.Index=RbBagCounter.Registry.length;
   RbBagCounter.Registry[this.Index]=this;
}
RbBagCounter.prototype.GetSpanId=function()
{
   return "RbBagCounter_"+this.Index;
}
if (typeof(document.getElementById)=="function")
   RbBagCounter.prototype.GetSpan=function()
   {
      return document.getElementById(this.GetSpanId());
   }
else
   RbBagCounter.prototype.GetSpan=function()
   {
      return document.all[this.GetSpanId()];
   }
RbBagCounter.prototype.Html=function()
{
   return "<span id=\""+this.GetSpanId()+"\">"+this.GetBagCountString()+"</span>";
}
RbBagCounter.prototype.Start=function(Interval)
{
   this.Stop();
   if (typeof(Interval)!="undefined")
      this.Interval=Interval;
   this.GetBaseTicks();
   this.TimerHandle=window.setInterval("RbBagCounter.Registry["+this.Index+"].Update()",this.Interval,"javascript");
}
RbBagCounter.prototype.Stop=function()
{
   if (this.TimerHandle!=0)
   {
      window.clearInterval(this.TimerHandle);
      this.TimerHandle=0;
   }
   this.BaseTicks=null;
}
RbBagCounter.prototype.GetBaseTicks=function()
{
   if (this.BaseTicks==null)
      return this.SetBaseTicks();
   var t=this.BaseTicks+this.Count*this.Interval;
   if (t<Date.parse(new Date()))
       return this.SetBaseTicks();
   return t;
}
RbBagCounter.prototype.SetBaseTicks=function()
{
   this.BaseTicks=Date.parse(new Date());
   this.Count=0;
   return this.BaseTicks;
}
RbBagCounter.prototype.Update=function()
{
   this.Count++;
   this.GetSpan().innerHTML=this.GetBagCountString();
}
RbBagCounter.prototype.GetBagCountString=function()
{
   var secs=this.GetBaseTicks()/1000-this.BaseSeconds;
   var bags=Math.round(secs*RbBagCounter.NumBagsPerSecond);
   bags=bags.toString();
   var s="";
   for (var i=0;i<bags.length;i++)
   {
      if (i>0 && i%3==0)
         s=","+s;
      s=bags.charAt(bags.length-i-1)+s;
   }
   return s;
}

