
var contentDivs = [];
var listItems = [];
var articleIndex = "0"; 

// show next article as selected from the article nav
function showArticle(e){
	articleIndex = parseInt(this.id);
	showContent(articleIndex);
}

// show next article
function showNextArticle(){
	articleIndex++;
	showContent(articleIndex);
}

// show previous article
function showPreviousArticle(){
	articleIndex--;
	showContent(articleIndex);
}

// render the article content
function showContent(article) { 

	// first, close any open articles
	for (var i = 0; i < contentDivs.length; i++) { 
	    contentDivs[i].style.display = "none";
	    listItems[i].className = "";
	}
	// render the selected article
	contentDivs[article].style.display = "block";
	listItems[article].className = "active";
	
	// set the prev/next control visibility based on the 
	// current position within the article index
	if (article > 0)
		document.getElementById("previousCtrl").style.display = "block";
	else 	
		document.getElementById("previousCtrl").style.display = "none";
	
	if (article < (listItems.length -1))
		document.getElementById("nextCtrl").style.display = "block";
	else 	
		document.getElementById("nextCtrl").style.display = "none";
}

function initPage(){

	// build references to articles 
	contentDivs = document.getElementById("column-content").getElementsByTagName("div");
	
	// build references to article navigation elements
	listItems = document.getElementById("column-list").getElementsByTagName("li");
	listItems[0].className = "active";
	
	// show the default article
	contentDivs[0].style.display = "block";
	document.getElementById("previousCtrl").style.display = "none";
	// show 'next' button if more than one article
	if (listItems.length == 1)
		document.getElementById("nextCtrl").style.display = "none";
	
	var ids = [];
	for (var i = 0; i < listItems.length; i++) { 
	
		var elmId = "" + i + "";
		
		ids.push(elmId);   
		listItems[i].id = elmId; 
	}
	
	// assign click events to the various nav controls on the page
	YAHOO.util.Event.addListener(ids, "click", showArticle);
	YAHOO.util.Event.addListener("previousCtrl", "click", showPreviousArticle);
	YAHOO.util.Event.addListener("nextCtrl", "click", showNextArticle);
}


window.onload = initPage;