iStart = function(ni) {
	var whichi = document.getElementById("whichimage");
	var numi = document.getElementById("numberimages");
	var t = document.createTextNode("1");
	whichi.appendChild(t);
	var t = document.createTextNode(ni);
	numi.appendChild(t);
	}
	
iOnLoadImage = function(i) {
	var whichi = document.getElementById("whichimage");
	var replace = whichi.firstChild;
	var t = document.createTextNode(i);
	whichi.replaceChild(t,replace);
	}

startPreloader = function() {
	
	var ip = new ImagePreloader(aTimelineImages,loader,iStart,iOnLoadImage);
	
	}

loader = function() {
	var loadingScreen = document.getElementById("loading");
	var wrap = document.getElementById("wrap");
	loadingScreen.style.display = "none";
	wrap.style.visibility = "visible";
	dynamicResizer();
	scrollerLoader();
	}

dynamicResizer = function() {
	var h = getScreenDimension(true);
	var w = getScreenDimension(false);
	var correction = 165;
	var widthc = 20;
	var widthc2 = widthc - 3;
	var infoPane = document.getElementById("scrollingcontainer2");
	var scrollContainer = document.getElementById("scrollercontainer2");
	var scrollArea = document.getElementById("scrollarea2");
	var scrollWrap = document.getElementById("scroll2wrap");
	var timelinePane = document.getElementById("scrollingcontainer1");
	var timelineScrollArea = document.getElementById("scrollercontainer1");
	var scrolling2 = document.getElementById("scrolling2");
	infoPane.style.height = (h - correction) + "px";
	scrollWrap.style.width = (w - widthc) + "px";
	scrolling2.style.width = (w - widthc - 35) + "px";
	timelinePane.style.width = (w - widthc2) + "px";
	timelineScrollArea.style.width = (w - widthc2) + "px";
	// scrollContainer.style.height = (h - correction) + "px";
	// scrollArea.style.height = (h - correction) + "px";
	}

scrollerLoader = function() {
	initTimeLineScroller();
	// initInfoPaneScroller();
	}
	
initTimeLineScroller = function() {
	var scrollertop = new scroller();
	scrollertop.init("scrolltop",document.getElementById("scrollingcontainer1"),document.getElementById("scrolling1"),document.getElementById("scrollarea1"),document.getElementById("scrollercontainer1"),document.getElementById("scroller1"),false,true,true,document.getElementById("scrollleft1"),document.getElementById("scrollright1"),90,400,23,34);
	}
	
initInfoPaneScroller = function() {
	var scrollerbottom = new scroller();
	scrollerbottom.init("scrollbottom",document.getElementById("scrollingcontainer2"),document.getElementById("scrolling2"),document.getElementById("scrollarea2"),document.getElementById("scrollercontainer2"),document.getElementById("scroller2"),true,false,true,document.getElementById("scrollleft2"),document.getElementById("scrollright2"),30,400,23,53);
	}
	
assignIntLinkHandlers = function() {
	if (document.getElementById && document.getElementsByTagName) {
		infoContainer = document.getElementById("scrolling2");
		mLinks = infoContainer.getElementsByTagName("a");
		for (i=0; i<mLinks.length; i++) {
			if (mLinks[i].className == "jump") {
				mLinks[i].onclick = showInfo;
				}
			}
		}
	}
	
fireup = function() {
	infoPane = document.getElementById("scrolling2");
	buildInfoPane('home');
	// buildInfoPane('archimedes-of-syracuse');
	}
	
removeRows = function() {
	while(infoPane.hasChildNodes()) {
		infoPane.removeChild(infoPane.lastChild);
		}
	}
	
showInfo = function() {
	var page = this.parentNode.id;
	if (page.length == 0) {
		// try to parse it from the url
		page = this.href.slice((this.href.lastIndexOf("?m=")+3));
		}
	buildInfoPane(page);
	return false;
	}
	
buildInfoPane = function(page) {
	if (typeof theTimeLine == 'undefined') {
		theTimeLine = new TimeLine();
		}
	// connect("xml/"+page+".xml","GET","null","timeline");
	connect("output-mathinfo.php?m="+page,"GET","null","timeline");
	}
	
assignInfoHandler = function() {
	if (document.getElementById && document.getElementsByTagName) {
		timelineContainer = document.getElementById("scrolling1");
		mBoxes = timelineContainer.getElementsByTagName("p");
		for (i=0; i<mBoxes.length; i++) {
			if (mBoxes[i].className == "infop") {
				mBoxes[i].onclick = showInfo;
				}
			}
		}
	}

addLoadEvent(startPreloader);
addLoadEvent(assignInfoHandler);
addResizeEvent(loader);
addLoadEvent(fireup);