//coding: utf-8
//SetCookie(nom, valeur, expires, path, domain, secure)
function SetCookie(nom, valeur) {
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = nom+"="+escape(valeur)+
    ((expires == null) ? "" : ("; expires="+expires.toGMTString()))+
    ((path == null) ? "" : ("; path="+path))+
    ((domain == null) ? "" : ("; domain="+domain))+
    ((secure == true) ? "; secure" : "");
}
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}
function ReadCookie(nom) {
    if(document.cookie.indexOf(nom) == -1) return false;
    var arg = nom+"=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
	var j = i+alen;
	if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
	i = document.cookie.indexOf(" ",i)+1;
	if (i == 0) break;
    }
    return false;
}
function DelCookie(nom) {
    if(document.cookie.indexOf(nom) == -1) return false;
    var date = new Date;
    date.setFullYear(date.getFullYear()-1);
    SetCookie(nom,null,date, '/');
    return true;
}

/*********
 DIAPORAMA
*********/
var imgList = new Array();
var curImgIndex = ReadCookie('roubaud_diapo') ? ReadCookie('roubaud_diapo') : 0;
var timer = 0;

// Fonction de changement des images (rotation)
function rotation() {
    var imgShowIndex = imgList[parseInt(curImgIndex) + 1] ? parseInt(curImgIndex) + 1 : 0;
    imgList[imgShowIndex].style.display = 'block';
    imgList[parseInt(curImgIndex)].style.display = 'none';
    //alert('curImgIndex='+curImgIndex+' / imgShowIndex='+imgShowIndex);
    curImgIndex = imgShowIndex;
    SetCookie('roubaud_diapo', imgShowIndex, null, '/');
    /*
    imgList[curImgIndex].onmouseover = function() { clearInterval(timer); };
    imgList[curImgIndex].onmouseout = function() { timer = setInterval(rotation, 3000); };
    */
}
// Initialisation du rotation
function rotationInit(elementId) {
    if(document.getElementById || document.createElement) {
	imgList = document.getElementById( elementId ).getElementsByTagName('li');
	//on vérifie qu'il y ai au moins 2 images...
	if(imgList.length >= 2) {
	    if(!curImgIndex) {
		//on cache tous les li sauf le 0
		imgList[0].style.display = 'block';
		for(var k = 1; k < imgList.length; ++k) imgList[k].style.display = 'none';
	    }
	    else {
		for(var k = 0; k < imgList.length; ++k) {
		    if(k == parseInt(curImgIndex)) imgList[k].style.display = 'block';
		    else imgList[k].style.display = 'none';
		}
	    }
	    timer = setInterval(rotation, 3000);
	}
    }
}

