var init_pos;
var old_pos=0;
var lst_timeout=new Array(0,1);
var timout_show_subnavlink = new Array();
var timout_hide_subnavlink = new Array();
var stop_pos=false;

var uagent = navigator.userAgent.toLowerCase();
if (    ( uagent.search("iphone") > -1 ) ||
        ( uagent.search("ipod") > -1 )   ||
        ( uagent.search("symbian") > -1) ||
        ( uagent.search("android") > -1) ||
        ( uagent.search("windows ce") > -1) ||
        ( uagent.search("blackberry") > -1) ||
        ( uagent.search("palm") > -1)
  ) {
    var navigatorType = 'smartdevice';
} else if (navigator.appName == 'Microsoft Internet Explorer') {
    var navigatorType = 'MSIE';
} else if (navigator.appVersion.indexOf('WebKit') != -1) {
    var navigatorType = 'WebKit';
} else if (navigator.appCodeName == 'Mozilla') {
    var navigatorType = 'Gecko';
} else {
    var navigatorType = 'Other';
}

var FuncOL = new Array();

function addFuncOL(fct) {
    FuncOL[FuncOL.length] = fct;
}

window.onload = function() {
    for(var i = 0, l = FuncOL.length; i<l; i ++)
        FuncOL[i]();
};

addFuncOL (function() {
            document.getElementById("selector").style.left=old_pos+'%';
        });

function loadXMLDoc(dname){
    if (window.XMLHttpRequest) {
        xhttp=new XMLHttpRequest();
    } else {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET",dname,false);
    xhttp.send("");
    return xhttp.responseXML;
}


function init_navlink_selector(pos) {
    /*
     * Initialise la postion du selecteur
     *   - pos : position en % du selecteur
     */
    old_pos = pos;
    init_pos = pos;
}


function change_navlink_selector (nv_pos) {
    /*
     * Deplace le selecteur
     *   - nv_pos : nouvelle position en % du selecteur
     */

    if (navigatorType == "smartdevice")
        return true;

    if (stop_pos == true)
        return true;

    var nb_incr = Math.round(Math.abs(old_pos - nv_pos)*.3) + 1;
    var delta_tps = 40;
    var tps = 0;
    //dbgpos = new Array();

    for(var i = 0, l = lst_timeout.length; i<l; i ++)
        clearTimeout(lst_timeout[i]);

    for (i=0; i<=nb_incr; i++) {
        pos = Math.round(-Math.cos(Math.PI*i/nb_incr)*50+50) * (nv_pos - old_pos) / 100 + old_pos ;
        lst_timeout[i] = setTimeout('document.getElementById("selector").style.left="'+pos+'%"; old_pos='+pos+';',tps);
        tps = tps + delta_tps;
        //dbgpos[i] = pos;
    }
    //~ old_pos = nv_pos;

}

function reset_navlink_selector() {
    change_navlink_selector(init_pos);
}

function stop_navlink_selector() {
    stop_pos=true;
}

function show_subnavlink (id) {
    node = document.getElementById(id);
    if ((navigatorType == 'MSIE') || (navigatorType == "smartdevice") || (navigatorType == "other")) {
        node.style.visibility = 'visible';
    } else {
        if (timout_hide_subnavlink[id]) {
            for(var i = 0, l = timout_hide_subnavlink[id].length; i<l; i ++)
                clearTimeout(timout_hide_subnavlink[id][i]);
        }
        if (node.style.visibility != 'visible') {
            node.style.visibility = 'visible';
            node.style.top = 0;
            if (navigatorType == 'WebKit') {
                node.style.opacity = .3;
                timout_show_subnavlink[0] = setTimeout('document.getElementById("'+id+'").style.opacity = .5; document.getElementById("'+id+'").style.top = "10px"; ',50);
                timout_show_subnavlink[1] = setTimeout('document.getElementById("'+id+'").style.opacity = .8; document.getElementById("'+id+'").style.top = "20px"; ',100);
                timout_show_subnavlink[2] = setTimeout('document.getElementById("'+id+'").style.opacity = 1; document.getElementById("'+id+'").style.top = "30px"; ',150);
            } else {
                timout_show_subnavlink[0] = setTimeout('document.getElementById("'+id+'").style.opacity = 1; document.getElementById("'+id+'").style.top = "10px"; ',50);
                timout_show_subnavlink[1] = setTimeout('document.getElementById("'+id+'").style.top = "20px"; ',100);
                timout_show_subnavlink[2] = setTimeout('document.getElementById("'+id+'").style.top = "30px"; ',150);
            }
        } else {
            node.style.opacity = 1;
            node.style.top = "30px"
            node.style.visibility = 'visible';
        }
    }
}

function hide_subnavlink (id) {
    if ((navigatorType == 'MSIE') || (navigatorType == "smartdevice") || (navigatorType == "other")) {
        document.getElementById(id).style.visibility = 'hidden';
    } else {
        timout_hide_subnavlink[id]=new Array();
        if (navigatorType == 'WebKit') {
            timout_hide_subnavlink[id][0] = setTimeout('document.getElementById("'+id+'").style.opacity = .8; document.getElementById("'+id+'").style.top = "20px"; ',250);
            timout_hide_subnavlink[id][1] = setTimeout('document.getElementById("'+id+'").style.opacity = .6; document.getElementById("'+id+'").style.top = "10px"; ',300);
            timout_hide_subnavlink[id][2] = setTimeout('document.getElementById("'+id+'").style.opacity = .3; document.getElementById("'+id+'").style.top = "0px"; ',350);
            timout_hide_subnavlink[id][3] = setTimeout('document.getElementById("'+id+'").style.visibility = "hidden"; ',400);
        } else {
            timout_hide_subnavlink[id][0] = setTimeout('document.getElementById("'+id+'").style.top = "20px"; ',250);
            timout_hide_subnavlink[id][1] = setTimeout('document.getElementById("'+id+'").style.top = "10px"; ',300);
            timout_hide_subnavlink[id][2] = setTimeout('document.getElementById("'+id+'").style.top = "0px"; ',350);
            timout_hide_subnavlink[id][3] = setTimeout('document.getElementById("'+id+'").style.visibility = "hidden"; ',400);
        }
    }
}
