

var xmlHttp;

function createXMLHttpRequest() {

	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function rotate(address) {

	createXMLHttpRequest();
	
	
	
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", address, true);
	xmlHttp.send(null);
}

function handleStateChange() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			parseResults();
		}
	}
}

function parseResults() {

	
	
	
	
	document.getElementById("rotwrapper").innerHTML = xmlHttp.responseText;
	
	navigation()
	
	

}

function navigation() {
	
	n = story + 1;
	p = story -1;
	
	if (p == 0) {
		p = total;
	}
	else if (n > total) {
		n = 1;
	}
	
	
	
	
	
	var nav = document.getElementById("test");
	nav.innerHTML = "<div class='rotnav'><div class='left'><a href=\"javascript:minusone();rotate('rotations/story" + p + ".php');\"><img src='images08/homepage/rotation_back.gif' alt='previous rotation item' height='16' width='16' /></a> <a href=\"javascript:addone();rotate('rotations/story" + n + ".php');\"><img src='images08/homepage/rotation_next.gif' alt='next rotation item' height='16' width='16' /></a></div><div class='right'>" + s + " of " + total + " | <a href='stories.php'>more</a></div></div>";	
			
		

		//document.write("<div class='rotnav'>");
//    	document.write("<div class='left'>");
//    	document.write("<a href=\"javascript:rotate('rotations/story" + p + ".php');addone();\"><img src='images08/homepage/rotation_back.gif' alt='previous rotation item' height='16' width='16' /></a> <a href=\"javascript:rotate('rotations/story" +n+ ".php');addone();\"><img src='images08/homepage/rotation_next.gif' alt='next rotation item' height='16' width='16' /></a>");
//        document.write("</div>");
//        document.write("<div class='right'>");
//        document.write(+s+ " of "+total+ " | <a href='stories.php'>more</a>");
//        document.write("</div>");
//    	document.write("</div>");


}

function addone(){
	s++;
	story++;
	
	if (story > total) {
		story = 1;
	}
	
	if (s > total) {
		s = 1;
	}
	
}

function minusone(){
	s--;
	story--;
	
	if (story == 0) {
		story = total;
	}
	
	if (s == 0) {
		s = total;
	}
	
}
	
	









