var scrollInt;
var scrTime, scrSt, scrDist, scrDur, scrInt;

function getBrowser()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	return browser + b_version
}

function getRealTop(el) 
{
	var yPos, tempEl

	yPos = el.offsetTop;
	tempEl = el.parentNode;
	while (tempEl != null) 
	{
		dPos = tempEl.offsetTop;
		if ( dPos > 0 )
		{
			yPos += dPos;
			//alert ('current scroll offset ' + yPos)
		}
		tempEl = tempEl.parentNode;
	}
	return yPos;
}

function scrollToAnchor(aname)
{

	var ele;

	if (!document.getElementById)
		return;

	if (document.getElementById(aname) != null)
		ele = document.getElementById(aname);
	else
		return;
	
		
	// set scroll target
	if (window.scrollY)
		scrSt = window.scrollY;
	else if (document.documentElement.scrollTop)
		scrSt = document.documentElement.scrollTop;
	else
		scrSt = document.body.scrollTop;	

	
	scrDist = ele.offsetTop - scrSt;
	
	scrDur = 500;
	scrTime = 0;
	scrInt = 10;

	// set interval
	clearInterval(scrollInt);
	scrollInt = setInterval( scrollPage, scrInt );
	
}

function scrollToAnchor2(aname)
{
	// this version of scrollTo Anchor attempts to cope with IE7's unusual
	// way of calculating the position of things on the screen

	var ele;

	if (!document.getElementById)
		return;
	
	ele = document.getElementById(aname);
		
	// set scroll target
	if (window.scrollY)
		scrSt = window.scrollY;
	else if (document.documentElement.scrollTop)
		scrSt = document.documentElement.scrollTop;
	else
		scrSt = document.body.scrollTop;	
	
	whichbrowser = getBrowser()
	if (whichbrowser.indexOf('MSIE 7.0') != -1)
	{
		// IE7 calculates offsetTop relative to parent, others do it ref the browser window
		// so we have to do some tree walking
		//scrDist = getRealTop(ele) - scrSt; // oringial
		scrDist = ele.offsetTop - scrSt;

		// Also IE7 seems to scroll so the item is at the very top of the window but
		// we want it about a third of the way down, so knock off 200 pixels
		//scrDist = scrDist - 200 // oringial
		scrDist = scrDist + 200
	}
	else
	{
		scrDist = ele.offsetTop - scrSt;
	}
	
	scrDur = 500;
	scrTime = 0;
	scrInt = 10;

	//alert(' scrStart: ' + scrSt + ' scrDist: '+ scrDist )
	
	
	// set interval
	clearInterval(scrollInt);
	scrollInt = setInterval( scrollPage, scrInt );
	
}

function easeInOut(t,b,c,d)
{
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}

function scrollPage()
{
	scrTime += scrInt;
	if (scrTime < scrDur) {
		window.scrollTo( 0, easeInOut(scrTime,scrSt,scrDist,scrDur) );
	}else{
		window.scrollTo( 0, scrSt+scrDist );
		clearInterval(scrollInt);
	}
}


function addLoadEvent(func) {   
   var oldonload = window.onload;   
   if (typeof window.onload != 'function') {   
     window.onload = func;   
   } else {   
     window.onload = function() {   
       if (oldonload) {   
         oldonload();   
       }   
       /*func(); */  
     }   
   }   
 }   

