var xhr = null;
 
/* Fonction de creation de l'objet XMLHttpRequest qui resservira pour chaques fonctions AJAX*/
function getXhr()
 {
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest(); 
  else if(window.ActiveXObject)
   {  
    try
     {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch (e)
     {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
  else 
   { 
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour"); 
    xhr = false; 
   } 
 }
 
 
//fonction qui va enregistrer l'id session de pub pour être sur du bon clic !!!
 function lance_session_pub(id_pub)
 {
  getXhr();
  xhr.onreadystatechange = function()
   {
    if(xhr.readyState == 4 && xhr.status == 200)
     {
	 //rien à faire !
     }
   }
  xhr.open("POST",'/inc/squelette/ajax/session_pub.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send("id_pub="+id_pub);
 }



window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);

var d=document, imgsP = new Array(), zInterval = null, current=0, pause=false;

function so_init()
{
	if(!d.getElementById || !d.createElement)return;

	css = d.createElement('link');
	css.setAttribute('href','/inc/javascript/xfade/slideshow2.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	d.getElementsByTagName('head')[0].appendChild(css);

	imgsP = d.getElementById('rotator').getElementsByTagName('img');
	for(i=1;i<imgsP.length;i++) imgsP[i].xOpacity = 0;
	imgsP[0].style.display = 'block';
	imgsP[0].xOpacity = .99;
	document.getElementById("rotator").style.display="block";
	
	lance_session_pub(imgsP[0].id);
	
	setTimeout(so_xfade,5000);
}

function so_xfade()
{
	

	cOpacity = imgsP[current].xOpacity;
	nIndex = imgsP[current+1]?current+1:0;
	nOpacity = imgsP[nIndex].xOpacity;

	
	
	
	cOpacity-=.05;
	nOpacity+=.05;

	imgsP[nIndex].style.display = 'block';
	imgsP[current].xOpacity = cOpacity;
	imgsP[nIndex].xOpacity = nOpacity;

	setOpacity(imgsP[current]);
	setOpacity(imgsP[nIndex]);

	if(cOpacity<=0)
	{
		imgsP[current].style.display = 'none';
		current = nIndex;

		lance_session_pub(imgsP[current].id);
		setTimeout(so_xfade,5000);
	}
	else
	{
		setTimeout(so_xfade,50);
	}

	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}