// JavaScript Document
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// REMPLACEMENT DU CONTENU D'UNE DIV
function envoieRequete(url,id)
 {
 var xhr_object = null;
 var position = id;
 if(window.XMLHttpRequest) xhr_object = new XMLHttpRequest();
 else
 if (window.ActiveXObject) xhr_object = new ActiveXObject("Microsoft.XMLHTTP");

 // On ouvre la requete vers la page désirée
 xhr_object.open("GET", url, true);
 xhr_object.onreadystatechange = function(){
 if ( xhr_object.readyState == 4 )
 {
 // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
 document.getElementById(position).innerHTML = xhr_object.responseText;
 }
 }
 // dans le cas du get
 xhr_object.send(null);

 }

// AFFICHE PROGRESSIF D'UNE DIV
function Suite(lien,affiche,hauteur) 
{ 
var objet = document.getElementById(affiche); // entre id div que tu veux faire apparaître ! 
var objet_ferm1 = document.getElementById('texte');
objet.style.visibility="visible";
if(objet.style.display == "none" || !objet.style.display) 
{ 
	if (objet_ferm1.style.display == "block")
	{
			var object_fermeture = objet_ferm1;
			var nom = "texte";
		object_fermeture.style.display = "none"
	}
	objet.style.display = "block"; 
	objet.style.overflow = "hidden"; 
	lien.innerHTML = "ouvrir"; 
	var hFinal = hauteur; //Hauteur finale (la hauteur une fois que ça aura fini de déplier !) 
	var hActuel = 0; //Hauteur initiale (la hauteur dès le début !) 
	var timer; 
	var fct = function () 
	{ 
		hActuel += 10; //Augmente la hauteur de 20px (tu peux modifier) tous les 40ms ! 
		objet.style.height = hActuel + 'px'; 
		if( hActuel > hFinal) 
		{ 
			clearInterval(timer); //Arrête le timer 
			//objet.style.overflow = 'inherit'; 
		} 
	}; 
	fct(); 
	timer = setInterval(fct,40); //Toute les 40 ms 
}
else if(objet.style.display == "block") 
{ 
	var hFinal = 0; //Hauteur finale (la hauteur une fois que ça aura fini de déplier !) 
	var hActuel = hauteur; //Hauteur initiale (la hauteur dès le début !) 
	var timer; 
	var fct = function () 
	{ 
		hActuel -= 20; //Augmente la hauteur de -20px (tu peux modifier) tous les 40ms ! 
		objet.style.height = hActuel + 'px'; 
		if( hActuel == 40) 
		{ 
			clearInterval(timer); //Arrête le timer 
			//objet.style.overflow = 'inherit'; 
			objet.style.display = "none"; 
		} 
	}; 
	fct(); 
	timer = setInterval(fct,40); //Toute les 40 ms 
	lien.innerHTML = 'fermer'; 
}
}

function affiche(affiche,affichage) {
	if (affichage == 'oui'){
		document.getElementById(affiche).style.display='block';
	}
	else {
		document.getElementById(affiche).style.display='none';
	}

}

// animation image defilante index

var CurrentW = 0;
var CurrentH = 0;
var sens = "gauche";	
function ScrollBackground(MaxW, MaxH, mSec){
	var taille_ecran=screen.width;
	var taille_fenetre=document.body.offsetWidth;
	//alert(taille_fenetre);
	var delta = MaxW - taille_fenetre;
	if ( sens == "droite"){
		sens = "droite";
		CurrentW++;
		if (CurrentW ==0){
			sens = "gauche";	
		}
	}
	else{
		CurrentW--;
		if (CurrentW == -delta){
			sens = "droite";	
		}
	}
	document.getElementById("main_index").style.backgroundPosition= CurrentW + "px " + CurrentH+ "px ";
	setTimeout("ScrollBackground("+MaxW+","+MaxH+","+mSec+")",mSec);

}

// animation ouverture d'image ( villas tanger )
//This code was created by the fine folks at Switch On The Code - http://blog.paranoidferret.com
//This code can be used for any purpose

function animate(elementID, newLeft, newTop, newWidth, newHeight, time, callback, newzindex, w_partielle,img_partielle)
{
  var el = document.getElementById(elementID);
  if(el == null)
    return;
 
  var cLeft = parseInt(el.style.left);
  var cTop = parseInt(el.style.top);
  var cWidth = parseInt(el.style.width);
  var cHeight = parseInt(el.style.height);
 
  var totalFrames = 1;
  if(time> 0)
    totalFrames = time/40;

  var fLeft = newLeft - cLeft;
  if(fLeft != 0)
    fLeft /= totalFrames;
 
  var fTop = newTop - cTop;
  if(fTop != 0)
    fTop /= totalFrames;
 
  var fWidth = newWidth - cWidth;
  if(fWidth != 0)
    fWidth /= totalFrames;
 
  var fHeight = newHeight - cHeight;
  if(fHeight != 0)
    fHeight /= totalFrames;
   
  doFrame(elementID, cLeft, newLeft, fLeft,
      cTop, newTop, fTop, cWidth, newWidth, fWidth,
      cHeight, newHeight, fHeight, callback,newzindex,w_partielle,img_partielle);

}

function doFrame(eID, cLeft, nLeft, fLeft,
      cTop, nTop, fTop, cWidth, nWidth, fWidth,
      cHeight, nHeight, fHeight, callback,newzindex,w_partielle,img_partielle)
{
  var el = document.getElementById(eID);
   if(el == null)
     return;

  cLeft = moveSingleVal(cLeft, nLeft, fLeft);
  cTop = moveSingleVal(cTop, nTop, fTop);
  cWidth = moveSingleVal(cWidth, nWidth, fWidth);
  cHeight = moveSingleVal(cHeight, nHeight, fHeight);

  el.style.left = Math.round(cLeft) + 'px';
  el.style.top = Math.round(cTop) + 'px';
  el.style.width = Math.round(cWidth) + 'px';
  el.style.height = Math.round(cHeight) + 'px';
   el.style.zIndex = newzindex;

  if(cLeft == nLeft && cTop == nTop && cHeight == nHeight
    && cWidth == nWidth)
  {
    if(callback != null)
      callback();
	  
	  if (nWidth == w_partielle){
		id_image = 'img_' + eID;
 		document.getElementById(id_image).style.width = nWidth + 'px';
  		document.getElementById(id_image).style.height = nHeight + 'px';
		document.getElementById(id_image).src = img_partielle;
		pendant_zindex = document.getElementById(eID).style.zIndex;
  		new_zindex = parseInt(pendant_zindex) - 2;
		document.getElementById(eID).style.zIndex = new_zindex;
		//alert("apres : "+pendant_zindex);
  }
    return;
  }
  setTimeout( 'doFrame("'+eID+'",'+cLeft+','+nLeft+','+fLeft+','+cTop+','+nTop+','+fTop+','+cWidth+','+nWidth+','+fWidth+','+cHeight+','+nHeight+','+fHeight+','+callback+','+newzindex+','+w_partielle+',"'+img_partielle+'")', 40);
 

  
}

function moveSingleVal(currentVal, finalVal, frameAmt)
{
  if(frameAmt == 0 || currentVal == finalVal)
    return finalVal;
 
  currentVal += frameAmt;
  if((frameAmt> 0 && currentVal>= finalVal)
    || (frameAmt <0 && currentVal <= finalVal))
  {
    return finalVal;
  }
  return currentVal;
}

function slideExample2(elementId, headerElement,img_complete,w_complete,h_complete,l_complete,t_complete,img_partielle,w_partielle,h_partielle,l_partielle,t_partielle,zindex)
{
   var element = document.getElementById(elementId);
  // ouverture	  
  id_image = 'img_' + elementId;
  old_zindex = document.getElementById(elementId).style.zIndex;
  new_zindex = parseInt(old_zindex) + 1;
  		//alert("pendant : "+new_zindex);

  if(element.up == null || element.down)
   {
      animate(elementId, l_complete, t_complete, w_complete, h_complete, 393, null, new_zindex,w_partielle,img_partielle);
      element.up = true;
      element.down = false;
	  id_image = 'img_' + elementId;
      headerElement.innerHTML = '<img id="'+id_image+'" src="'+img_complete+'" width="'+w_complete+'" height="'+h_complete+'">';
   }
  // fermeture
	else
   {
      animate(elementId, l_partielle, t_partielle, w_partielle, h_partielle, 393, null, new_zindex,w_partielle,img_partielle);
      element.down = true;
      element.up = false;
     // headerElement.innerHTML = '<img src="'+img_complete+'" width="'+w_complete+'" height="'+h_complete+'">';
}
   
}

