// Simple div switcher thing by Craig
// needs to be include along with prototye 1.5
// to get it rolling use:  onLoad="initContent()
// declare a holding div with an id of 'content'
// within 'content' have as many elements as you like with a class of 'content_inner'

var currentNode = 0;

function initContent(){
	
	//hide ALL of the divs
	var innerDivs = $('normal_content').getElementsByClassName('content_inner');

	if(innerDivs.size()){
		var totalNodes = innerDivs.size();
		innerDivs.invoke('hide');
		//show the first div
		innerDivs.first().show();
		//set the link text
		showContentLinks(totalNodes);
	}
}

function showNextContent() {
	//hide ALL of the divs
	var innerDivs = $('normal_content').getElementsByClassName('content_inner');
	if(innerDivs.size()){
		var totalNodes = innerDivs.size();
		innerDivs.invoke('hide');
		//get the div we want to show
		if(currentNode < (totalNodes-1)){ currentNode++; }
		else{ currentNode = 0; }
		//show the one we actually want to see
		innerDivs[currentNode].show();
		//set the link text
		showContentLinks(totalNodes);	
	}
}

function showPrevContent() {
	//hide ALL of the divs
	var innerDivs = $('normal_content').getElementsByClassName('content_inner');
	if(innerDivs.size()){
		var totalNodes = innerDivs.size();
		innerDivs.invoke('hide');
		//get the div we want to show
		if(currentNode > 0){ currentNode--; }
		else{ currentNode = totalNodes-1; }
		//show the one we actually want to see
		innerDivs[currentNode].show();
		//set the link text
		showContentLinks(totalNodes);	
	}
}

function showContentLinks(totalNodes){
	//if we are on the first node
	if(currentNode == 0){
		$('content_link').replace('<div id="content_link"><a href="javascript:showNextContent()" >Next &#187;</a></div>');
	}
	else if(currentNode < totalNodes-1){
		$('content_link').replace('<div id="content_link"><a href="javascript:showPrevContent()" > &#171; Previous</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:showNextContent()" >Next &#187;</a></div>');
	}
	else{
		$('content_link').replace('<div id="content_link"><a href="javascript:showPrevContent()" > 	&#171; Previous</a></div>');
	}
}

