// Cre8ted by RE

var scroll_delay = new Array();
var scroll_frame = new Array();
var scroll_func = new Array();
var scroll_func2 = new Array();
var scroll_func3 = new Array();
var scroll_ids = new Array();
var scroll_nodecount = new Array();
var scroll_pause = new Array();
var scroll_random = new Array();
var scroll_speed = new Array();
var scroll_step = new Array();
var scroll_stop = new Array();
var scroll_type = new Array();

function scrollerInit(frame, tag, type, speed, delay, step, random) {
	if (ie || dom) {
		var ai = scroll_ids.length;
		scroll_ids[scroll_ids.length] = tag;

		scroll_frame[ai] = '';
		if (frame != null)
			scroll_frame[ai] = frame;

		scroll_type[ai] = 'vertical';
		if (type != null)
			scroll_type[ai] = type;

		scroll_speed[ai] = 20;
		if (speed != null)
			scroll_speed[ai] = speed;

		scroll_delay[ai] = 3000;
		if (delay != null)
			scroll_delay[ai] = delay;

		scroll_step[ai] = 2;
		if (step != null)
			scroll_step[ai] = step;

		scroll_random[ai] = false;
		if (random != null)
			scroll_random[ai] = eval(random);

		scroll_stop[ai] = false;
		scroll_func[ai] = function() { scrollerStart(ai) };
		addEvent(window, 'load', 'scroll_func[' + ai + ']');
		return ai;
	}
}

function scrollerMessagePrepare(ai, m) {
	if (scroll_stop[ai] != true && m > 0) {
		var o, o2;
		if ((o = findObj(scroll_ids[ai], scroll_frame[ai])) != null && (o2 = findObj(scroll_ids[ai] + 'a_m' + m, scroll_frame[ai])) != null) {
			o2.style.display = '';
			o2.style.position = 'absolute';
			o2.style.clip = 'rect(0 ' + o.offsetWidth + 'px ' + o.offsetHeight + 'px 0)';
			if (scroll_type[ai] == 'vertical') {
				o2.style.left = o.offsetWidth + 'px';
				//o2.style.left = '0px';
				o2.style.top = o.offsetHeight + 'px';
			}
			else {
				o2.style.left = o.offsetWidth + 'px';
				o2.style.top = o.offsetHeight + 'px';
				//o2.style.top = '0px';
				o2.style.whiteSpace = 'nowrap';
			}
		}
	}
}

function scrollerMessageState(ai, m) {
	if (scroll_stop[ai] != true && m > 0) {
		var o;
		if ((o = findObj(scroll_ids[ai] + 'a_m' + m, scroll_frame[ai])) != null) {
			o.style.display = '';
			o.style.left = '0px';
			o.style.top = '0px';
		}
	}
}

function scrollerMove(ai, mc, mp) {
	if (scroll_stop[ai] != true) {
		if (scroll_pause[ai])
			setTimeout('scrollerMove(' + ai + ', ' + mc + ', ' + mp + ')', 500);
		else {
			var mn, o, o2;
			mn = mc + 1;
			if ((o2 = findObj(scroll_ids[ai] + 'a_m' + mp, scroll_frame[ai])) != null) {
				if (scroll_type[ai] == 'vertical') {
					if (parseInt(o2.style.top) >= o2.offsetHeight * -1)
						o2.style.top = parseInt(o2.style.top) - scroll_step[ai] + 'px';
				}
				else {
					if (parseInt(o2.style.left) >= o2.offsetWidth * -1)
						o2.style.left = parseInt(o2.style.left) - scroll_step[ai] + 'px';
				}
			}
			if ((o = findObj(scroll_ids[ai] + 'a_m' + mc, scroll_frame[ai])) != null) {
				if (mc == mp)
					mp = 0;
				if (scroll_type[ai] == 'vertical') {
					if (parseInt(o.style.top) > 0 && parseInt(o.style.top) <= scroll_step[ai]) {
						scrollerMessagePrepare(ai, mp);
						scrollerMessageState(ai, mc);
						if (findObj(scroll_ids[ai] + 'a_m' + mn, scroll_frame[ai]) == null)
							mn = 1;
						setTimeout('scrollerMove(' + ai + ', ' + mn + ', ' + mc + ')', scroll_delay[ai]);
					}
					else if (parseInt(o.style.top) >= o.offsetHeight * -1) {
						o.style.left = '0px';
						o.style.top = parseInt(o.style.top) - scroll_step[ai] + 'px';
						setTimeout('scrollerMove(' + ai + ', ' + mc + ', ' + mp + ')', scroll_speed[ai]);
					}
				}
				else {
					if (parseInt(o.style.left) > 0 && parseInt(o.style.left) <= scroll_step[ai]) {
						scrollerMessagePrepare(ai, mp);
						scrollerMessageState(ai, mc);
						if (findObj(scroll_ids[ai] + 'a_m' + mn, scroll_frame[ai]) == null)
							mn = 1;
						setTimeout('scrollerMove(' + ai + ', ' + mn + ', ' + mc + ')', scroll_delay[ai]);
					}
					else if (parseInt(o.style.left) >= o.offsetWidth * -1) {
						o.style.left = parseInt(o.style.left) - scroll_step[ai] + 'px';
						o.style.top = '0px';
						setTimeout('scrollerMove(' + ai + ', ' + mc + ', ' + mp + ')', scroll_speed[ai]);
					}
				}
			}
		}
	}
}

function scrollerStart(ai) {
	var o, o2;
	if ((o = findObj(scroll_ids[ai], scroll_frame[ai])) != null && (o2 = findObj(scroll_ids[ai] + 'a', scroll_frame[ai])) != null) {
		o.style.position = 'relative';
		o.style.overflow = 'hidden';
		if (o.style.width == '')
			o.style.width = '100%';

		i = ai;
		if (scroll_type[ai] == 'vertical') {
			scroll_func2[i] = function() { scroll_pause[ai] = false };
			addEvent(o, 'mouseout', 'scroll_func2[i]');
			scroll_func3[i] = function() { scroll_pause[ai] = true };
			addEvent(o, 'mouseover', 'scroll_func3[i]');
		}

		o2.style.height = o.offsetHeight;
		o2.style.width = o.offsetWidth;

		var mc, mn
		var cn = o2.childNodes;
		j = 0;
		for (i=0; i<cn.length; i++) {
			//add ids to child nodes
			o = cn[i];
			if (o.nodeType == 1) {	//html element
				j++;
				o.setAttribute('id', scroll_ids[ai] + 'a_m' + j);
				scrollerMessagePrepare(ai, j);
			}
		}
		mc = 1;
		scroll_nodecount[ai] = j;
		if (eval(scroll_random[ai])) {
			//select random first node
			mc = Math.ceil(Math.random()*scroll_nodecount[ai]);
		}

		if (mc > 0) {
			//show first node
			scrollerMessageState(ai, mc);
			mn = mc + 1;
			if (findObj(scroll_ids[ai] + 'a_m' + mn, scroll_frame[ai]) == null)
				mn = 1;
			if (mc == mn && (o2 = findObj(scroll_ids[ai] + 'a', scroll_frame[ai])) != null) {
				//duplicate single message
				mn = mc + 1;
				o = o.cloneNode(true);
				o.setAttribute('id', scroll_ids[ai] + 'a_m' + mn);
				o2.appendChild(o);
				scrollerMessagePrepare(ai, mn);
			}
			setTimeout('scrollerMove(' + ai + ', ' + mn + ', ' + mc + ')', scroll_delay[ai]);
		}
	}
}
