/**
 * ACCEUIL.JS
 * fichier Javascript contenant toutes les fonctions utiles à la page d'acceuil
 *
 *****/
 
/**
 * cette variable est la position du pointeur de dossier
 * besoin d'être en variable globale
 */ 
var positionDossier = 0;
var positionDossier2 = 1;

/**
 * fonction switchOnglet(num,total)
 * => affiche l'onglet numero num sur l'ensemble total d'onglet
 * num (int) = position de l'onglet
 * total (int) = nombre total d'onglet
 **/
 function switchOnglet(num,total)
{
  for (i=0;i<total;i++)
  {
    idOnglet="onglet_"+i;
    idLien="lien_"+i;

    _onglet=findObject(idOnglet);
    _lien=findObject(idLien);

    if (i==num)
    {
      classOnglet = "afficher";
      classLien = "selected";
    }
    else
    {
      classOnglet = "masquer";
      classLien = "unselected";
    }
     _onglet.className =classOnglet;
     _lien.className= classLien;
   }
}

/**
 * fonction switchOffre(num,total)
 * => affiche l'offre numero num sur l'ensemble total d'offre
 * num (int) = position de l'offre
 * total (int) = nombre total d'offre
 **/
 function switchOffre(num,total)
{
  for (i=0;i<total;i++)
  {
    idInfoOffre="infoOffre_"+i;
    idLien="lienOffre_"+i;

    _infoOffre=findObject(idInfoOffre);
    _lien=findObject(idLien);

    if (i==num)
    {
      classInfoOffre = "afficher";
      classLien = "selected";
    }
    else
    {
      classInfoOffre = "masquer";
      classLien = "unselected";
    }
     _infoOffre.className =classInfoOffre;
     _lien.className= classLien;
   }
}

/**
 * fonction switchDossier(num,total)
 * => affiche le dossier numero num sur l'ensemble total d'offre
 * num (int) = position de l'offre
 * total (int) = nombre total d'offre
 **/
 function switchDossier(num, num2, total)
{
  for (i=0;i<total;i++)
  {
   	idDossier = "idDossier_"+i;

    _dossier = findObject(idDossier);

    if (i == num || i == num2)
      	classDossier = "afficher";
    else
      	classDossier = "masquer";
      
     _dossier.className = classDossier;
   }
   if (num  == (total-1))
   {
	   	idDossier = "idDossier_0";
	   	_dossier = findObject(idDossier);
	   	classDossier = "afficher finCarsl";
	   	_dossier.className = classDossier;
   	}
}

/**
 * fonction next sert à passer au dossier suivant
 */
 function next(total)
 {
 	//si la position suivante est égale au totale des dossiers(en commencant à compter à 0) on passe à la position suivante
	if ((positionDossier2) >= (total - 1))
	{
		positionDossier = (total - 1);
		positionDossier2 = 0;	
	}
	else if(positionDossier == (total - 1))
	{
		positionDossier = 0;
		positionDossier2 = 1;
	}
	else
	{
		positionDossier++;
		positionDossier2++;
 	}
 	switchDossier(positionDossier,positionDossier2, total);		

 }
 
 /**
 * fonction previous sert à passer au dossier precedent
 */
 function previous(total)
 {
 	//si on se trouve en position 0 alors on passe à la position précédente
	if (positionDossier <= 0)
	{
		positionDossier = (total - 1);
		positionDossier2 = 0;
	}
	else if(positionDossier2 <= 0)
	{
		positionDossier--;
		positionDossier2 = (total - 1);
	}
	else
	{
		positionDossier--;
		positionDossier2--;
	}	
 	
 	switchDossier(positionDossier, positionDossier2, total);		

 }


