/* **********************************************************************
Site:						hamlet-berlin.de
URL:						www.hamlet-berlin.de (info@hamlet-berlin.de)
Filename:				anchorjump.js
Description:		animated anchor links with unobtrusive JavaScript
Credits:				BrandSpankingNew  Timothy Groves, Munich, Germany
								www.brandspankingnew.net/archive/2005/09/animated_anchor.html
********************************************************************** */

var scrollInt, scrTime, scrSt, scrDist, scrDur, scrInt;

function replaceAnchorLinks()
{
var anchors, i, targ, targarr;
if(!document.getElementById)return;
anchors = document.getElementsByTagName("a");
for(i=0;i<anchors.length;i++) {
if(anchors[i].href.indexOf("#")!=-1&&anchors[i].href.indexOf(document.URL)!=-1) {
targ=anchors[i].href.substring(anchors[i].href.indexOf("#")+1);
targarr=document.getElementsByName(targ);
if(targarr.length) {
anchors[i].className=(targarr[0].offsetTop<anchors[i].offsetTop)?"up":"down";
anchors[i].id="__"+targ;
anchors[i].onclick=function () {
scrollToAnchor(this.id.substring(2));
// alert(this.id.substring(2));
return false;
};
anchors[i].href="#";
}
}
}
}


function scrollPage()
{
scrTime+=scrInt;
if(scrTime<scrDur) {
window.scrollTo(0,easeInOut(scrTime,scrSt,scrDist,scrDur));
}
else {
window.scrollTo(0,scrSt+scrDist);
clearInterval(scrollInt);
}
}


function scrollToAnchor(aname)
{
var anchors, i, ele;
if(!document.getElementById)return;
anchors=document.getElementsByTagName("a");
for(i=0;i<anchors.length;i++) {
if(anchors[i].name==aname) {
ele=anchors[i];
i=anchors.length;
}
}
scrSt=window.scrollY?window.scrollY:document.body.scrollTop;
scrDist=ele.offsetTop-scrSt;
scrDur=500;
scrTime=0;
scrInt=10;
clearInterval(scrollInt);
scrollInt=setInterval(scrollPage,scrInt);
}


function easeInOut(t,b,c,d)
{
return c/2*(1-Math.cos(Math.PI*t/d))+b;
}