/**
 * the DtTvB's Standard Helper Script [3555 bytes]
 * @author the DtTvB [http://dttvb.yi.org]
 * @version 1.2
 */

/**
 * Makes a XML HTTP Request obejct
 * @returns XMLHttpRequest
 */
function xmlhttp() {
	if (window.XMLHttpRequest) 
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP"); 
	return false;
}

/**
 * Finds the left position of the element, from the left of the document.
 * @param el An element you want to search for.
 * @returns The left position of el, relative to the left of the document.
 */
function getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent;
	while (el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}

/**
 * Finds the top position of the element, from the top of the document.
 * @param el An element you want to search for.
 * @returns The top position of el relative to the top of the document.
 */
function gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent;
	while (el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

/**
 * Changes opacity of an element.
 * @param el An element you want to set its opacity.
 * @param opx Opacity value (0 = transparent, 100 = opaque)
 */
function opax(el, opx) {
	if (typeof(el.style.filter) != 'undefined') el.style.filter = 'alpha(opacity=' + opx + ')';
	else if (typeof(el.style.opacity) != 'undefined') el.style.opacity = opx / 100;
	else if (typeof(el.style.MozOpacity) != 'undefined') el.style.MozOpacity = opx / 100;
}

/**
 * Ease in (slowly start, and become faster) function, used for animations.
 * @param pos Position of current animation, 0 = the beginning, and 1 = the end.
 * @returns Calculated position.
 */
function easeIn(pos) {
	return pos == 0 ? 0 : Math.pow(pos, 2);
}

/**
 * Ease out (fastly start, and become slower) function, used for animations.
 * @param pos Position of current animation, 0 = the beginning, and 1 = the end.
 * @returns Calculated position.
 */
function easeOut(pos) {
	return pos == 0 ? 0 : 1 - Math.pow(1 - pos, 2);
}

/**
 * Ease in-out (slowly start, become faster, and slow down at the end) function, used for animations.
 * @param pos Position of current animation, 0 = the beginning, and 1 = the end.
 * @returns Calculated position.
 */
function easeInOut(pos) {
	return pos == 1 ? 1 : (pos < 0.5 ? easeIn(pos * 2) / 2 : (easeOut((pos - 0.5) * 2) / 2) + 0.5);
}

/**
 * Animator function. Declare it with new. (e.g. var anim1 = new Animator(...);)
 * To stop the animation, call the function stop. (e.g. anim1.stop();)
 * @param $s Starting value
 * @param $e Ending value
 * @param $i Increment value (between 0 and 1, lesser = slower, but not 0!)
 * @param $f A function that will be called each frame, with the first parameter set to current value, second parameter set to frame number, and third parameter set to a boolean value which tells whether the animation is finished or not.
 * @param $ef [Optional] Easing function, if not specified, it will use linear easing.
 */
function Animator($s, $e, $i, $f, $ef) {
	var $c = 0;
	var $t = 0;
	var $cf = 0;
	if (typeof($ef) == 'undefined') {
		var $ef = function($i) {
			return $i;
		};
	}
	function anime() {
		$c += $i;
		if ($c > 1) $c = 1;
		$f ($s + (($e - $s) * $ef($c)), ++$cf, $c == 1);
		if ($c < 1) setTimeout(anime, 20);
	}
	function stop() {
		clearTimeout ($t);
	}
	if (this != window) {
		this.stop = stop;
	}
	anime ();
}