/* $Id: fonctions.js,v 1.12 2006/06/13 16:20:43 christian Exp $ */

var fonctions_old_onload = null;
if (typeof window.onload == "function")
{
	fonctions_old_onload = window.onload;
}
window.onload = function()
{
	if (fonctions_old_onload)
	{
		fonctions_old_onload();
		fonctions_old_onload = null;
	}
	if (typeof preload_images == "function") { preload_images(); }
	// BEGIN: to fix old Geckos
	if (
		!document.readyState &&
		!window.opera &&
		!window.find &&
		window.home &&
		document.getElementsByTagName &&
		navigator.product &&
		(navigator.product == 'Gecko')
	)
	{
		var im = document.getElementsByTagName("img");
		for (var i = 0; i < im.length; i++)
		{
			if (im[i].className == 'nn6' || im[i].id == 'intersite')
			{
				im[i].style.display = 'inline-block';
				im[i].style.verticalAlign = '13%';
			}
		}
	}
	// END: to fix old Geckos
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// pour images aléatoires
// imprime un élément style ou un élément img
// arguments de la fonction (obj,mode,pos,attr,sel) :
/*

obj = array de 1 ou 2 dimension(s) (object) REQUIRED

exemple 1 dimension:

	var logosInterne = [
	  "../../images/iu/bandeau-secondaire/defaut.jpg",
	  "../../images/iu/bandeau-secondaire/img01.jpg",
	  "../../images/iu/bandeau-secondaire/img02.jpg",
	  "../../images/iu/bandeau-secondaire/img03.jpg"
	];


exemple 2 dimensions:

	var logosAccueil = [
	  {
	    "milieu":"../images/iu/accueil/phare/01-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/01-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/01-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/02-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/02-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/02-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/03-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/03-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/03-haut.jpg"
	  },
	  {
	    "milieu":"../images/iu/accueil/phare/04-milieu.jpg",
	    "bas":"../images/iu/accueil/phare/04-bas.jpg",
	    "haut":"../images/iu/bandeaupiv/bandeaux/accueil/04-haut.jpg"
	  }
	];

*/
// mode = 'img' ou 'style' (string) REQUIRED
// pos = clé du array si 2 dimensions (string) exemple: 'haut'
// attr = array des attributs (object) OPTIONAL exemple: ['alt=""','border="0"'] ou ['type="text/css"'] ou []
// sel = sélecteur CSS si mode='style' (string) exemple: '#menu-accueil'
function imagesAleatoires(obj, mode, pos, attr, sel)
{
	var out = '';
	if (typeof obj.alea == 'undefined')
	{
		obj.alea = Math.floor(Math.random()*obj.length);
	}
	out += (mode == 'img' ? '<img src="' : "\n\n<style");
	if (attr && attr.length && mode=='style' && sel)
	{
		for (var i=0; i<attr.length; i++)
		{
			out += (' ' + attr[i] + ' ');
		}
		out += (">\n" + sel + ' {background-image:url("');
	}
	out += (pos ? obj[obj.alea][pos] : obj[obj.alea]);
	out += (mode == 'img' ? '"' : "\");}\n");
	if (attr && attr.length && mode=='img')
	{
		for (var i=0; i<attr.length; i++)
		{
			out += (' ' + attr[i] + ' ');
		}
	}
	out += (mode == 'img' ? ' />' : "</style>\n\n");
	document.writeln(out);
}
