isIE = document.all ? true : false ;   // teste si la navigateur est IE

var timeOut = null;

function ucfirst(str) {
   return str.substr(0,1).toUpperCase()+str.substr(1)
}

onDomReady = (function(){

  // create event function stack
  var load_events = [],load_timer,done,exec,old_onload,
  init = function () {
    done = true;    
    clearInterval(load_timer);// kill the timer
    while (exec = load_events.shift()){
      exec();
    }
  };

  return function(func){

    if (done) return func();// if the init function was already ran, just run
    
    if (!load_events[0]) {
      if(document.readyState && window.ActiveXObject){
        if (!document.getElementById('ie_ready')){
          var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
				  document.write('<script id="ie_ready" defer src="' + src + '"><\/script>');
				  document.getElementById('ie_ready').onreadystatechange = function(){
				    if (this.readyState == "complete"){
					    init();
					  }
				  };
			  }
      }else if (document.readyState && /WebKit/i.test(navigator.userAgent)){ // for Safari      
        load_timer = setInterval(function() {
          if (/loaded|complete/.test(document.readyState))
            init(); // call the onload handler
          }, 30);          
      }else if(document.addEventListener){// for other browsers
        document.addEventListener("DOMContentLoaded", init, false);        
      }else{
        old_onload = window.onload;
        window.onload = function() {
          init();
          if (old_onload) old_onload();
        };
      }
    }
    load_events.push(func);
  }
})();

onDomReady(function(){ 
  initRollover(); 
  if(typeof initFade == 'function') initFade();
  if(typeof imageViewer == 'function') 
   setTimeout(function(){ viewer = new imageViewer(); }, 200);
});

function initRollover()
{
  var divMenu = document.getElementById("menuContent");
  divMenu.onmouseover = function(){ cancelTimer() };
  divMenu.onmouseout  = function(){ createTimer() };
  var firstEntry = divMenu.firstChild;
  while (firstEntry != null)
  {
    if( firstEntry.tagName == "LI" )
    {
      var currNode = firstEntry.childNodes.item(0);
      if (isIE)
      {
        currNode.onmouseover = function(){ cancelTimer(); displayImageMirror(this.id); }
      }
      else
      {
        currNode.onmouseover = function(event){ cancelTimer(); displayImageMirror(this.id); }
      }
    }
    firstEntry = firstEntry.nextSibling;
  }
  displayImageMirror(currPage);
}

function displayImageMirror(myId)
{
  document.getElementById("miroir").style.backgroundImage = "url('sys/menu/" + LANG + "/" + myId + ".png')";
}

function createTimer()
{
  timeOut = setTimeout(function(){displayImageMirror(currPage);},500);
}

function cancelTimer()
{
  clearTimeout(timeOut);
}