$$('#tabs .ce_text').each(function(obj) {
  if(!obj.hasClass('tabnav')) {
    small = new Element('small', {'html': obj.getHeight()});
    small.inject(obj);
    obj.setStyle('height', 0);
  }
});

var clicks = 0;

$$('#tabs li').addEvent('click', function() {
   
   var active = this.hasClass('active') ? true : false;
   
   $$('#tabs li').removeClass('active');
   if(active === false) this.addClass('active');
   
   var count  = 0;
   var name   = this.innerHTML;
   var target = '';
   $$('#tabs li').each(function(obj) {
      count++;
      if(obj.innerHTML== name) target = count + 1;
   });
   count=0;
   $$('#tabs .ce_text').each(function(obj) {
      count++;
      if(count == target) {
	 if(active === true) {
	    obj.tween('height', 0);
	    clicks = 0;
	 }else{
	    height = obj.getChildren('small')[0].innerHTML;
	    if(clicks == 0) { obj.tween('height', height); }else{ setTimeout(function() { obj.tween('height', height); }, 500); }
	    clicks++;
	    console.log(clicks);
	 }
      }else{
	 if(!obj.hasClass('tabnav')) obj.tween('height', 0);
      }
   });
});
