function TabCarouselClass(p) {

this.labelHeight = 30;
this.tabWidth = 940; 
this.tabHeight = 250; 
this.speed = 5;
this.openStep = 10;
this.subStep = 22;

for (i in p) {
  this[i] = p[i];
}

_current_tab = 1;
// avoid lock up because user is fast clicking on various areas
_busy = false;


this.open = function(id, clear) {

  if (clear && !_busy) {
	  if (tabs = document.getElementsByName("tcar_label_" + _current_tab)) {
	    for (i = 0; i < tabs.length; i++) {
		    tabs[i].className = "tcar_label";
	    }
	  }

	  if (tabs = document.getElementsByName("tcar_label_" + id)) {
	    for (i = 0; i < tabs.length; i++) {
		    tabs[i].className = "tcar_label_trans";
	    }
	  }

	  if (subnav = document.getElementById("tcar_subnav" + _current_tab)) {
	    subnav.style.display = "none";
	  }

	  if (subnav = document.getElementById("tcar_subnav" + id)) {
	    subnav.style.display="";
	  }
  }

  if (clear && _busy) {
    return;
  }
    
	if (id == _current_tab) {
    return;
  }

  _busy = true;

  o1 = document.getElementById("tcar_tab" + id);
	o2 = document.getElementById("tcar_tab" + _current_tab);
	
	o1_old_height = parseInt(o1.style.height.replace(/px/, ""));
	o2_old_height = parseInt(o2.style.height.replace(/px/, ""));
    
  o1_new_height = o1_old_height + this.openStep;
	o2_new_height = o2_old_height - this.openStep;

	if (o2_new_height < this.labelHeight) {
	  o2_new_height = this.labelHeight;
  }

	if (o1_new_height > this.tabHeight) {
	  o1_new_height = this.tabHeight;
  }
    
	o1.style.height = o1_new_height + "px";
	o2.style.height = o2_new_height + "px";
	    
  if (o2.style.height == this.labelHeight + "px") {
	  _busy = false;
	  _current_tab = id;
	  return 1;
	}
	else {
    me = this;
	  window.setTimeout(function() { me.open(id, false); }, this.speed);
	}
}


this.sub = function(pos, clear) {

  if (clear && _busy) {
    return;
  }

	if (s = document.getElementById("tcar_t" + _current_tab)) {
	  _busy=true;
	       
	  current_offset = parseInt(s.style.left.replace(/px/, ""));
	  target_offset = (pos - 1) * -1 * this.tabWidth;
	    
	  if (current_offset > target_offset) {
		  dir = -1;
	  }
	  else {
		  dir = 1;
	  }
	    
	  corridor = Math.abs(current_offset - target_offset);

	  if (corridor < this.subStep) {
		  s.style.left = target_offset + "px";

		  if (pag = document.getElementsByName("tcar_pager" + _current_tab)) {
		    for (i = 0; i < pag.length; i++) {
    			if (pag[i].innerHTML == pos) {
			      pag[i].className = "tcar_pager_active";
			    }
			    else {
			      pag[i].className = "tcar_pager";
			    }
		    }
		  }
		
		  _busy = false;
	  }
	  else {
		  s.style.left = (current_offset + (dir * this.subStep)) + "px";
      me = this;
		  window.setTimeout(function() { me.sub(pos, false); }, this.speed);
	  }
	}
}


}

