//Dclaration des globales...
diaporama='';
id_dia_suivante='';
id_dia_precedente='';
//Vitesse du diaporama en millisecondes...
timingdiaporama=4000;

function printArticle(newsid){
	window.open('/actu/print/'+newsid+'&','impression','top=50, left=50, height=480, width=640, toolbar=no, resizable=no, location=no, menubar=no, status=no, scrollbars=yes');
}

function affImage(url,w,h){
	blu=window.open('', 'actuimage', 'top=50, left=50, height='+h+', width='+w+', toolbar=no, resizable=no, location=no, menubar=no, status=no, scrollbars=no');
	blu.document.open();
	blu.document.write('<html><body style="border:0px;margin:0px;padding:0px;"><img src="'+url+'" width="'+w+'" height="'+h+'" onclick="window.close();" style="cursor:pointer;" border="0"></body></html>');
	blu.document.close();
}

function playDiaporama(){
	
	OBJlecture=document.getElementById('bt0').style;
	OBJlecture.width='0px';
	OBJlecture.display='none';
	OBJpause=document.getElementById('bt1').style;
	OBJpause.width='100%';
	OBJpause.display='block';
	if(document.getElementById('bt01') && document.getElementById('bt11')){
		OBJlecture=document.getElementById('bt01').style;
		OBJlecture.width='0px';
		OBJlecture.display='none';
		OBJpause=document.getElementById('bt11').style;
		OBJpause.width='100%';
		OBJpause.display='block';
	}
	
	if(arguments.length > 1){
		topicid=arguments[1];
		changeDia(0,topicid);
		diaporama=setInterval("changeDia(0,"+topicid+")",timingdiaporama);
	}else{
		changeDia(0);
		diaporama=setInterval("changeDia(0)",timingdiaporama);
	}
}

function getXmlNodeValue(xmlNode){
  return Try.these(
    function() {return xmlNode.text;},
    function() {return xmlNode.textContent;}
  );
}

function htmlspecialchars(ch) {
   ch = ch.replace(/&/g,"&amp;")
   ch = ch.replace(/\"/g,"&quot;")
   ch = ch.replace(/\'/g,"'")
   ch = ch.replace(/</g,"&lt;")
   ch = ch.replace(/>/g,"&gt;")
   return ch
}

function changeDia(photoid){
	if ( (photoid==0) || (photoid=='') ) {
		photoid=id_dia_suivante;	
	}
	if(arguments.length > 1){
		topicid=arguments[1];
	}else{
		topicid='';
	}
	var handlerFunc = function(t) {
		var xmlDoc = t.responseXML;
		var xml_photo_courante = xmlDoc.getElementsByTagName('photo')[0];
		var xml_photo_suivante = xmlDoc.getElementsByTagName('photosuivante')[0];
		var xml_photo_precedente = xmlDoc.getElementsByTagName('photoprecedente')[0];
		
		var xml_news = xmlDoc.getElementsByTagName('news');
		var xml_news_title = xmlDoc.getElementsByTagName('newstitle');
		var xml_news_date = xmlDoc.getElementsByTagName('newsdate');
		var xml_topic = xmlDoc.getElementsByTagName('topic');
			
		id_news=xml_news[0].getAttribute('id');
		id_dia_suivante=xml_photo_suivante.getAttribute('id');
		id_dia_precedente=xml_photo_precedente.getAttribute('id');
		topic=xml_topic[0].getAttribute('name');
		
		if(xml_news[0].firstChild && xml_news[0].firstChild.nodeValue)
			var news=xml_news[0].firstChild.nodeValue;
		
		if(xml_news_title[0].firstChild && xml_news_title[0].firstChild.nodeValue)
			var newstitle=xml_news_title[0].firstChild.nodeValue;
		
		if(xml_news_date[0].firstChild && xml_news_date[0].firstChild.nodeValue)
			var newsdate=xml_news_date[0].firstChild.nodeValue;
	
		if(news != '' && newsdate != '' && newstitle !=''){
				document.getElementById('newstronc').innerHTML=news;
				document.getElementById('newsdate').innerHTML=newsdate;
				document.getElementById('newstitle').innerHTML=newstitle;
				document.getElementById('newstitle').href="/actu/"+topic+"/"+id_news+"&";
		}
		document.getElementById('diaori').innerHTML='<a href="/actu/'+topic+"/"+id_news+'&"><img src="'+xml_photo_courante.getAttribute('filepath')+'" style="cursor:pointer;margin:5px auto;" id="diapo" title="'+htmlspecialchars(newstitle)+'"/></a>';
	}
	url='/js/actu_diaporama.php';
	if(topicid != '')
		params='photoid='+photoid+'&topicid='+topicid;
	else
		params='photoid='+photoid;
	var opt={
		method:'post',
		postBody:
		params,
		onSuccess:handlerFunc
	}
	new Ajax.Request(url,opt);
}

function pause(){
	OBJlecture=document.getElementById('bt0').style;
	OBJlecture.width='100%';
	OBJlecture.display='block';
	OBJpause=document.getElementById('bt1').style;
	OBJpause.width='0px';
	OBJpause.display='none';
	if(document.getElementById('bt01') && document.getElementById('bt11')){
		OBJlecture=document.getElementById('bt01').style;
		OBJlecture.width='100%';
		OBJlecture.display='block';
		OBJpause=document.getElementById('bt11').style;
		OBJpause.width='0px';
		OBJpause.display='none';
	}
	clearInterval(diaporama);
}
