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;
}
var smoothScroll = 0; // This is a handle to cancel the scrolling timer.
var Dtop; //This is where we want to get to.
var totalDist = 0; // This is the total distance we need to move.
var amountLeftToMove = 0; // This is the amount left to go.
var currentTopInt;
function setContent(content) {
	/*@cc_on
		/*@if (@_jscript_version == 5.6)
			setContentFast(content);
			return;
		/*@end
	@*/
	if( document.body && ( document.body.scrollTop || document.body.scrollLeft )) {
		var scrollTop = document.body.scrollTop;
       	}
       	else if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )) {
			var scrollTop = document.documentElement.scrollTop;
	}
	else {
		var scrollTop = 0;
	}

	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0 && document.getElementById(content)) {
			var contentElement = document.getElementById(content);
			var cardHeight = contentElement.offsetHeight;
			var mainColElement = document.getElementById("mainCol");
			var mainColHeight = mainColElement.offsetHeight;

                        Dtop = 16;
                        if (scrollTop > 186) {
                                Dtop += (scrollTop - 186);
			}
                        if (Dtop + cardHeight > mainColHeight)
                                Dtop = mainColHeight - cardHeight;

			// Dtop is where we want to be

			// where is the Dtop now?
			var currentTopStr = contentElement.style.top;
			currentTopInt = parseInt(currentTopStr.substring(    0,currentTopStr.indexOf("px"),0     ));

			// kill any scroll that has already been started
			if (smoothScroll)
				clearTimeout(smoothScroll);
			totalDist = Dtop - currentTopInt;
			amountLeftToMove = totalDist;
			// Start a new scroll
			scrollit(content);
		}
	}
}
function setContentFast(content) {
	if( document.body && ( document.body.scrollTop || document.body.scrollLeft )) {
		var scrollTop = document.body.scrollTop;
       	}
       	else if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )) {
			var scrollTop = document.documentElement.scrollTop;
	}
	else {
		var scrollTop = 0;
	}

	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0 && document.getElementById(content)) {
			var contentElement = document.getElementById(content);
			var cardHeight = contentElement.offsetHeight;
			var mainColElement = document.getElementById("mainCol");
			var mainColHeight = mainColElement.offsetHeight;

                        Dtop = 16;
                        if (scrollTop > 186) {
                                Dtop += (scrollTop - 186);
			}
                        if (Dtop + cardHeight > mainColHeight)
                                Dtop = mainColHeight - cardHeight;
			contentElement.style.top = Dtop+"px";
		}
	}
}
			
function scrollit(content) {
	var whereToMoveInt;
	if (document.getElementById)
		var contentElement = document.getElementById(content);
	// lets move part of the way
	if (amountLeftToMove > 0)
		var amountToMove = Math.ceil(amountLeftToMove * 0.25);
	else 
		var amountToMove = Math.floor(amountLeftToMove * 0.25);
	var amountToMoveInt = parseInt(amountToMove);

	if (amountLeftToMove > -2 && amountLeftToMove < 2)
		whereToMoveInt = Dtop;
	else whereToMoveInt = amountToMoveInt + currentTopInt;

	// set the Dtop
	contentElement.style.top = whereToMoveInt+"px";
	if (whereToMoveInt != Dtop) {
		smoothScroll = setTimeout("scrollit('"+content+"')", 50);
		currentTopInt = whereToMoveInt;
		amountLeftToMove -= amountToMove;
	}
       	else {
		amountLeftToMove = 0;
		clearTimeout(smoothScroll);
	}
}

//window.onresize = function() {
//	setContent();
//}
//window.onscroll = function() {
//	setContent();
//}

