
var Kotvy = {
    interval: 30,
    multiplier: 6,
    init: function()
    {
        var a = document.getElementsByTagName("a");
        var url = location.href.substring(0, location.href.length - location.hash.length);
        for(var i = 0, l = a.length; i < l; i++)
        {
            if(a[i].href.substr(0, url.length) == url && a[i].href.indexOf("#") > -1)
            {
                a[i].destination = document.getElementById(a[i].hash.substr(1));
                a[i].onclick = Kotvy.click;
            }
        }
    },
    
    
    click: function()
{
    if(!this.destination) return true;
    var d = this.destination;
    Kotvy.intervalId = setInterval(function()
    {
        Kotvy.moveTo(d);
    }, Kotvy.interval)
    Kotvy.moveTo(d);
    return false;
},


    
    moveTo: function(destination)
    {
        var x = 0, y = -1;
        var o = destination;
        while(o)
        {
            x += o.offsetLeft;
            y += o.offsetTop;
            o = o.offsetParent;
        }
        var spo = Kotvy.scrollPosition();
        var dx = (x - spo[0]) / Kotvy.multiplier, dy = (y - spo[1]) / Kotvy.multiplier;
        if(dx > 0) dx = Math.ceil(dx); else dx = Math.floor(dx);
        if(dy > 0) dy = Math.ceil(dy); else dy = Math.floor(dy);
        scrollBy(dx, dy);
        var spn = Kotvy.scrollPosition();
        if(spo[0] == spn[0] && spo[1] == spn[1])
{
    clearInterval(Kotvy.intervalId);
    location.hash = destination.id;
    destination.id == 'kontakt' && document.getElementById('myAnchor').focus();
}
    },
    scrollPosition: function()
    {
        return [document.body.scrollLeft || document.documentElement.scrollLeft || window.pageXOffset || 0, document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0];
    }
};
