function rollover(idx)
{
	var a;
	
	if(document.all)
		a = document.all("hl");
	else
		a = document.getElementsByName("hl");
	
	if(idx >= a.length)
	{
		return;
	}
	
	for(i=0; i<a.length;i++)
	{
		if(idx != i)
			a[i].style.display = "none";
		else
			a[i].style.display = "block";
	}
}

function writeDate()
{
	document.write((new Date()).toString().substr(0,20));
}


function showPlayer(url)
{
	var win = window.open(url, "rteplayer", "height=560,width=860,status=yes,toolbar=no,menubar=no,location=no");
	win.focus();
}
function showRadioPlayer(url)
{
	var win = window.open(url, "rteradioplayer", "height=645,width=752,status=yes,toolbar=no,menubar=no,location=no");
	win.focus();
}

function showlisting(a,b)
{
	var el1 = document.getElementById("listing" + a);
	var el2 = document.getElementById("listing" + b);
	
	if(el1 != null && el2 != null)
	{
		el1.style.display = "none";
		el2.style.display = "block";
		el2.style.width = "100%";
	}
}


function changeStoryImage (img)
{
	var el = document.getElementById("storyImage" + img);

	for (i=1; document.getElementById("storyImage" + i) != null; i++)
	{
		document.getElementById("storyImageListItem" + i).className = "unselected";
		document.getElementById("storyImage" + i).style.display = "none";
	}
	if(el != null)
	{
		document.getElementById("storyImageListItem" + img).className = "selected";
		el.style.display = "block";
	}

}

function gotoDate(dt)
{
	var new_date = new Date(dt);
	
	if(new_date > today)
		return;
	
	var month = new_date.getMonth()+1;
	if(month < 10) month = "0" + month;

	var date = new_date.getDate();
	if(date < 10) date = "0" + date;

	var new_loc = "/news/" + new_date.getFullYear() + "/" +  month + date + "/" + "index.html";


//	var new_loc = String(window.location);
//	if(re_url.exec(String(window.location)))
//	{
//		new_loc = new_loc.replace(re_url, "/" + new_date.getFullYear() + "/" +  month + date + "/");
//		var pos = new_loc.lastIndexOf("/");
//		new_loc = new_loc.substr(0, pos + 1) + "index.html";
//	}
//	else
//	{
//		var pos = new_loc.lastIndexOf("/");
//		new_loc = new_loc.substr(0, pos + 1) + "/" + new_date.getFullYear() + "/" +  month + date + "/" + "index.html";
//	}
	
	window.location = new_loc;
}

function gotoDateProg(dt)
{
	var new_date = new Date(dt);
	
	if(new_date > today)
		return;
	
	var month = new_date.getMonth()+1;
	if(month < 10) month = "0" + month;
	var date = new_date.getDate();
	if(date < 10) date = "0" + date;

	var new_loc = String(window.location);
	new_loc = "/news/" + new_date.getFullYear() + "/" +  month + date + "/" + PROG_FILENAME + ".html";
	
	window.location = new_loc;
}


var CALENDAR_DATE = new Date();
var PROG_FILENAME="index";
function getCalendarDatesAsync(url, dt)
{
	if(Sarissa)
	{
		CALENDAR_DATE = dt;
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", url, true);
		
		xmlhttp.onreadystatechange = function() {
		    if (xmlhttp.readyState == 4) {
		        renderCalendar(CALENDAR_DATE, "gotoDateProg", xmlhttp.responseText)
		    }
		}
		xmlhttp.send(null);
	}
}

function changeMonth(dt)
{
	dt = new Date(dt);
	getCalendarDatesAsync("/news/" + PROG_FILENAME + "/inc/archive.inc", dt.valueOf());
}



function PrintPreview()
{
	var win = window.open();
	win.document.write("<html>");
	win.document.write("<head>");	
	win.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/news/style/print.css\" />");
	win.document.write("</head>");
	win.document.write("<body>");	
	win.document.write("<img src=\"/news/images/logo_printable_news.gif\">\n");	
	win.document.write("<hr>");		
	win.document.write(document.getElementById("primaryContent").innerHTML);
	win.document.write("<p><strong>Story from RT&Eacute; News:<br />"+document.location+"</strong></p>");
	win.document.write("</body>");
	win.document.write("</html>");	
	win.document.close();
}


function showTop5(typ, cat) {
	Sarissa.updateContentFromURI('http://www.rte.ie/ajaxxml/top5headlines_'+cat+'_'+typ+'.xml', document.getElementById('top5headlines'), null, null, true);

	if (typ == 'ranked') {
		document.getElementById("top5title_read").className = "top5title_off top5_read_border";
		document.getElementById("top5title_ranked").className = "top5title_on";
	}
	else if (typ == 'read') {
		document.getElementById("top5title_ranked").className = "top5title_off top5_ranked_border";
		document.getElementById("top5title_read").className = "top5title_on";
	}
	if (cat == 'news') {
		document.getElementById("top5categories_news").className = "top5categories_on";
		document.getElementById("top5categories_sport").className = "top5categories_off";
		document.getElementById("top5categories_business").className = "top5categories_off";
		document.getElementById("top5categories_arts").className = "top5categories_off";
	}
	else if (cat == 'sport') {
		document.getElementById("top5categories_news").className = "top5categories_off";
		document.getElementById("top5categories_sport").className = "top5categories_on";
		document.getElementById("top5categories_business").className = "top5categories_off";
		document.getElementById("top5categories_arts").className = "top5categories_off";
	}
	else if (cat == 'arts') {
		document.getElementById("top5categories_news").className = "top5categories_off";
		document.getElementById("top5categories_sport").className = "top5categories_off";
		document.getElementById("top5categories_business").className = "top5categories_off";
		document.getElementById("top5categories_arts").className = "top5categories_on";
	}
	else if (cat == 'business') {
		document.getElementById("top5categories_news").className = "top5categories_off";
		document.getElementById("top5categories_sport").className = "top5categories_off";
		document.getElementById("top5categories_business").className = "top5categories_on";
		document.getElementById("top5categories_arts").className = "top5categories_off";
	}
}

function timeSincePublish (y,m,d,h,min,s,z) {

	var rtePublishTime = new Date(y,m-1,d,h,min,s);
	var rtePublishTimeUTC = new Date(rtePublishTime.getTime() - (3600000*z)) ;
	var currTime = new Date();
	var currTimeUTC = new Date(currTime.getTime() + (today.getTimezoneOffset()*60000));
	var diff = currTimeUTC.getTime() - rtePublishTimeUTC.getTime();
	var diffMin = parseInt(diff/60000);
	if (diffMin <= 60) {
		if (diffMin < 0) {
			document.write("0&nbsp;min");
		}
		else {
			document.write(diffMin + "&nbsp;min");
		}
	}
}

function fadeUpNews(element,red,green,blue) {
	if (element.fade) {
		clearTimeout(element.fade);
	}
	element.style.backgroundColor = "rgb("+red+","+green+","+blue+")";
	if (red == 255 && green == 255 && blue == 255) {
		return;
	}
	var newred = red + Math.ceil((255 - red)/20);
	var newgreen = green + Math.ceil((255 - green)/20);
	var newblue = blue + Math.ceil((255 - blue)/20);
	var repeat = function() {
		fadeUpNews(element,newred,newgreen,newblue)
	};
	element.fade = setTimeout(repeat,50);
}

function liveModuleFade(oNode, oTargetElement, update) {
	if (update)
	{
		fadeUpNews(oTargetElement.ownerDocument.getElementById("liveModuleNews_xmlHolder"),212,89,21);
	}
}


function initTabMenu() {
	var menuEl = document.getElementById("tabMenu");
	var children = menuEl.childNodes;
	var done = false;
	var url = window.location;
	if (url == "http://www.rte.ie/news/" || url == "http://www.rte.ie/news/fullindex.html") {
		url = "http://www.rte.ie/news/index.html";
	}
	for(i=0; i<children.length; i++) {
		if (children[i].nodeName.toLowerCase() == "div") {
			var href = children[i].getElementsByTagName("a")[0].getAttribute("href");
			if (href == url ) {
				children[i].className = "on";
				var text = children[i].getElementsByTagName("a")[0].innerHTML;
				children[i].innerHTML = text;
				done = true;
			}
			else if (done == false) {
				children[i].className = "off_l";
			}
			else {
				children[i].className = "off_r";
			}
		}
	}
}








