
function ReferenceBrowser() {
  
  this.sliders = new Array();
  this.activeSlideElement = null;
  this.timer = null;

  
  this.displayReference = function( ref ) {
    
    
    if ( !ref.reference || ref == this.activeSlideElement )
      return;
      
    this.activeSlideElement.className = '';
    this.activeSlideElement.reference.style.display = 'none';
    ref.reference.style.display = 'block';
    ref.className ='active';
    this.activeSlideElement = ref;
    
    
  }
  
  this.displayNext = function() {
    
    var ref = null;
    
    for ( var i = 0; i < this.sliders.length; i++ ) {
      if ( this.activeSlideElement == this.sliders[i] ) {
      
        if ( i == ( this.sliders.length - 1 ) )
          ref = this.sliders[0];
        else
          ref = this.sliders[i+1];
      
      }
    }
    
    if ( ref == null ) return;
    this.displayReference( ref );
    this.startSliding();
  }
  
  
  this.stopSliding = function() {
    clearTimeout( this.timer );
  }
  
  this.startSliding = function() {
      this.timer = setTimeout( 'window.rb.displayNext()', 3500 );
  }
  
  
  this.init = function( parent ) {
    var c = 1;
    for( var i = 0; i < parent.childNodes.length; i++ ) {
      var el = parent.childNodes[i];
      if ( el.tagName == 'LI') {
        el.reference = document.getElementById( 'slide' + c );
        c++;
        if ( el.className == 'active' ) {
          this.activeSlideElement = el;
        }
        
        el.onclick = function() {
          window.rb.stopSliding();
          window.rb.displayReference( this );
        }
        
        this.sliders.push( el );
        
      }
    }
  }
}

window.onload = function() {
  window.rb =  new ReferenceBrowser();
  window.rb.init( document.getElementById( 'reflinks' ) );
  window.rb.startSliding();
  
  
}

