/*
 * @author Philip Trettner
 * @created 09.11.2009
 */

/*if ( !$ ) $ = function(obj) {
    return document.getElementById(obj);
}*/

var navis = [];
var navi_links = [];
var navi_progress = [];
var navi_count = 0;
var navi_index = -1;
var navi_init_index = -1;
var fps = 60;     //Anzahl der Frames pro Sekunde
var speed = 300; //Anzahl der Millisekunden, um einen Reiter vollst�ndig offen zu haben
var lastTick;

//Known Bug: IE zeigt png's nicht richtig an
var ie = ((navigator.userAgent.indexOf('MSIE')!=-1)&&(navigator.userAgent.indexOf('Opera')==-1));
if ( ie ) speed /= 2;

function SetProgress(index, progress) {
    if (!ie) {
        var left = 24;
        if ( progress >= 0.5 ) left = (1 - progress) * 24 * 2;
        navi_progress[index] = progress;
        navi_links[index].style.paddingLeft = Math.round(left) + "px";
        var opa = 1;
        if ( progress < 0.5 ) opa = progress * 2;
        navi_links[index].style.opacity = opa + "";
    } else {
        navi_progress[index] = progress;
        navi_links[index].style.paddingLeft = Math.round((1 - progress) * 24) + "px";
    }
}

function NaviRoutine() {
    var progress = new Date().getTime() - lastTick.getTime();
    lastTick = new Date();
    for ( var i = 0; i < navi_count; ++i ) {
        if ( i == navi_index ) {
            if ( navi_progress[i] < 1 ) {
                navi_progress[i] += progress / speed;
                if ( navi_progress[i] >= 1 ) {
                    navi_progress[i] = 1;
                }
                SetProgress(i, navi_progress[i]);
            }
        } else {
            if ( navi_progress[i] > 0 ) {
                navi_progress[i] -= progress / speed;
                if ( navi_progress[i] <= 0 ) {
                    navi_progress[i] = 0;
                }
                SetProgress(i, navi_progress[i]);
            }
        }
    }
}

var save = window.onload;
window.onload = function() {
    if ( save ) save();
    var eles = document.getElementsByTagName("div");
    for ( var i = 0; i < eles.length; ++i ) {
        var ele = eles[i];
        if ( ele.className.indexOf("navi_link_active") != -1 ) {
            navis[navi_count] = ele;
            navi_links[navi_count] = ele.getElementsByTagName("a")[0];
            navi_progress[navi_count] = 0;
            if ( ele.className == "navi_link_active nonactive" ) {
                SetProgress(navi_count, 0);
                ele.getElementsByTagName("img")[0].style.visibility = "visible";
                var f2 = function() {
                    var savi = navi_count;
                    document.getElementById("navi_link_" + (savi + 1)).onmouseover =
                    ele.onmouseout = function(){
                        navi_index = navi_init_index;
                    };
                };
                f2();
            } else {
                navi_init_index = navi_index = navi_count;
                SetProgress(navi_count, 1);
            }
            var f = function() {
                var savi = navi_count;
                document.getElementById("navi_link_" + (savi + 1)).onmouseover =
                ele.onmouseover = function(){
                    navi_index = savi;
                };
            };
            f();
            navi_count++;
        }
    }
    lastTick = new Date();
    window.setInterval(NaviRoutine, Math.round(1000/fps));
};
