BEHAVE = {
	// autoscroll - true, on-demand - false
	'auto': true,
	// vertical - true, horizontal - false
	'vertical': true,
	// scrolling speed, pixels per 40 milliseconds;
	// for auto mode use negative value to reverse scrolling direction
	'speed': 1,
	// pause afther
	'pause_a': 0,
	// pause before
	'pause_b': 4
};

n_timeout= n_interval = n_pos = n_cur = prior = 0;

var ajust = BEHAVE.vertical ?
	function () { getElem('mn').style.top = n_pos } :
	function () { getElem('mn').style.left = n_pos }

function getElem(div) {
	return document.getElementById ? document.getElementById(div) : document.all[div]
}

function init(n_2measure) {
	o_cont = getElem('mnc');
	var b_fl = true, e_frm, k = 0, i;
	if (n_2measure != null)
		ITEMS[n_2measure].height = BEHAVE.vertical ? o_cont.offsetHeight : o_cont.offsetWidth;
	for (i = ITEMS.length - 1; i >= 0; i--) {
		if (!ITEMS[i].height) {
			if (ITEMS[i].content) {
				o_cont.innerHTML = getElem(ITEMS[i].content).innerHTML;
				return setTimeout("init(" + i + ")", 100);
			}
			b_fl = false;
		}
 	}
	if (!b_fl) 
		return setTimeout("init()", 100);
	main = getElem('mn');
	main.style.visibility='visible';
	if (BEHAVE.auto)
		move(0);
}

// internal control methods
function move(p) {
	if (prior <= p && n_interval == 0) {
		prior = 0
		n_interval = setInterval("roll()", 40)
	}
}

function stop(p) {
	if (prior < p) 
		prior = p
	if (n_timeout != 0) {
		clearTimeout(n_timeout)
		n_timeout = 0
	}
	if (n_interval != 0) {
		clearInterval(n_interval)
		n_interval = 0
	}
}

function sleep(delay) {
	stop(0);
	n_timeout=setTimeout("move_s()", delay * 1000)
}

function move_s() {
	n_pos -= n_step;
	ajust();
	move(0);
}

function roll() {
	var item = ITEMS[n_cur];
	var h = parseInt(parent.document.getElementById("NewsTicker").height);
	var w = parseInt(parent.document.getElementById("NewsTicker").width);
	var n_wheight = BEHAVE.vertical ? h : w;

	if (n_pos > n_wheight) {
		item = ITEMS[n_cur = n_cur == 0 ? ITEMS.length - 1 : n_cur - 1]
		n_pos = -item.height
		item.supply()
	}
	else if (n_pos < - item.height) {
		item = ITEMS[n_cur = n_cur == ITEMS.length - 1 ? 0 : n_cur + 1]
		n_pos = n_wheight
		item.supply()
	}
	var delta = n_wheight - item.height
	if (BEHAVE.pause_a > 0 && n_pos >= delta && n_pos < n_astep + delta) {
		n_pos = delta
		ajust()
		return sleep (BEHAVE.pause_a)
	}
	if (BEHAVE.pause_b > 0 && n_pos >= 0 && n_pos < n_astep) {
		n_pos = 0
		ajust()
		return sleep (BEHAVE.pause_b)
	}
	n_pos -= n_step
	ajust()
}

function supp () {
	o_cont = getElem('mnc');
	o_cont.innerHTML = getElem(this.content).innerHTML;
	ajust()
}

function start() {
	o_container = parent.document.getElementById ?
		parent.document.getElementById("NewsTicker") : parent.document.all["NewsTicker"];
	n_step = BEHAVE.speed != 0 ? BEHAVE.speed : 1;
	n_astep = Math.abs(n_step);
	
	for (var i in ITEMS) {
		ITEMS[i].supply = supp;
	}
	
	if (BEHAVE.auto) {
		document.body.onmouseover = function () { stop(1) }
		document.body.onmouseout = function () { move(1) }
	} else {
		arrup.onmouseover = function () {
			n_step = -n_astep;
			move(1)
		}
		arrdn.onmouseover = function () {
			n_step = n_astep;
			move(1)
		}
		arrdn.onmouseout = arrup.onmouseout = function () {
			n_pos += n_step
			stop(1)
		}
	}
	init();
}

