var PINT_SMOOTHSCROLL_INTERVAL;
var PINT_SMOOTHSCROLL_STEPS = 25;

function PINT_AddSmoothScrolling() 
	{
	var anchors = document.getElementsByTagName('a');
	
	for (var anchorIndex=0; anchorIndex < anchors.length; anchorIndex++) 
		{
		var currentAnchor = anchors[anchorIndex];
	    // If the link is internal to the page (begins in #) then attach the smoothScroll function as an onclick event handler
		if ((currentAnchor.href && currentAnchor.href.indexOf('#') != -1) && ((currentAnchor.pathname == location.pathname) 
		|| ('/'+currentAnchor.pathname == location.pathname)) && (currentAnchor.search == location.search)) 
			{
			currentAnchor.onclick = PINT_SmoothScroll;
			}
		}
	}
	

function PINT_SmoothScroll(e) 
	{
	e = (e) ? e : ((window.event) ? window.event : "")
	if (e) 
		{
		var eventsource = PINT_GetEventSource(e);		
		// Make sure you aren't using a text node
		while (eventsource.nodeType == 3) 
			eventsource = eventsource.parentNode;

		// sanity check
		if (eventsource.nodeName.toLowerCase() != 'a') return;		
	 	
		var currentAnchor = eventsource.hash.substr(1);
		var anchors = document.getElementsByTagName('a');
		var targetLink = null;
		
		for (var anchorIndex=0; anchorIndex<anchors.length; anchorIndex++)
			{
			var element = anchors[anchorIndex];
			if (element.name && (element.name == currentAnchor))
				{
				targetLink = element;
				break;
				}
			}
		// if we didn't find the target link... pass back to browser	
		if (!targetLink) return true;
		}
		
		// Find the destination's position
		var xDestination = targetLink.offsetLeft;
		var yDestination = targetLink.offsetTop
		var currentElement = targetLink;
		
		while (currentElement.offsetParent && (currentElement.offsetParent != document.body))
			{
			currentElement = currentElement.offsetParent;
			xDestination += currentElement.offsetLeft;
			yDestination += currentElement.offsetTop;
			}
	 	
		clearInterval(PINT_SMOOTHSCROLL_INTERVAL);
		currentYPosition = PINT_GetCurrentYPosition();
		
		stepSize = parseInt((yDestination - currentYPosition)/ PINT_SMOOTHSCROLL_STEPS)
		PINT_SMOOTHSCROLL_INTERVAL	= setInterval('PINT_ScrollWindow('+stepSize+','+yDestination+',"'+currentAnchor+'")',10);
		// And stop the actual click happening
		if (window.event) 
			{
		   	window.event.cancelBubble = true;
   			window.event.returnValue = false;
			}
		if (e && e.preventDefault && e.stopPropagation) 
			{
		   	e.preventDefault();
		   	e.stopPropagation();
			}	 
	}

function PINT_ScrollWindow() 
	{
	if (PINT_ScrollWindow.arguments.length != 3) return false;
		var screenAmount = PINT_ScrollWindow.arguments[0];
		var destination = PINT_ScrollWindow.arguments[1];
		var currentAnchor = PINT_ScrollWindow.arguments[2];

		oldCurrentYPosition = PINT_GetCurrentYPosition();
		isPositionAbove = (oldCurrentYPosition < destination);
		window.scrollTo(0,oldCurrentYPosition + screenAmount);
		isCurrentYPosition = PINT_GetCurrentYPosition();
		isPositionAboveNow = (isCurrentYPosition < destination);
		if ((isPositionAbove != isPositionAboveNow) || (oldCurrentYPosition == isCurrentYPosition)) {
		  // if we've just scrolled past the destination, or
		  // we haven't moved from the last scroll (i.e., we're at the
		  // bottom of the page) then scroll exactly to the link
		  window.scrollTo(0,destination);
		  // cancel the repeating timer
		  clearInterval(PINT_SMOOTHSCROLL_INTERVAL);
		  // and jump to the link directly so the URL's right
		  location.hash = currentAnchor;
		}
	}

function PINT_GetCurrentYPosition() 
	{
	var currentPosistion = 0;
	if (document.body && document.body.scrollTop)
   		currentPosistion = document.body.scrollTop;
 	if (document.documentElement && document.documentElement.scrollTop)
   		currentPosistion = document.documentElement.scrollTop;
	if (window.pageYOffset)
   		currentPosistion = window.pageYOffset;
	
	return currentPosistion;
} 

	

function smoothScroll(e) {
 // This is an event handler; get the clicked on element,
 // in a cross-browser fashion
 if (window.event) {
   target = window.event.srcElement;
 } else if (e) {
   target = e.target;
 } else return;
 
 // Make sure that the target is an element, not a text node
 // within an element
 if (target.nodeType == 3) {
   target = target.parentNode;
 }
 
 // Paranoia; check this is an A tag
 if (target.nodeName.toLowerCase() != 'a') return;
 
 // Find the <a name> tag corresponding to this href
 // First strip off the hash (first character)
 anchor = target.hash.substr(1);
 // Now loop all A tags until we find one with that name
 var allLinks = document.getElementsByTagName('a');
 var destinationLink = null;
 for (var i=0;i<allLinks.length;i++) {
   var lnk = allLinks[i];
   if (lnk.name && (lnk.name == anchor)) {
     destinationLink = lnk;
     break;
   }
 }
 
 // If we didn't find a destination, give up and let the browser do
 // its thing
 if (!destinationLink) return true;
 
 // Find the destination's position
 var destx = destinationLink.offsetLeft;  
 var desty = destinationLink.offsetTop;
 var thisNode = destinationLink;
 while (thisNode.offsetParent &&  
       (thisNode.offsetParent != document.body)) {
   thisNode = thisNode.offsetParent;
   destx += thisNode.offsetLeft;
   desty += thisNode.offsetTop;
 }
 
 // Stop any current scrolling
 clearInterval(PINT_SMOOTHSCROLL_INTERVAL);
 
// cypos = ss_getCurrentYPos();
cypos = PINT_GetCurrentYPosition();
 
 ss_stepsize = parseInt((desty-cypos)/PINT_SMOOTHSCROLL_STEPS);
 PINT_SMOOTHSCROLL_INTERVAL = setInterval('PINT_ScrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
 
 // And stop the actual click happening
 if (window.event) {
   window.event.cancelBubble = true;
   window.event.returnValue = false;
 }
 if (e && e.preventDefault && e.stopPropagation) {
   e.preventDefault();
   e.stopPropagation();
 }
}


function ss_addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
}  

var ss_STEPS = 25;
//ss_addEvent(window,"load",ss_fixAllLinks);
// run the onload script

function runScripts()
	{
//	PINT_AddSmoothSrolling();
//	ss_fixAllLinks();
//	primeSlide();
	}
//window.onload = runScripts;