
function RotationPub(objet,xmlfile)
{
    	//private
    	var m_objet = objet; //pour regle bug interval
	var m_file = xmlfile;
	var m_width = 280;
	var m_height = 90;
	var m_wait = 5;
	var m_conteneur = "test";
	
	var publicites = new Array();
	var intervalId;        //timer d'interval
	var no_pub = 0;
	
	//public
	this.SetWidth = SetWidth;
	this.SetHeight = SetHeight;
	this.SetWaitTime = SetWaitTime;
	this.ShowPub = ShowPub;
	this.AffPub = AffPub;
	this.NextPub = NextPub;   
	
	//methodes
	function SetWidth( width ) 
	{
		m_width = width;
	}
	
	function SetHeight( height ) 
	{
		m_height = height;
	}
	
	function SetWaitTime( wait ) 
	{
		m_wait = wait;
	}

	//afficher les pubs	
	function ShowPub( conteneur)
	{
		m_conteneur = conteneur;
		if (ImportXML())
		{
			if(ReadXML())
			{
				if(publicites.length > 1)
					intervalId = setInterval (m_objet+".NextPub()", publicites[no_pub]["delay"] * 1000)
				AffPub();
			}
			else
				document.write("Publicités");		
		}
		else
			document.write("Publicités");
	}
	
	function NextPub()
	{
		clearInterval (intervalId);
		intervalId = setInterval (m_objet+".NextPub()", publicites[no_pub]["delay"] * 1000);
		opacity('img_pub', 100, 0, 1000);
		setTimeout(m_objet+".AffPub()", 1000);
	}
	
	function AffPub()
	{	

		//recuperer le conteneur
		var div = null;
		if (document.getElementById)
		    div = document.getElementById(m_conteneur);
		else if (document.all)
		    div = document.all[m_conteneur];
		    
		if(div != null)
		{	
//			var pub = "<a href='" + publicites[no_pub]["info"] + "' target='_blank' " +
//		          "   alt='" + NewTitle + "' title='" + NewTitle + "'> " +
//		          "<img id='img_pub' src='" + publicites[no_pub]["location"] + "' border='0' width='" + m_width + "' height='" + m_height + "' " +
//		          " style='filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;' /> " +
//		          "</a>";
		          
				//remplacer les ' par des /" pour gérer les ' dans le title de l'image
		    var pub = "<a href=\"" + publicites[no_pub]["info"] + " \" target=\"_blank\" " +
		          "   alt=\"" + publicites[no_pub]["title"] + "\" title=\"" + publicites[no_pub]["title"] + "\"> " + 
		          "<img id=\"img_pub\" src=\"" + publicites[no_pub]["location"] + "\" border=\"0\" width=\"" + m_width + "\" height=\"" + m_height + "\" " +
		          " style=\"filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;\" /> " +
		          "</a>";

			div.innerHTML = pub;
			opacity('img_pub', 0, 100, 1000);

		}
		else
			document.write("Publicités");
		
		no_pub++;
		if(no_pub >= publicites.length)
			no_pub = 0;
	}
	
	//import XML
	function ImportXML()
	{	
		try //Internet Explorer
		{
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(m_file);
		}
		catch(e)
		{
		  	try //Firefox, Mozilla, Opera, etc.
		    	{
		    		parser=new DOMParser();
		    		xmlDoc=parser.parseFromString(m_file,"text/xml");
		    	}
		  	catch(e) 
		  	{
		  		return false;
		  	}
		}
		
		return true;
	}
	 
	//lire le fichier XML  
	function ReadXML()
	{
		try 
		{
			//balise parent
		 	var x = xmlDoc.getElementsByTagName('track');
			
			//recuperer les balises
			for (i = 0; i < x.length; i++)
			{
				publicites[i] = new Array();
				
				for (j = 0; j < x[i].childNodes.length; j++)
				{
					if (x[i].childNodes[j].nodeType != 1) continue;
					var balise = x[i].childNodes[j].nodeName;
					var data = x[i].childNodes[j].firstChild.nodeValue;
					
					publicites[i][balise] = data;
				}
			}
		}
		catch(e)
		{
			return false;
		}
		
		return true;
	}
}	

function opacity(id, opacStart, opacEnd, millisec) 
{
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

//change the opacity for different browsers
function changeOpac(opacity, id) 
{
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
