/*----------------------------------------------*/
/*         XMLHTTPRequest		*/
/*----------------------------------------------*/

// Fonction permettant l'initialisation du  XMLHttpRequest en fonction du navigateur 
function getRequester()
{
	var xhr = null;
	try
	{
		xhr = new XMLHttpRequest();// MFF...
	}
	catch (e)
	{
		try
		{
			xhr = new ActiveXObject('Msxml2.XMLHTTP'); //MSIE 6
		}
		catch (e)
		{
			try
			{
				xhr = new ActiveXObject('Microsoft.XMLHTTP'); //MSIE 5
			}
			catch (e){ return false;}
		}
	}
	return xhr;
}

// Création, ouverture, envoi et test de la requete
function ajax( url, vars, callbackFunction)
{
	//Initialisation de l'objet 
	var xhr = getRequester();
	//Ouverture de l'objet 
	xhr.open( 'POST', url, true);
	xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded');
	
	xhr.onreadystatechange = function()
	{
		if( xhr.readyState == 4  && xhr.status == 200)
		{
			if( xhr.responseXML && xhr.responseXML.hasChildNodes())
			{
				callbackFunction(xhr.responseXML,true);
			}	
			else if( xhr.responseText)
			{
				callbackFunction(xhr.responseText,false);
			}		
		}
	};
	xhr.send( vars);
}


/*----------------------------------------------*/
/*  Fonctions propres au cas proposés */
/*----------------------------------------------*/
// Fonctions lancée aprés le retour de la réponse XMLHTTPRequest
function show(reponse_ajax,xml_txt)
{
	//alert (reponse_ajax);
	document.getElementById('conteneur_youtub').style.display = 'none';
	document.getElementById('affiche').style.zIndex=100;
	document.getElementById('affiche').style.display='inline';
	document.getElementById('affiche').innerHTML = reponse_ajax;
	setTimeout("close_affiche()",3000);

}

// Fonctions qui lance l'appel AJAX
function affiche($image,$largeur,$hauteur)
{
	// On lance la procédure Ajax en faisant appel à l'url créant le fichier HTML
	$taille_screen=screen.width;
	$left=($taille_screen-$largeur)/2;
	ajax('recup_affiche.php?image='+ $image + '&largeur='+ $largeur + '&left='+ $left + '&hauteur='+ $hauteur, null, show);
}

//
// hideLightbox()
//
function close_affiche()
{
	// get objects
	objOverlay = document.getElementById('affiche_over');
	objLightbox = document.getElementById('affiche');
	
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	document.getElementById('conteneur_youtub').style.display = 'block';

}