var currentLine = 0;
var maxLine;
var currentPos = -1;
var titleLength;
var Lines;
var lineUrls;
var ndelay;
var marginTop;
var fontSize
var hrHeight;
var hrMargin;
var paddingTag;
var divTag;
var browserisIE;
var bgColor; //	

/*Ezt a f?ggv?nyt kell megh?vni az oldalon.
	akts 		: azt aktualit?sokat tartalmaz? t?mb
	urls	 	: az aktualit?sokhoz taroz? url-ek
	tLenght 	: max ennyi karakter jelenhet meg egy sorba. Az enn?l hosszabb linkeket t?bb sorba t?rdeli
	max 		: Az egyszerrre l?that? sorok sz?ma
	delay 		: k?t mozg?s k?z?tt eltelt id? millisecben
	margintop 	: a linkek k??z??tti t??rk??z
	fontsize 	: bet??m??ret
	hrheight 	: az elv??laszt?? vonal vastags??ga
	hrmargin 	: t??rk??z az elv??laszt?? vonal ??s a link k??z??tt
*/
function doWrite(akts,urls,tLength,max,delay,bgcolor/*,margintop,fontsize,hrheight,hrmargin*/){
	titleLength	= tLength;
	maxLine = max;
	ndelay = delay;
	bgColor =bgcolor;//'004B8F';
	marginTop = 5;//margintop;
	fontSize = 10;//fontsize;
	hrHeight = 1;//hrheight;
	hrMargin = 5;//hrmargin;
	
	browserisIE = navigator.appName == 'Microsoft Internet Explorer' ? true :false;

	moveUp(akts,urls);		
}

function putCover(position){
/*	oldCover = document.getElementById('cover');
	root = document.getElementById('aktualitas');
	if (oldCover != null) root.removeChild(oldCover);
	var cover = document.createElement('div');
	//cover.setAttribute("style","position:relative; top:-"+position+"px; height:15px; background-color:#"+bgColor+";");
	cover.appendChild(document.createTextNode('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'));
	cover.style.position='relative';
	cover.style.top=-position+"px;";
	cover.style.height=fontSize	;
	cover.style.background-color=bgColor;
	cover.style.className='CoverClass';
	cover.id="cover";
	root.appendChild(cover);
	
	//bottom cover
	oldBottomCover = document.getElementById('bottomCover');
	root = document.getElementById('aktualitas');
	if (oldBottomCover != null) root.removeChild(oldBottomCover);
	var bottomCover = document.createElement('div');
	var tempFontSize = fontSize+18;
	var tempPosition = -position+maxLine*12;
	bottomCover.setAttribute("style","position:relative; top:"+tempPosition+"px; height:"+tempFontSize+"px; background-color:#"+bgColor+";");
	bottomCover.style.position='relative';
	bottomCover.style.top=tempPosition;
	bottomCover.style.height=tempFontSize;
	bottomCover.style.background=bgColor;
	bottomCover.id="bottomCover";
	bottomCover.appendChild(document.createTextNode('aaaaaaaaaaaaaaaaaaaa'));
	root.appendChild(bottomCover);*/
}

/*ez a rekurz?v f?ggv?ny val?sy?tja meg a v?gtelen ciklust*/
function moveUp(akts,urls){
	if (currentPos == -1){
		if (Lines!=null && Lines[currentLine] == 'hr'){
			currentPos = 22;	
							//alert(currentLine);		
		}
		else{
			if (Lines!=null && Lines[currentLine-1]=='hr'){
				currentPos = 2*hrMargin+hrHeight-marginTop-1;
			
//				currentPos = 16;		
			}
			else{
//				currentPos = fontSize+marginTop+1;
				currentPos = 16;
			}
		}
		deleteLinks();
		createLinks(akts,urls);
	}
	else{
		changePos(currentPos);
	}

	currentPos--;
	setTimeout("moveUp(akts,urls)",ndelay);
	document.body.style.cursor='default';
}

/*t?rli a DOM-b?l az aktualit?sokhoz tartoz? linkeket ?s a hr-eket*/
function deleteLinks(){
document.body.style.cursor='default';
	var root = document.getElementById('aktualitas');
	var divs = root.getElementsByTagName('div');
	for (var i=0;i<divs.length;i++){

		if ( (divs[i].nodeName.toLowerCase() == 'div') &&
	         ( (divs[i].getAttribute('class') == 'Title') || (divs[i].getAttribute('class') == 'Title2') || (divs[i].getAttribute('class') == 'hr') ) )
		{
//			alert(divs[i].getAttribute('class'));
			root.removeChild(divs[i]);
			//az?rt kell, mert a t?rl?sel eggyel el?r?bb ker?lnek a t?r?lt elem ut?ni elemek
			i--;
		 }
	}

}

/*Felfel? mozgatja a linkeket, ?s a hr-eket */
function changePos(currentPos){
document.body.style.cursor='default';
	var divs = document.getElementById('aktualitas').childNodes;
	for (var i=1;i<divs.length;i++){

		if  (divs[i].nodeName.toLowerCase() == 'div'){
			if  ( ( divs[i].getAttribute('class') == 'Title' ) || (divs[i].getAttribute('class') == 'Title2') ){

				if (!browserisIE) divs[i].setAttribute('style','position:relative; top:'+currentPos+'px;')
				
				divs[i].style.position = 'relative';
				divs[i].style.top = currentPos+"px";
/*				divs[i].style.margin.top = 5;
				divs[i].style.margin.bottom = 0;*/
		 	}
		 	if  (divs[i].getAttribute('class') == 'hr') {
		 		divs[i].setAttribute('style','position:relative; top:'+currentPos+'px;');
		 		divs[i].firstChild.setAttribute('style','margin: '+hrMargin+'px 0;');

				divs[i].style.position = 'relative';
				divs[i].style.top = currentPos+"px";
				divs[i].firstChild.style.margin.top = hrMargin;
				divs[i].firstChild.style.margin.bottom = 0;
		 	}
		}

	}
}

/*?ssze?ll?tja azt a t?mb?t, amely a megjelen?tend? sorokat tartalmazza(linkek, hr-ek) */
function createLinks(akts,urls){
	Lines = new Array();
	lineUrls = new Array();
	var j = 0;

	for (var i=0;i<akts.length;i++){
		//berak egy elv??laszt??elemet
		Lines[j] = 'hr';
		j++;

		//elk??sz??ti a k??vetkez?? linket
		title = akts[i];
		while (title.length>titleLength){

			var k = titleLength;
			var splitIndex = titleLength;
			while ( (title.charAt(k) != ' ') && (k>0) ) k--;
			if (k > 0) splitIndex = k+1;
			
			Lines[j] = title.substring(0,splitIndex);

			lineUrls[j] = urls[i];
			j++;
			title = title.substring(splitIndex);
		}
		Lines[j] = title;

		lineUrls[j] = urls[i];
		j++;
	}	

	writeLinks(); 
}

/*Berakja a DOM-ba a megjelen?tend? elemeket */
function writeLinks(){
	var	max = Lines.length;
	var j = currentLine;

//	var hr = 2*hrMargin+hrHeight-marginTop-1;
	var hr = 13;
//	var hr = 6;
	var div = fontSize+marginTop+1;
	var div = 17;
	var position = 0;
	var last;
	var s='';
	var newA;
	var newOuterDiv;
	for (var i=0;i<maxLine;i++){
		if (Lines[j] =='hr'){
			var newDiv = document.createElement('div');
			newDiv.setAttribute('class','hr')
			newDiv.className='hr';
			var newHr = document.createElement('hr');
			newHr.setAttribute('style','margin-top:'+hrMargin+'px; height:'+hrHeight+'px;');
			newHr.style.margin.top=hrMargin;
			newHr.style.margin.bottom=0;
			newDiv.setAttribute('style','position:relative; top:'+currentPos+'px;');
			newDiv.style.position='relative';
			newDiv.style.top = currentPos+"px";
//			newDiv.style.height = hrHeight;
//			newDiv.style.margin.top = hrMargin;
			newDiv.appendChild(newHr);
			document.getElementById('aktualitas').appendChild(newDiv);		
			
			position+=hr;
			last=10;
			s+='hr ';
		}
		else{
			
			if ( (j>0 && Lines[j-1] == 'hr') || (j==0) || (i==0) ){
/*				newDiv.setAttribute('class','Title');
				newDiv.className='Title';*/
				newOuterDiv = document.createElement('div');
				newOuterDiv.setAttribute('class','Title');
				newOuterDiv.className='Title';
				
				newOuterDiv.setAttribute('style','font:bold 10px Verdana; position:relative; top:'+currentPos+'px;')
				newOuterDiv.style.position='relative';
				newOuterDiv.style.top=currentPos+"px";
/*				newOuterDiv.style.margin.top=marginTop;
				newOuterDiv.style.margin.bottom=0;
	*/			
				newA = document.createElement('a');
				newA.setAttribute('href',lineUrls[j]);
				newA.setAttribute('style','font-size: '+fontSize+'px;');
				newA.style.fontSize = fontSize+"px";
				newOuterDiv.appendChild(newA);
//				alert(newOuterDiv.getAttribute('class'));
			}else{
/*				newDiv.setAttribute('class','Title2');
				newDiv.className='Title2';*/
			}
			
			var newDiv = document.createElement('div');
/*			newDiv.setAttribute('style','font:bold 10px Verdana; margin-top:'+marginTop+'px; margin-bottom:0px;')
			newDiv.style.margin.top = marginTop;
			newDiv.style.margin.bottom = 0;*/
		/*	newDiv.setAttribute('style','font:bold 10px Verdana; position:relative; top:'+currentPos+'px; margin-top:'+marginTop+'px; margin-bottom:0px;')
			newDiv.style.position='relative';
			newDiv.style.top=currentPos;
			newDiv.style.margin.top=marginTop;
			newDiv.style.margin.bottom=0;
*/
			
/*			var newA = document.createElement('a');
			newA.setAttribute('href',lineUrls[j]);
			newA.setAttribute('style','font-size: '+fontSize+'px;');
			newA.style.fontSize = fontSize;*/
			var newTitle = document.createTextNode(Lines[j]);
/*			newA.appendChild(newTitle);
			newDiv.appendChild(newA);	*/
			newDiv.appendChild(newTitle);
			newA.appendChild(newDiv);
			document.getElementById('aktualitas').appendChild(newOuterDiv);
			
			position+=div;
			last=5;
			s+='div';
		}
		j++;
		if (j == max) j = 0;
	}
//	alert(s+'  hr:'+hr+' div:'+div+' pos:'+position+' last:'+last);
	last = 0;
	putCover(position+last);
	currentLine++;
	if (currentLine == max)	 currentLine = 0;
}

