/*CS This is for the Placement Regions Local Resources page. This is so we can have one file to control these headlines and the rotating headlines sidebar*/

//Write info to page
function createHeadlinesDiv(xmlDoc) {

	var headlines = xmlDoc.getElementsByTagName('headlines');
	var headlinesTable = null;
	
	if(document.getElementById('recentHeadlines')) {
		headlinesTable = document.getElementById('recentHeadlines');
		var table = document.createElement('table');
		table.setAttribute('id','statsTable');
		table.setAttribute('cellPadding','4');
		table.setAttribute('cellSpacing','0');
		table.setAttribute('border','0');
		table.setAttribute('width','320');
		var tbody = document.createElement('tbody');
		var thr = document.createElement('tr');
		var th = document.createElement('th');
		th.setAttribute('scope','col');
		var thHeader = document.createTextNode('Recent Headlines');
		
		headlinesTable.appendChild(table);
		table.appendChild(tbody);
		tbody.appendChild(thr);
		thr.appendChild(th);
		th.appendChild(thHeader);
	}
	
	var newsItem = headlines[0].getElementsByTagName("newsItem");
	var itemNum;
	var hCount = 0;
		if(newsItem.length >= 5){
			itemNum = 5;
		}
		else {
			itemNum = newsItem.length;
		}
		
		for (i=0; i<newsItem.length; i++) {
			var htmlPath= newsItem[i].getAttribute("html"); //Path to html page
			var headline = document.createTextNode(newsItem[i].getAttribute("headline")); //Headlinetext
		
			var URLpath = newsItem[i].getAttribute("html");
			var URL = '"'+URLpath+'"';		
			var headlineTxt = newsItem[i].getAttribute("headline").toString();
	
			if (hCount < itemNum) {
				fader[2].message[i] = "<div onClick='window.open("+URL+")'>"+headlineTxt+" &raquo;</div>";
				hCount++;
			}
			
			if(headlinesTable != null) {
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				if (i%2 == 0) {
					td.setAttribute('class','altCol');
					td.setAttribute('className','altCol');
				}
				var a = document.createElement('a');
				a.setAttribute('href',URLpath);
				a.setAttribute('target','_blank');
				
				tbody.appendChild(tr);
				tr.appendChild(td);
				td.appendChild(a);
				a.appendChild(headline);				
			}
		}
}