// xonTAB JavaScript API (Animation) v1.0

// This is the main Animation function
function st_animation(elem, css, frame, to, speed, rate, slow) {
	if (Math.abs(to-frame) > 0) {
		// if slow is set to true the animation will slow down
		if ((slow) && (Math.abs(to-frame) <= Math.abs(rate*5))) {
			speed+=5;
			if (rate>0) {
				rate-=3;
				if (rate<1) rate = 1;
			} else {
				rate+=3;
				if (rate>-1) rate = -1;
			}
		}
		if (Math.abs(to-frame) < Math.abs(rate)) {
			rate = Math.abs(to-frame);
		}
		// Set rate to + or - according to the values of frame and to
		if (to >= frame) { 
			rate = Math.abs(rate);
		} 
		else {
			rate = -Math.abs(rate); 
		}
		frame+=rate;
		switch (css) {
			// Increase Width Animation
			case "width" : 
				elem.style.width = frame+'px';
				break;
			// Increase Height Animation
			case "height" : 
				elem.style.height = frame+'px';
				break;
			// Move Top Animation
			case "top" : 
				elem.style.top = frame+'px';
				break;
			// Move Left Animation
			case "left" : 
				elem.style.left = frame+'px';
				break;
			// Text Indent Animation
			case "textIndent" : 
				elem.style.textIndent = -frame+'px';
				break;
			// Text Indent Animation
			case "textScroll" : 
				elem.style.clip = 'rect('+frame+'px,auto,auto,auto)';
				break;
			// Opacity Animation
			case "opacity" : 
				elem.style.opacity = frame;
				elem.style.filter = 'alpha(opacity='+frame*100+')';
				break;
			case "opacitynoie" : 
				elem.style.opacity = frame;
				break;
		}
		var s = setTimeout(function(){st_animation(elem, css, frame, to, speed, rate, slow)},speed);
		return s;
	}
}