﻿
window.fact_swap = function() {
//populate the array client side, using data from the seo friendly pre tag
  if(!this.aQuotes){
    this.aQuotes = new Array('No Data')
    o = document.getElementById('ivndata')
    if(o){
      tmp = o.innerHTML.split(/\{\}/)
      for(var i=0; i<tmp.length; i++){
        if(tmp[i].length>1) this.aQuotes[this.aQuotes.length] = tmp[i]
      }
    }
  }
  
  //if returning prematurely, cancel running timer
  if(this.mTimer){
    clearTimeout(this.mTimer)
    this.mTimer = null
  }

  //seconds to wait before swapping quote
  this.mInterval = 9000

  if(this.aQuotes){
    //pick a starting point randomly
    if(!this.ivnlastqt) this.ivnlastqt = parseInt(Math.random()*(this.aQuotes.length-1))
    if(++this.ivnlastqt>this.aQuotes.length-1) this.ivnlastqt=1
    o = document.getElementById('dynamic_fact')
    if(o){
      if(o.filters && o.filters[0]) o.filters[0].apply()
      o.innerHTML = this.aQuotes[this.ivnlastqt]
      if(o.filters && o.filters[0]) o.filters[0].play()
      this.mTimer = setTimeout('window.fact_swap()',this.mInterval)
    }
  }
}  
window.fact_swap()
