// JavaScript Document

// Script Avialable Site Wide
// Known links: students/degreeplans.shtml | students/compstandards.shtml

//var destination = 500; // (Y-axis) number derived by mesuring the number of pixels the alert box area is from the top of the page.

function scrollToPosition(destination) {
	var scrOfY = 0;
  	var scrollMax = 0;
	var pgHeight = 0;
	var pgMax_v1 = document.body.scrollHeight;
	var pgMax_v2 = document.body.offsetHeight;
	if(pgMax_v1 > pgMax_v2) {
		var pgMax = document.body.scrollHeight;
	} else {
		var pgMax = document.body.offsetHeight;
	}
	if(typeof(window.pageYOffset) == 'number') {
    	//Netscape compliant
    	scrOfY = window.pageYOffset;
		pgHeight = self.innerHeight;
  	} else if(document.body && document.body.scrollTop) {
    	//DOM compliant
    	scrOfY = document.body.scrollTop;
		pgHeight = document.body.clientHeight;
  	} else if(document.documentElement && document.documentElement.scrollTop) {
    	//IE6 standards compliant mode
    	scrOfY = document.documentElement.scrollTop;
		pgHeight = document.documentElement.clientHeight;
  	}
	scrollMax = pgMax - pgHeight;
	var distance = Math.abs(destination - scrOfY);
	if(distance > 10) {
		if(scrOfY >= scrollMax) {
			 clearTimeout(scrolldelay);
		} else {
			var stepsize = distance / 9;
			if(stepsize < 10) {
				stepsize = 9;
			}
			if (scrOfY > destination) {
				//window.scroll(0,destination); // horizontal and vertical scroll targets
				window.scrollBy(0,-stepsize); // horizontal and vertical scroll increments
				var scrolldelay = setTimeout('scrollToPosition('+destination+')',80); // scrolls every __ milliseconds clearTimeout(scrolldelay);
			} else if(scrOfY < destination) {
				window.scrollBy(0,stepsize);
				var scrolldelay = setTimeout('scrollToPosition('+destination+')',80); // scrolls every __ milliseconds
			}
		}
	}
	return false;
}

function scrollToId(id) {
	var obj = document.getElementById(id);
	var curleft = 0; curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		}
	}
	curtop = curtop - 5;
	//return [curleft,curtop];
	scrollToPosition(curtop);
	return false;
}