Animator = function (obj) {
	this.locked = false;
	this.openingComplete = true;
	this.closingComplete = true;
	this.status = 0;
	this.obj = obj;
	this.obj.className += ' height_' + obj.offsetHeight;
	this.obj.style.display = "none";
}

Animator.prototype.getClassParameter = function(targetNode, paramName, defaultValue){
	// get the class parameter from the classname
	var classParameter = targetNode.className;
	// split the classname between the parameter name
	classParameter = classParameter.split(paramName + '_');
	// split the second piece between spaces and take the first part,  if there are two pieces
	classParameter = (classParameter.length>1) ? classParameter[1].split(' ')[0] : null ;
	// return the value
	return (classParameter!=null) ? classParameter : defaultValue ;
}

Animator.prototype.getVisibleState = function(node){
	// what kind of node is this
	switch(node.nodeName.toLowerCase()){
		case 'table' : visibleState='table' ; break;
		case 'thead' : visibleState='table-header-group' ; break;
		case 'tfoot' : visibleState='table-footer-group' ; break;
		case 'tbody' : visibleState='table-row-group' ; break;
		case 'tr' : visibleState='table-row' ; break;
		case 'td' : visibleState='table-cell' ; break;
		case 'th' : visibleState='table-cell' ; break;
		default : visibleState='block';
	}
	// apply the state
	return (document.all && navigator.userAgent.indexOf('Opera')<0) ? 'block' : visibleState;
}

Animator.prototype.close = function(){
	// set the loop status
	this.locked = true;
	this.openingComplete = true;
	this.closingComplete = true;
	
	obj = this.obj;
	// FOR THE CLOSING NODE
	if(obj && this.status == 1){
		// what is the content's height of this object
		closingCurrentHeight = parseInt(obj.offsetHeight);
		closingContentHeight = parseInt(this.getClassParameter(obj, 'height', '0'));
		//alert(closingCurrentHeight);
		// calculate the step-size
		closingStep = Math.round(closingContentHeight / 10);
		// if the current height isn't big enough
		if(closingCurrentHeight > closingStep){
			//alert(obj.style.height);
			this.closingComplete = false;
			// set the container to hide any overflow
			obj.style.overflow = 'hidden';
			// set the container to the current height + a step
			obj.style.height = (closingCurrentHeight - closingStep) + 'px';
		// else
		}else{
			this.closingComplete = true;
			// hide the node
			obj.style.display = 'none';
			// remove the overflow parameter
			obj.style.overflow = 'visible';
			// set the height to automatic
			obj.style.height = 'auto';
			// RESET THE PARENT NODE (since the animation loop prevents this to be done in it's regular function "toggleNext"
			//titleNode = tnn.titleNode;
			//if(titleNode.className) titleNode.className = titleNode.className.replace('active','link');
			//if(titleNode.src!=null) titleNode.src = titleNode.src.replace('active','link');
			//tnn.titleNode = null;
		}
	}
	if(this.closingComplete){
		// restore the click lock
		this.locked = false;
		this.status = 0;
	// else
	}else{
		// call this function again
		setTimeout("document.getElementById('" + obj.id + "').animator.close();", 10);
	}
}

Animator.prototype.open = function(){
	// FOR THE OPENING NODE
	obj = this.obj;
	this.locked = true;
	this.openingComplete = true;
	this.closingComplete = true;
	if(obj && this.status == 0){
		// what is the content's height of this object
		openingCurrentHeight = parseInt(obj.offsetHeight);
		//alert(openingCurrentHeight);
		openingContentHeight = parseInt(this.getClassParameter(obj, 'height', '0'));
		// calculate the step-size
		openingStep = Math.round(openingContentHeight / 10);
		// if the current height isn't big enough
		//alert(openingCurrentHeight + ' - ' + openingContentHeight);
		if(openingCurrentHeight <= openingContentHeight - openingStep){
			//alert(obj.style.height);
			this.openingComplete = false;
			// set the container to hide any overflow
			obj.style.overflow = 'hidden';
			// set the container to the current height + a step
			obj.style.height = (openingCurrentHeight + openingStep) + 'px';
			// make the node visible
			obj.style.display = this.getVisibleState(obj);
		// else
		}else{
			this.openingComplete = true;
			// remove the overflow parameter
			obj.style.overflow = 'visible';
			// set the height to automatic
			obj.style.height = 'auto';
		}
	}
	// REPEAT OR END
	// if both limits are reached
	if(this.openingComplete){
		// restore the click lock
		this.locked = false;
		this.status = 1;
	// else
	}else{
		// call this function again
		setTimeout("document.getElementById('" + obj.id + "').animator.open();", 10);
	}
}
