/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function ActiveCard(element_id){
  document.write("<dl id='" + element_id + "'></dl>");
  this.cardbox = document.getElementById(element_id);
  this.cardboxcss = '';
  this.tags = new Array();
  this.content = null;

  this.cardClassName = new Array();
  this.cardClassName['box'] = "";
  this.cardClassName['tags'] = "";
  this.cardClassName['info'] = "";
  this.cardClassName['active'] = "";

  this.cardCss = new Array();
  this.cardCss['box'] = "";
  this.cardCss['tags'] = "";
  this.cardCss['info'] = "";
  this.cardCss['active'] = "";
  this.cards = new Array();

  this.runTime = 2000;
}


ActiveCard.timeout = -1;
ActiveCard.selectTags = false;
ActiveCard.select_id = 0;
ActiveCard.inContent = false;



ActiveCard.prototype.setTagsElement = function(){
  this.cardbox.innerHTML = "";
  if(this.cards.length != 0){
    num = this.cards.length;
    for(i = 0; i < num; ++i){
      this.tags[i] = document.createElement("dt");
      this.tags[i].innerHTML = this.cards[i]['tags'];
      this.tags[i].onmouseover = new Function("ActiveCard.selectTags=true;card.active(" + i +");");
      this.cardbox.appendChild(this.tags[i]);
    }
  }
}

ActiveCard.prototype.setCardContent = function(){
  this.content = document.createElement("dd");
  if(this.cardClassName['info'] != ""){
    this.content.className = this.cardClassName['info'];
  }
  else {
    this.content.style.cssText = "clear:both;";
  }
  this.cardbox.appendChild(this.content);

}

ActiveCard.prototype.active = function(active_id){
  if(active_id == undefined || active_id == "undefined"){
    active_id = 0;
  }

  //ActiveCard.select_id = active_id;

  num = this.tags.length;
  for(i=0; i < num ; ++i){
    if(active_id == i){
      if(this.cardClassName['active'] == ""){
        this.tags[i].style.cssText = this.cardCss['active'] + "text-align:center; float:left;";
      }
      else{
        this.tags[i].className = this.cardClassName['active'];
      }
      this.content.innerHTML = this.cards[i]['info'];

    }
    else{
      if(this.cardClassName['tags'] == ""){
        this.tags[i].style.cssText = this.cardCss['tags'] + "text-align:center; float:left;";
      }
      else{
        this.tags[i].className = this.cardClassName['tags'];
      }
    }
  }

  if(ActiveCard.selectTags || ActiveCard.inContent){
    window.clearTimeout(ActiveCard.timeout);

    this.content.onmouseover = new Function("ActiveCard.inContent = true;");
    this.content.onmouseout = new Function("ActiveCard.inContent = false;");;
    this.tags[active_id].onmouseout = new Function("ActiveCard.selectTags = false;");
    
  }
  else {
    this.content.onmouseover = null;
    this.content.onmouseout = null;

    this.tags[active_id].onmouseout = null;
    if(++active_id >= num){
      active_id = 0;
    }
  }
  ActiveCard.timeout = setTimeout("card.active(" + active_id +")", this.runTime);
}

ActiveCard.prototype.stop = function(){
  window.clearTimeout(ActiveCard.timeout);
}


ActiveCard.prototype.drawCard = function(){
  this.cardbox.style.cssText = this.cardboxcss;
  this.setTagsElement();
  this.setCardContent();
  this.active();
}

ActiveCard.activecard = function(element_id){
  return card = new ActiveCard(element_id);
}

function debug(string){
  par = document.getElementById("test");
  par.innerHTML = string;
}