var tabClass = "tab w3c_tab";
if(document.attachEvent) tabClass = "tab IE_tab";

//if(document.attachEvent) window.alert("OK");
//window.alert(tabClass);

function Tab(tabCollection, title, content)
{
 this.type = "Tab";
 
 this.hnd = tabCollection;
 
 this.title = title;
 this.content = content;
 
 //window.alert(tabClass);
 
 this.tabDOM = document.createElement('div');
 this.tabDOM.hnd = this;
 setClass(this.tabDOM, tabClass);
 setEvent(this.tabDOM, "onmouseover", "if(this.className != '"+tabClass+" selected') this.className = '"+tabClass+" over';");
 setEvent(this.tabDOM, "onmouseout", "if(this.className != '"+tabClass+" selected') this.className = '"+tabClass+"';");
 setEvent(this.tabDOM, "onclick", "this.hnd.hnd.selectTab(this.hnd);");
 this.tabDOM.innerHTML = "<DIV>"+title+"</DIV>";
 this.hnd.tabCollectionDOM.appendChild(this.tabDOM);
}

function TabCollection(hnd)
{
 this.type = "TabCollection";
 
 this.hnd = hnd;
 removeAllNodes(this.hnd);
 
 this.tab = new Array();
 this.selectedTabIndex = -1;
 this.saveTabChanges = 1;
 
 this.tabCollectionDOM = document.createElement('div');
 setClass(this.tabCollectionDOM, "tabList");
 hnd.appendChild(this.tabCollectionDOM);
 
 this.tabContentDOM_wrapper = document.createElement('div');
 setClass(this.tabContentDOM_wrapper, "tabContentWrapper");
 hnd.appendChild(this.tabContentDOM_wrapper);
 
 this.tabContentDOM = document.createElement('div');
 setClass(this.tabContentDOM, "tabContent");
 this.tabContentDOM_wrapper.appendChild(this.tabContentDOM);
 
 this.addTab = function(title, content)
 {
  this.tab.push(new Tab(this, title, content));
  if(this.tab.length == 1) this.selectTab(0);
 }
 
 this.getTabIndex = function(tab)
 {
  for(var i=0; i< this.tab.length; i++) if(this.tab[i] == tab) return i;
  return -1;
 }
 
 this.selectTab = function(index)
 {
  if(typeof(index) == "object") index = this.getTabIndex(index);
 
  for(var i=0; i< this.tab.length; i++) setClass(this.tab[i].tabDOM, tabClass);
  setClass(this.tab[index].tabDOM, tabClass+" selected");
  
  if(this.saveTabChanges) 
  {
   if(this.selectedTabIndex != -1) this.tab[this.selectedTabIndex].content = removeNode(this.tabContentDOM.firstChild);
  }
  else removeAllNodes(this.tabContentDOM);
  
  if(typeof(this.tab[index].content) == "string")	this.tabContentDOM.innerHTML = this.tab[index].content;
  if(typeof(this.tab[index].content) == "object")	this.tabContentDOM.appendChild(this.tab[index].content.cloneNode(true));
  
  this.selectedTabIndex = index;
 }
}
