// JavaScript Document
var container = document.getElementById('announce');
function startScroll(){
	if(container.timer_id!=undefined) return; //если таймер уже установлен то выходим
	container.scroll_items = container.getElementsByTagName('div'); //внутренние дивы
	if(container.scrollSpeed==undefined) container.scrollSpeed = 30; //скорость прокрутки поумолчанию
	var b = container.scroll_items;
	
	for(var i=0; i<b.length; i++){
		if(b[i].heightBefore==undefined) b[i].heightBefore = -1 * (b[i].offsetTop + b[i].offsetHeight);
		try{ if(b[i].style.top == '') b[i].style.top = '0px'; } catch(err){}
	}
	container.timer_id = window.setInterval('doScroll();',container.scrollSpeed); //запускаем таймер
}
function doScroll(){
	b = container.scroll_items;
	for(var j=0; j<b.length; j++){
		var top = parseInt(b[j].style.top);
		if(top == b[j].heightBefore){ // если сообщение вышло из поля зрения смещаем его в конец очереди
			var new_pos = container.scrollHeight + b[j].heightBefore;
			b[j].style.top = new_pos+'px';
			top = new_pos;
		}
		b[j].style.top = (top - 1)+'px';
	}
}
function stopScroll(){
	window.clearInterval(container.timer_id);
	container.timer_id = undefined;
}
function speedUp(){ //увеличиваем скорость (уменьшаем интервал)
	stopScroll();
	min_interval = 1;
	step = 15;
	if(container.scrollSpeed - step > min_interval) container.scrollSpeed-= step;
	else container.scrollSpeed = min_interval;
	startScroll();
}
function speedDown(){ //уменьшаем скорость (увеличиваем интервал)
	stopScroll();
	max_interval = 100;
	step = 15;
	if(container.scrollSpeed + step < max_interval) container.scrollSpeed+= step;
	else container.scrollSpeed = max_interval;
	startScroll();
}
container.onmouseover = function() { stopScroll(); }
container.onmouseout = function() { startScroll(); }