/**
 *  Client : Ville de Fouesnant-les Gl&eacute;nan
 *  Projet : OUE451 - Refonte du portail web de la ville
 *           Site de la Mairie de la ville - JS
 *  Auteur : Julien Roulette
 *
 *  Fonctionnalité : Fonctions js dela page d'accueil
 *
 */
 
// change le texte situé sous les pictos météo, kioske, etc.
function chgtxt(text){
    if(!text) text='&nbsp;';
    var newtext = MM_findObj('soustitres-actions');
    newtext.innerHTML = text;
}

// trouve un objet dom dans la page courante
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;
}

var i=1; var timer = null;
var total=0;
var duree=5000; var isstopped=false;

function donotdisplay(menu){
    var k=1;
    var hideobj = MM_findObj(menu+''+k);
    while(hideobj!=null){
        hideobj.style.display='none';
        k++;
        hideobj = MM_findObj(menu+''+k);
    }
}

function donotdisplayfirst(menu){
    var k=2;
    var hideobj = MM_findObj(menu+''+k);
    while(hideobj!=null){
        hideobj.style.display='none';
        k++;
        hideobj = MM_findObj(menu+''+k);
        if(menu=='une-') total=total+1;
    }
}

function chgmenunext(nextorprevious){
    var oldi = i;
    var oldobjdesc = MM_findObj('une-'+i);
    oldobjdesc.style.display='none';
    //new Effect.Puff(oldobjdesc)
    if(nextorprevious=='next') i++;
    else if(nextorprevious=='previous') i--;
    else if(nextorprevious=='first') i=1;

    var objdesc = MM_findObj('une-'+i);
	if(objdesc == null) {
        if(i<1){
            /* MANTIS 44 - JBO - 04/09/07 >>> */
            i=total+1;
            /* MANTIS 44 - JBO - 04/09/07 <<< */
            var objdesc = MM_findObj('une-'+i);
		    new Effect.Appear(objdesc);
			//objdesc.style.display='block';
		}
        else {
			i=1;
			var objdesc = MM_findObj('une-'+i);
			new Effect.Appear(objdesc);
			//objdesc.style.display='block';
		}
	}
    else {
		new Effect.Appear(objdesc);
		//objdesc.style.display='block';
	}

	return objdesc;
}

function chgtimer(){
    var chger = chgmenunext('next');
    if(chger==null) chgmenunext('first');
}

function chgmenunexttimerleft(nextorprevious){
    if(isstopped) setPause();
    clearInterval(timer);
    chgmenunext(nextorprevious);
	timer = setInterval("chgtimer()", duree);
}

function launch(){
    var objLien = MM_findObj('pause-sys');
    isstopped = false;
	timer = setInterval("chgtimer()", duree);
    objLien.className='pause';
    var hideobj = MM_findObj('indicateur-lecteur');
    hideobj.style.display='none';
}

function setPause(){
    if(isstopped) launch();
    else {
        var objLien = MM_findObj('pause-sys');
        isstopped = true;
        clearInterval(timer);
        objLien.className='paused';

        var showobj = MM_findObj('indicateur-lecteur');
        showobj.style.display='block';
    }
}

var olda=1;

function affiche(id) {
    var oldobjdesc = MM_findObj('affiche-'+olda);
    oldobjdesc.style.display='none';

    var oldobjonglet = MM_findObj('onglet-'+olda);
    oldobjonglet.className='none';

    olda = id;
    var objdesc = MM_findObj('affiche-'+id);
    //objdesc.style.display='block';
    new Effect.Appear(objdesc);
    var objonglet = MM_findObj('onglet-'+id);
    objonglet.className='current';
}

function donotdisplayfirstaction(menu){
    var objh2 = MM_findObj('h2-action-1');
    objh2.className = 'current';

    var k=2;
    var hideobj = MM_findObj(menu+''+k);
    while(hideobj!=null){
        hideobj.style.display='none';
        k++;
        hideobj = MM_findObj(menu+''+k);
    }
}

var oldact = 1;

function action(i){
    if(oldact != i){
        var oldobjdesc = MM_findObj('action-'+oldact);
    	//oldobjdesc.style.display='none';
    	new Effect.BlindUp(oldobjdesc);

    	var objh2 = MM_findObj('h2-action-'+oldact);
    	objh2.className = 'none';

        var objdesc = MM_findObj('action-'+i);
    	if(objdesc == null) {
    	   var objdesc = MM_findObj('action-'+i);
    	   new Effect.BlindDown(oldobjdesc);
    	   //oldobjdesc.style.display='block';

    	   var objh2 = MM_findObj('h2-action-'+oldact);
    	   objh2.className = 'current';
    	}
        else {
    	   oldact=i;
    	   var objdesc = MM_findObj('action-'+i);
    	   new Effect.BlindDown(objdesc);
    	   //objdesc.style.display='block';
    	   var objh2 = MM_findObj('h2-action-'+i);
    	   objh2.className = 'current';
    	}
    }
}

//fonction nécessaire pour empêcher l'affichage de toutes les images
function doNotDisplayUne() {
    donotdisplayfirst('une-');
    timer = setInterval("chgtimer()", duree);

    var hideobj = MM_findObj('indicateur-lecteur');
    hideobj.style.display='none';
}
