//var max = maxImage();
var max=18;
var cpt = Math.floor(Math.random() * max);

function nomFichier(cpt)
{
	var numero = cpt.toString();
	if (cpt <=9)
	{
		numero =  "0"+cpt.toString();
	}
	return "/userfiles/image/bandeau/bandeau"+numero+".jpg";
}


function maxImage()
{
    var max = 1;
    while (isThere(nomFichier(max)))
    {
        max++;
    }
    return max-1;
}

function changeImages()
{
	cpt++;
	document.getElementById('ima').src=nomFichier(cpt);
	if(cpt>=max) cpt=0;
	setTimeout('changeImages()',5000);
}

// recupération de fonctions pour tester la présence d'une URL
function isThere(url) {
	var req= new AJ(); // XMLHttpRequest object
	try {
		req.open("HEAD", url, false);
		req.send(null);		
		return req.status== 200 ? true : false;
	}
	catch (er) {
		return false;
	}
}
function AJ() {
	var obj;
	if (window.XMLHttpRequest) obj= new XMLHttpRequest(); 
	else if (window.ActiveXObject){
		try{
			obj= new ActiveXObject('MSXML2.XMLHTTP.3.0');
		}
		catch(er){
			try{
				obj= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(er){
				obj= false;
			}
		}
	}
	return obj;
}


