// JavaScript Document

function init() {
	window.setTimeout("initUpBox()", 1000);
}

function initUpBox () {
	var bc = document.getElementById("uptodate");
	bc.innerHTML = "";
	//window.alert(dates.length);
	for(var i = 0; i < 3; i++) {
		if (dates.length >= i) {
			var upbox = document.createElement("div");
			upbox.className = "upbox";
			upbox.setAttribute("id", "upbox"+dates[i]["id"]);
			upbox.setAttribute("onclick", "window.location='" + folderAdd + "pages/news.php?updid=" + dates[i]["id"] + "'");
			var div = document.createElement("div");
			var b = document.createElement("b");
			var txt = document.createTextNode(dates[i]["date"]);
			b.appendChild(txt);
			div.appendChild(b);
			var br = document.createElement("br");
			upbox.appendChild(br);
			var p = document.createElement("p");
			if (dates[i]["subject"].length > 15)
				var txt = document.createTextNode(dates[i]["subject"].substr(0, 20)+"...");
			else 
				var txt = document.createTextNode(dates[i]["subject"]);
			p.appendChild(txt);
			div.appendChild(p);
			upbox.appendChild(div);
			bc.appendChild(upbox);
		}
	}	
	window.setTimeout("slideUpBox()", 3000);
}

function slideUpBox() {	
	Effect.SlideUp('upbox'+dates[topPos]["id"]);
	topPos++;
	if (topPos == dates.length)
		topPos = 0;
	
	
	var cp = topPos+2;
	if (cp == dates.length)
		cp = 0;
	if (cp > dates.length)
		cp = 1;
	
	var bc = document.getElementById("uptodate");
	
	var upbox = document.createElement("div");
	upbox.className = "upbox";
	upbox.setAttribute("id", "upbox"+dates[cp]["id"]);
	upbox.setAttribute("onclick", "window.location='" + folderAdd + "pages/news.php?updid=" + dates[cp]["id"] + "'");
	upbox.style.display = "none";
	var div = document.createElement("div");
	var b = document.createElement("b");
	var txt = document.createTextNode(dates[cp]["date"]);
	b.appendChild(txt);
	div.appendChild(b);
	var br = document.createElement("br");
	upbox.appendChild(br);
	var p = document.createElement("p");
	var txt = document.createTextNode(dates[cp]["subject"]);
	p.appendChild(txt);
	div.appendChild(p);
	upbox.appendChild(div);
	bc.appendChild(upbox);
	Effect.SlideDown("upbox"+dates[cp]["id"]);
	
	window.setTimeout("slideUpBox()", 3000);
	/*new Effect.Move('upbox2', { x: 0, y: -48, mode: 'relative' });
	new Effect.Move('upbox2', { x: 0, y: -48, mode: 'relative' });
	new Effect.Move('upbox3', { x: 0, y: -48, mode: 'relative' });*/
}
