/**
SWITCHING MECHANISM
**/

function Switcher(id) {
  this.id      = id;
  this.options = new Array();
  this.index   = -1;
  
  this.setVisible = _setVisible;
  this.addOption  = _addOption;
  this.setActive  = _setActive;      
  this.run        = _run;  
}
    
function _setVisible(index, bShow) {
  if (index >= 0 && index < this.options.length){
    this.options[index].style.display = bShow ? 'inline' : 'none';
  }
}

function _setActive(index) {      
  this.setVisible(this.index, false);
  this.index = index;
  this.setVisible(this.index, true);
}

function _addOption(option) {
  var idx = this.options.length
  this.options[idx] = option;
  this.setVisible(idx, false);
}


function _run() {
  idx = (this.index + 1) % this.options.length
  this.setActive(idx);
  setTimeout(this.id +'.run()', 4800);
}