function makeUnits() {
  this["h"] = 60*60*1000;    	// hours
  this["d"] = 24*60*60*1000;	// days
  this["w"] = 7*24*60*60*1000;	// weeks
}
units = new makeUnits();

function RotatorEvent(whenstr, runtime, whatstr) {

  if ( whenstr.length < 10 ) {
    var year = this.now.getYear();
    if ( year < 1000 ) year += 1900;	// Nav 2&3 bug!
    if ( whenstr.substring(2,3) == ":" ) {
      // Prepend current date to time-only format
      whenstr = this.now.getDate() + this.now.toString().substring(3,8) + year + " " + whenstr;
    } else {
      // Append current year to day-and-date format
      whenstr = whenstr + " " + year;
    }
  }

  var when = new Date(whenstr);
  if ( when == 0 || isNaN(when) ) alert("Bad date: "+whenstr);

  var unit = units[runtime.substring(runtime.length-1)];
  if ( typeof(unit) == "undefined" ) alert("Bad duration: "+runtime);
  var len = runtime.substring(0,runtime.length-1) * unit;

  if ( this.now.getTime() < when.getTime() ) return;     // hasn't started yet
  if ( when.getTime()+len < this.now.getTime() ) return; // already finished

  // Event is active, assign its text string to the object
  this.content = whatstr;
}

function GetEvent() {
  return this.content;
}

function Rotator(str, zone) { 
  this.content = str;		// default text for the event
  this.now = new Date();
  if ( zone ) {			// adjust for event's time zone
    this.now.setTime(this.now.getTime() +
    (this.now.getTimezoneOffset()-Math.round(zone*60))*60*1000);
  //alert("TZoffset="+Date.getTimezoneOffset()/60+" zone="+zone);
  }
  this.event   = RotatorEvent;	// function to define new events
  this.getEvent = GetEvent; 	// function to get winning event
}

