function startStream(now) {
//  alert ('starting realtime stream');
  stream_on = true;
  $("stream_play").className = "alfa";
  $("stream_pause").className = "";

  $("stream_play").blur();
  if (now == true) {
  	getStream();
  } else {
		setTimeout ("getStream()", 10000);
	}
	return false;
}

function getStream() {
//  alert ('get update');
	if (stream_on) {
		getCnt(stream_cnt + "_999","/?page=" + page_name + (page_name == "bytopics"?"&topic="+topic_id:"") + "&ajax&lite&stream_nid=" + stream_nid+"&uniq="+Math.random(),1)
		setTimeout ("getStream()", 10000);
	}
	return false;
}

function pauseStream() {
	stream_on = false;
  $("stream_pause").className = "alfa";
  $("stream_play").className = "";
  $("stream_pause").blur();
}

function addToStream() {
	if (stream_on) {
	var newsCount = 0;
	if (page_name == "bytopics")
		trg2 = "t"+topic_id
	else
		trg2 = page_name;

	target = $(trg2+"_cnt");
	for (var i =0 ; i < $(stream_cnt+"_cnt").childNodes.length;i++) {
		if ($(stream_cnt+"_cnt").childNodes[i].className == "n_b") {
		  target.insertBefore ($(stream_cnt+"_cnt").childNodes[i], target.firstChild);
		  target.firstChild.setAttribute ("id", "i"+stream_nid + "_"+ newsCount);
			$("i"+stream_nid + "_"+ newsCount).className += " alfa";
		  setTimeout("blinkEl($('i"+stream_nid + "_"+ newsCount +"'))", 300);
		 	newsCount++;
		}
	}
	cleanOldEls();
	return newsCount;
	}
//	alert ("news nodes:" + newsCount);
}

function blinkEl (el) {
	a = el.className.indexOf ("alfa")
	if (a != -1) {
		newName = el.className.substr (0, a-1);		
		num = Number(el.className.substr (a+4));
		if (!num)
			num = 5;
		num++;
		if (num < 10)
			newName += " alfa" + num;
		el.className = newName;
		setTimeout ("blinkEl($('"+el.id+"'))", 300);
	}
}

function cleanOldEls() {
	if (page_name == "bytopics")
		trg2 = "t"+topic_id
	else
		trg2 = page_name;

	el = $(trg2+"_cnt");
	//window.status = el.childNodes.length;
	while (el.childNodes.length > 20) {
		el.removeChild(el.lastChild);
	}
}
