/**
* phpAnvil Tools
*
* LICENSE
*
* This source file is subject to the new BSD license that is
* bundled with this package in the file LICENSE.txt. It is also
* available on the Internet at:  {@link http://www.phpanvil.com/LICENSE.txt}
*
* @package 		phpAnvilTools
* @copyright 	Copyright (c) 2010 Nick Slevkoff ({@link http://www.slevkoff.com})
* @license		http://www.phpanvil.com/LICENSE.txt		New BSD License
*/

var atr_prefixID = 'atr';
var atr_currentFrame = 1;
var atr_maxFrames = 0;
var atr_durationMS = 5000;
var atr_transitionMS = 1000;

function atui_startRotator(prefixID, maxFrames, durationMS, transitionMS) {
	atr_prefixID = prefixID;
	atr_maxFrames = maxFrames;
	atr_durationMS = durationMS;
	atr_transitionMS = transitionMS;
//	atui_show(atr_prefixID + atr_maxFrames);
	atui_rotate(atr_maxFrames);
}

function atui_rotate(fromFrame) {
	var toFrame = fromFrame;
	toFrame++;

	if (toFrame > atr_maxFrames) {
		toFrame = 1;
	}

	if (atr_maxFrames > 1) {
		atui_fade(atr_prefixID + fromFrame, atr_prefixID + toFrame, atr_transitionMS);
		setTimeout("atui_rotate(" + toFrame + ")", atr_durationMS + atr_transitionMS + atr_transitionMS);
	} else {
		atui_fadeIn(atr_prefixID + '1', 100);
//		atui_show(atr_prefixID + '1');
	}
}

function atui_fade(currentID, nextID, transitionMS) {
	atui_fadeOut(currentID, transitionMS);
	setTimeout("atui_fadeIn('" + nextID + "'," + transitionMS + ")", transitionMS);
}

function atui_fadeIn(id, transitionMS) {
	//speed for each frame
	var speed = Math.round(transitionMS / 100);
	var timer = 1;

	setTimeout("atui_show('" + id + "')",(timer * speed));
	timer++;

	for(i = 0; i <= 100; i++)
		{
		setTimeout("atui_changeOpacity(" + i + ",'" + id + "')",(timer * speed));
		timer++;
	}
}

function atui_fadeOut(id, transitionMS) {
	//speed for each frame
	var speed = Math.round(transitionMS / 100);
	var timer = 0;

	for(i = 100; i >= 0; i--) {
		setTimeout("atui_changeOpacity(" + i + ",'" + id + "')",(timer * speed));
		timer++;
	}
	setTimeout("atui_hide('" + id + "')",(timer * speed));
}

function atui_changeOpacity(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function atui_hide(id) {
	document.getElementById(id).style.display = "none";
}

function atui_show(id) {
	document.getElementById(id).style.display = "block";
}

