var ContentSwitcher = function()
{
  var ref = this;

  this._content = new Array();

  this.addContent = function(content)
  {
    this._content.push(content);
  }

  this.updateContent = function()
  {
    for(area in this._content)
    {
      var curr_area = this._content[area];
      curr_area.dom = new Array();
      for(index in curr_area.ids)
      {
        curr_area.dom[index] = document.getElementById(curr_area.ids[index]);
        var dom = curr_area.dom[index];
        changeOpac(0, dom);
        dom.style.zIndex = 0;
        dom.style.display = 'block';
        dom.style.position = 'absolute';
        dom.style.top = 0;
        dom.style.left = 0;
      }
    }
    this.fade(0);
    return false;
  }

  this.fade = function(opacity)
  {
    if(opacity < 100)
    {
      for(area in this._content)
      {
        var curr_area = this._content[area];
        changeOpac(opacity, curr_area.dom[curr_area.current]);
      }
      setTimeout(function(){ref.fade(opacity+10);}, 30);
    }
    else
    {
      for(area in this._content)
      {
        var curr_area = this._content[area];
        if(curr_area.dom[curr_area.current - 1])
        {
          changeOpac(0, curr_area.dom[curr_area.current - 1]);
        }
        else
        {
          changeOpac(0, curr_area.dom[curr_area.dom.length - 1]);
        }
        if(curr_area.dom[curr_area.current])
        {
          curr_area.dom[curr_area.current].style.zIndex = 0;
        }
        if(curr_area.dom[curr_area.current + 1])
        {
          curr_area.current++;
        }
        else
        {
          curr_area.current = 0;
        }
        if(curr_area.dom[curr_area.current])
        {
          curr_area.dom[curr_area.current].style.zIndex = 100;
        }
      }
      setTimeout(function(){ref.fade(0);},5000);
    }
  }
}

function changeOpac(opacity, dom)
{
  if(!dom || !dom.style)
  {
    return;
  }
  if(dom.style.MozOpacity != null)
  {
    dom.style.MozOpacity = (opacity / 100);
  }
  else if(dom.style.opacity != null)
  {
    dom.style.opacity = (opacity / 100);
  }
  else if(dom.style.filter != null)
  {
    dom.style.filter = 'alpha(opacity='+opacity+')';
  }
}
