function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Fetching data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	ahah(name,div);
	return false;
}


//We wrap all the code in an object so that it doesn't interfere with any other code
	var scroller = {
		init:   function() {
				
		//collect the variables
		scroller.docH = document.getElementById("content").offsetHeight;
		scroller.contH = document.getElementById("content_container").offsetHeight;
		scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight;
		if (scroller.contH < scroller.docH) {
			//calculate height of scroller and resize the scroller div
			//(however, we make sure that it isn't to small for long pages)
			scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
			//if(scroller.scrollH < 15) scroller.scrollH = 15;
					 
			document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";
					
			//what is the effective scroll distance once the scoller's height has been taken into account
			scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
					
			//make the scroller div draggable
			Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist);
					
			//add ondrag function
			document.getElementById("scroller").onDrag = function (x,y) {
				var scrollY = parseInt(document.getElementById("scroller").style.top);
				var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
				document.getElementById("content").style.top = docY + "px";
			 } 
		} else {
			document.getElementById("scrollArea").style.display = "none";
			document.getElementById("scroller").style.display = "none";
		}	function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		function setContent() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentElement = document.getElementById('center_page');
					var contentHeight = contentElement.offsetHeight;
					if (windowHeight - contentHeight > 0) {
						contentElement.style.position = 'relative';
						contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
			}
		}
	setContent();}
				  
}
				
window.onload = scroller.init;

function getWindowHeight_2() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
function setContent_2() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight_2();
				if (windowHeight > 0) {
					var contentElement = document.getElementById('center_page');
					var contentHeight = contentElement.offsetHeight;
					if (windowHeight - contentHeight > 0) {
						contentElement.style.position = 'relative';
						contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
			}
		}
		window.onresize = function() {
			setContent_2();
		}
	