var currentNews = 0;
var newsCacheHTML = Array();
var newsStubCache = Array();
function showNews(i){
	// hide btn
	if($('b'+i)) $('b'+i).hide();
	// if currentNews != 0 reset currentNews to stub and show its btn
	if(currentNews != 0){
		$('n'+currentNews).innerHTML = newsStubCache[currentNews];
		if($('b'+currentNews)) $('b'+currentNews).show();
	}
	// build the stub cache as we go
	if(!newsStubCache[i]){
		newsStubCache[i] = $('n'+i).innerHTML;
	}
	if(!newsCacheHTML[i]){
		new Ajax.Request('ajax-content.php', { parameters: { type: 'news', id: i }, method: 'post', onSuccess: function(transport){
			var news = transport.responseText;
			newsCacheHTML[i] = news;
			$('n'+i).innerHTML = news;
			currentNews = i;
		}});
	} else {
		$('n'+i).innerHTML = newsCacheHTML[i];
		currentNews = i;
	}
	//$('n'+i).scrollTo(); // the skipping was deemed undesirable!
}

document.observe("dom:loaded", function(){
	if(typeof news != 'undefined' && news != null && news!=""){
		showNews(news);
	} /*else {
		// auto open single stubs ... disabled!!
		// looks weird when u page to a page of results with 1 item
		/*
		var els = $$('div.newsdiv');
		if(els.length==1){
			var id = els[0].identify();
			showNews(id.substr(1));
		}
		
	}*/
});

