var h = 0; // init height to nowt
function getArticlesForPage(page, per_page) {
	
	// the below just stops the news pod getting too small
	/*var th = $("article_wrapper").offsetHeight;
	if (th > h) {  // is this temp h greater than the one we have saved?
		h = th;  // yeah, update
		$("article_outer").setStyle({
			height:h+'px'
		});
	}*/
	
	// below basically fades out the current stuff
	// then, *after* it finishes, fires an AJAX request, which...
	// *after* it completes, shows the wrapper again. Nice.
	new Effect.Fade($("article_wrapper"), {
		duration:0.25,
		afterFinish: function() {
			new Ajax.Request(base_href + "news/ajax/for-page/"+page+"/"+per_page+"/", {
				method:'get',
				onSuccess: function(transport) {
					var result = eval('(' + transport.responseText + ')');
					if (result.msg != "OK") {
						alert(result.msg);
					}
					if (result.articles.length == 0) {
						return;
					}
					var newdiv = new Element("div");
					for (var i = 0; i < result.articles.length; i++) {
						var article = result.articles[i];
						var str = "";
						str += "<h3><a href='news/"+article.url+"/'>"+article.title+"</a></h3>";
						str += "<p>"+article.introduction+"</p>";
						newdiv.insert(new Element("div", {'class':'story'}).update(str));
					}
					var c = 1;
					$$(".page_li").each(function(s) {
						if (c == page) {
							s.update(c);
						} else {
							s.update("<a href='javascript://' onclick='javascript:getArticlesForPage("+c+", "+per_page+");'>"+c+"</a>");
						}
						c++;
					});
					$("article_wrapper").update(newdiv);
					
					new Effect.Appear($("article_wrapper"), {
						duration:0.25
					});			
				}
			});
		}
	});
}
