function pre_load_imgs()
{ (new Image()).src = "images/home_over.png";
  (new Image()).src = "images/contact_over.png";
}

function roll_over_home()
{ if(document.getElementById)
  { if(document.getElementById("a_icone_accueil"))
    { document.getElementById("a_icone_accueil").onmouseover = function()
	  { document.getElementById("icone_accueil").src = "images/home_over.png";
	  }
      document.getElementById("a_icone_accueil").onmouseout = function()
	  { document.getElementById("icone_accueil").src = "images/home.png";
	  }
    }
  }
}

function roll_over_contact()
{ if(document.getElementById)
  { if(document.getElementById("a_icone_contact"))
    { document.getElementById("a_icone_contact").onmouseover = function()
	  { document.getElementById("icone_contact").src = "images/contact_over.png";
	  }
      document.getElementById("a_icone_contact").onmouseout = function()
	  { document.getElementById("icone_contact").src = "images/contact.png";
	  }
    }
  }
}

function addLoadEvent(func)
{ var oldonload = window.onload;
  if(typeof window.onload != 'function') window.onload = func;
  else
  { window.onload = function()
    { if(oldonload) oldonload();
      func();
    }
  }
}

addLoadEvent(pre_load_imgs);
addLoadEvent(roll_over_home);
addLoadEvent(roll_over_contact);

// ------------------------------------------------- photos colonne de droite

  var current_top = 0;
  var top_dy      = 10;
  var move_delay  = 60;
  var cycle_delay = 3000;

  var p1 = 1;
  var p2 = 2;
  var p3 = 3;

  var current_photo = 0;

  var v_photos = new Array();

  function init_photos()
  { xml_photos = loadXMLDoc("load_photos.php");
    p_nodelist = xml_photos.getElementsByTagName("photo");
    i1 = 1;
	if(navigator.appVersion.indexOf("MSIE") != -1)
	{ i1 = 0;
	}
    for(i = 0; i < p_nodelist.length; i++)
    { p_fichier = "";
      if(p_nodelist[i].childNodes[i1].childNodes[0].length > 0) p_fichier = p_nodelist[i].childNodes[i1].childNodes[0].nodeValue;
      p = new Array(p_fichier);
      v_photos.push(p);
    }
	if(v_photos.length > 1) { charge_photo(1); charge_photo(2); }
    if(v_photos.length > 2) setTimeout("defil_photos()", cycle_delay);
  }

  function loadXMLDoc(url)
  { var req = false;
    if(window.XMLHttpRequest && !(window.ActiveXObject))
	{ try { req = new XMLHttpRequest(); }
	  catch(e) { req = false; }
    }
	else if(window.ActiveXObject)
	{ try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch(e)
	  { try { req = new ActiveXObject("Microsoft.XMLHTTP");	}
	    catch(e) { req = false; }
      }
    }
	if(req)
	{ req.open("GET", url, false);
      req.send("");
	  return req.responseXML;
	}
	return null;
  }
 
  function defil_photos()
  { if(current_top == 0)
    { charge_photo(p3);
    }
    current_top -= top_dy;
    if(current_top <= -200)
    { current_top = 0;
      switch(p1)
      { case 1:
          p1   = 2;
          p2   = 3;
          p3   = 1;
          break;
        case 2:
          p1   = 3;
          p2   = 1;
          p3   = 2;
          break;
        case 3:
          p1   = 1;
          p2   = 2;
          p3   = 3;
          break;
      }
      move_photos();
      setTimeout("defil_photos()", cycle_delay);
    }
    else
    { move_photos();
      setTimeout("defil_photos()", move_delay);
    }
  }

  function move_photos()
  { move("photo" + p1, 0);
    move("photo" + p2, 200);
    move("photo" + p3, 400);
  }

  function charge_photo(k)
  { p     = get_obj("photo" + k);
    p_img = get_obj("p" + k + "_img");
    if(p != -1 && p_img != -1)
    { var i = current_photo;
	  do
	  { i = Math.floor(v_photos.length * Math.random());
	  }
	  while(i == current_photo);
	  current_photo = i;
      p_img.src = v_photos[i][0];
    }
    else return -1;
  }

  function get_obj(id)
  { if(document.getElementById) return document.getElementById(id);
    else if(document.all) return document.all[id];
    return -1;
  }

  function move(id, dec)
  { obj = get_obj(id);
    if(obj != -1)
    { obj.style.top = (current_top + dec) + "px";
    }
  }

