function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Non è stato possibile impostare un gestore di eventi");
  }
}

addEvent(window,'load',init,false)

function init(){
	if (document.getElementById('sipario')){
		initXML('first');
		}
	if (document.getElementById('menu-left')){
		getChildren();
		}
	wait(15000);
	attivi();	
}

var clr=[0,630,0,0]
var sources=['source_0.xml','source_1.xml','source_2.xml']
var lastSource=sources.length-1;
var countSources = 0;
var timerIDopen;
var timerIDclose;
var pathXML="/xml/";
function initXML(step){
var btnNext=document.getElementById('arr-next');
var btnPrev=document.getElementById('arr-prev');
	btnNext.style.display="block";
	btnPrev.style.display="block";
	if (step=='first'){
	btnPrev.style.display="none";
	apri('first');
	}
	if (step=='next'){
		countSources++;
		if (countSources==lastSource){
		btnNext.style.display="none";
		}
		apri();
	}
	if (step=='prev'){
		countSources--;
		if (countSources==0){
		btnPrev.style.display="none";
		}
		apri();
	}
}

function apri(quale){
	if (quale=='first'){
		countSources=0;
	}
	document.getElementById('opera').style.display="none";
	var sip=document.getElementById('sipario');
	sip.style.display='block';
	if (clr[2]<=350){
		clr[2]+=30;
		timerIDopen=window.setTimeout('apri()',90)
		}
	sip.style.clip= 'rect(' + clr.join('px ') + 'px)';
	if (clr[2]>=350){
		clearTimeout(timerIDopen);
		loadXMLDoc(pathXML+sources[countSources]);
		}
}
function chiudi(timeToClose){
clearTimeout(timeToClose);
var sip=document.getElementById('sipario');
document.getElementById('opera').style.display="block";
if (clr[2]>0){
	clr[2]-=30;
	timerIDclose=window.setTimeout('chiudi()',90)
	}
	sip.style.clip= 'rect(' + clr.join('px ') + 'px)';
	if (clr[2]==0){
		clearTimeout(timerIDclose);
		}
}


var xmlhttp;
var doc;
var pathThumbs="/img/Picpezzi/";
var pathBig="/img/pezzi/";
function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.onreadystatechange=state_Change
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.onreadystatechange=state_Change
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    }
  }
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
  if (xmlhttp.status==200)
  {
  doc=xmlhttp.responseXML;//imposto il documento cosi' e' visibile a tutte le funzioni
  printData();

  }
  else
  {
  alert("Problemi nel caricamento dei dati:" + xmlhttp.statusText)
  }
  }
}

function printData(){
drawThumbs();
drawContent('first');
	if (okThumbs=='done'){
	timeToClose=setTimeout('chiudi(timeToClose)',2000);
	}
}
function drawThumbs(){
var xmlDoc=doc;
	var thumb=xmlDoc.getElementsByTagName("thumb");
	var cthumbs=document.getElementById('articolo-thumbs')
	cthumbs.innerHTML='';
		for (i=0;i<thumb.length;i++){
			newdiv=document.createElement("div");
			newpar=document.createElement("p");
			newanchor=document.createElement("a");
			newanchor.href="#";
			newthumb=document.createElement("img");
			newthumb.src=pathThumbs+thumb[i].firstChild.nodeValue;
			newthumb.setAttribute('id',i);
			newthumb.onclick=new Function( "drawContent('" + i + "');" )
			newthumb.onmouseover=new Function( "drawPeriodo('" + i + "');" )
			cthumbs.appendChild(newdiv);
			newdiv.appendChild(newpar);
			newdiv.appendChild(newanchor);
			newanchor.appendChild(newthumb);
			}
	okThumbs='done';
	return okThumbs;
}
function drawPeriodo(counter){
var currentNode=counter;

	var xmlDoc=doc;
var ctitolohead=document.getElementById('articolo-titolo-head');
var cperiodohead=document.getElementById('articolo-periodo-head');
var nrArticoli=xmlDoc.getElementsByTagName("articolo").length;
 if (currentNode>=0&&currentNode<nrArticoli){
  		var currentTitolo=xmlDoc.getElementsByTagName("titolo")[currentNode];
			ctitolohead.innerHTML=currentTitolo.firstChild.nodeValue;
			
		var currentTitolo=xmlDoc.getElementsByTagName("periodo")[currentNode];
			cperiodohead.innerHTML=currentTitolo.firstChild.nodeValue;	
		}
}

function drawContent(counter){
switch (counter){
	case"first":
	currentNode=0;
	break;
	case"next":
	currentNode++;
	break;
	case"prev":
	currentNode--;
	break;
 default : currentNode=counter; //impostato da click su thumbs...
}
var xmlDoc=doc;
var ctitolohead=document.getElementById('articolo-titolo-head');
var cperiodohead=document.getElementById('articolo-periodo-head');
var ctitolo=document.getElementById('articolo-titolo');
var cabstract=document.getElementById('articolo-abstract');
var ctext=document.getElementById('articolo-contenuto');
var cbig=document.getElementById('articolo-big');

var nrArticoli=xmlDoc.getElementsByTagName("articolo").length;
  if (currentNode>=0&&currentNode<nrArticoli){
		document.getElementById('btn-prev-contenuto').style.display="block";
		document.getElementById('btn-next-contenuto').style.display="block";
		if (currentNode==0){
			var btnc=document.getElementById('btn-prev-contenuto').style.display="none";
			}
		if (currentNode==nrArticoli-1){
			var btnc=document.getElementById('btn-next-contenuto').style.display="none";
			}
		var currentBig=xmlDoc.getElementsByTagName("big")[currentNode];
			cbig.src=pathBig+currentBig.firstChild.nodeValue;
			
  		var currentTitolo=xmlDoc.getElementsByTagName("titolo")[currentNode];
			ctitolohead.innerHTML=currentTitolo.firstChild.nodeValue;
			
		var currentTitolo=xmlDoc.getElementsByTagName("periodo")[currentNode];
			cperiodohead.innerHTML=currentTitolo.firstChild.nodeValue;	
  
		var currentTitolo=xmlDoc.getElementsByTagName("titolo")[currentNode];
			ctitolo.innerHTML=currentTitolo.firstChild.nodeValue;
		
		var currentAbstract=xmlDoc.getElementsByTagName("abstract")[currentNode];
			cabstract.innerHTML=currentAbstract.firstChild.nodeValue;
			
		var currentText=xmlDoc.getElementsByTagName("contenuto")[currentNode];
			ctext.innerHTML=currentText.firstChild.nodeValue;	
		}
	else {
		if (currentNode<=0){
			//var btnc=document.getElementById('btn-next-contenuto').style.display="none";
		}
	}
}

// CONTROLLA MENU-NEW
function sopra(el){

el.parentNode.style.backgroundColor = "#d28a36";

if(el.parentNode.id=="voice-1"){
el.parentNode.style.backgroundImage="url(../img/bkg_top_left_act.gif)";
el.parentNode.style.backgroundRepeat="no-repeat";
el.parentNode.style.backgroundPosition="left bottom";
 }
/* else if(el.parentNode.id=="voice-8") {
el.parentNode.style.backgroundImage="url(../img/bkg_top_right_act.gif)";
el.parentNode.style.backgroundRepeat="no-repeat";
el.parentNode.style.backgroundPosition="right bottom";
  }*/
}
function fuori(el){
var father = el.parentNode;
if(father.className=="on"){
return;
}
else{
  el.parentNode.style.backgroundColor = "#535353";

  if(el.parentNode.id=="voice-1"){
   el.parentNode.style.backgroundImage="url(../img/bkg_top_left.gif)";
   el.parentNode.style.backgroundRepeat="no-repeat";
   el.parentNode.style.backgroundPosition="left bottom";
  }
/*  else if(el.parentNode.id=="voice-8"){
   el.parentNode.style.backgroundImage="url(../img/bkg_top_right.gif)";
   el.parentNode.style.backgroundRepeat="no-repeat";
   el.parentNode.style.backgroundPosition="right bottom";
  }*/
 }
}

function attivi(){
var menu = document.getElementById('list-menu');
var voci = menu.getElementsByTagName('li');
for(var i=0;i<voci.length;i++){
 if(voci[i].className=="on"){
 var obj = voci[i].childNodes[0];
 
   if(voci[i].id=="voice-1"){
	voci[i].style.backgroundColor = "#d28a36";
    voci[i].style.backgroundImage="url(../img/bkg_top_left_act.gif)";
    voci[i].style.backgroundRepeat="no-repeat";
    voci[i].style.backgroundPosition="left bottom";
    }
/*	else if(voci[i].id=="voice-8"){
	voci[i].style.backgroundColor = "#d28a36";
	voci[i].style.backgroundImage="url(../img/bkg_top_right_act.gif)";
    voci[i].style.backgroundRepeat="no-repeat";
    voci[i].style.backgroundPosition="right bottom";
	}*/
	else{
	voci[i].style.backgroundColor = "#d28a36";
	  }
    }
  }
}



// CONTROLLA ROLLOVER MENU-OLD
/*
function sopra(q){
if(q.className=='menu-voice on'){
q.className = "menu-voice on";
  }
  else {
q.className = "menu-voice-over";	  
  }
}

function fuori(z){
if(z.className=='menu-voice on'){
z.className = "menu-voice on";
}
else {
z.className = "menu-voice";
 }
} 
*/
function getChildren(){
	
var lion=new Array();
var padre=document.getElementById('menu-left');
  if (padre){	 	
    var figli=padre.getElementsByTagName("li");
        for (i=0;i<figli.length;i++){
            if (figli[i].className=='on'){
                lion.push(figli[i]);
                }
            }
			//alert(lion[0].childNodes[0].nodeName)
        if (lion.length==1) {
            return;
        }
        else if (lion.length==2){
			  var divLev1 = lion[0].getElementsByTagName("div");
			  var pLev1 = divLev1[0].getElementsByTagName("p");
			  var aLev1 = divLev1[0].getElementsByTagName("a");
			  
			  divLev1[0].style.backgroundColor="#FDFCF8";
			  
				  if(pLev1[0].className=="brd-top"){
					  pLev1[0].style.backgroundImage="url(/img/newmenu/lev1_off_top.gif)";
					  }
				  if(pLev1[1].className=="brd-bot"){
					  pLev1[1].style.backgroundImage="url(/img/newmenu/lev1_off_bot.gif)";
					  }	  
				
			  aLev1[0].style.color="#666666";
			
		  }	
		  else if (lion.length==3){	
			  //alert(lion[0].childNodes[0]);
			  
			  var divLev1 = lion[0].getElementsByTagName("div");
			  var pLev1 = divLev1[0].getElementsByTagName("p");
			  var aLev1 = divLev1[0].getElementsByTagName("a");
			  
			  var divLev2 = lion[1].getElementsByTagName("div");
			  var pLev2 = divLev2[0].getElementsByTagName("p");
			  var aLev2 = divLev2[0].getElementsByTagName("a");
			  //alert(pLev2.length)
			  
			  divLev1[0].style.backgroundColor="#FDFCF8";
			  
				  if(pLev1[0].className=="brd-top"){
					  pLev1[0].style.backgroundImage="url(/img/newmenu/lev1_off_top.gif)";
					  }
				  if(pLev1[1].className=="brd-bot"){
					  pLev1[1].style.backgroundImage="url(/img/newmenu/lev1_off_bot.gif)";
					  }	  
				
			  aLev1[0].style.color="#666666";
			 
			  divLev2[0].style.backgroundColor="#F7F7F7";
			 
				  if(pLev2[0].className=="brd-top"){
					  pLev2[0].style.backgroundImage="url(/img/newmenu/lev2_off_top.gif)";
					  }
				  if(pLev2[1].className=="brd-bot"){
					  pLev2[1].style.backgroundImage="url(/img/newmenu/lev2_off_bot.gif)";
					  }
				  aLev2[0].style.color="#CD9934";	  
		 }
			  
		
      
	}
}
function inviaAmico(){
	window.open('/egypt/invia.jsp','','width=500, height=550')
	}
	
function addPreferiti(){
	if(window.sidebar){
		window.sidebar.addPanel(document.title,document.location.href,"");// IE
	}
		else{
window.external.AddFavorite(document.location.href, document.title); // Firefox, Mozilla, ecc.
	}
}
    
	
	var timerID=null;
	//var pathSlide = "http:\\iside.domino.it\MuseoEgizio\slideshow\top_imma" + "\\";
	var pathSlide = "/img/slide/";
	var currentImg = 1;
	var currOpacity=0;
	var direction = 0;
	var stato = 0;
	slide1= new Image(848,150).src= pathSlide + "top_1.jpg";;
	slide2= new Image(848,150).src= pathSlide + "top_2.jpg";;
	slide3= new Image(848,150).src= pathSlide + "top_3.jpg";;
	slide4= new Image(848,150).src= pathSlide + "top_4.jpg";;
	slide5= new Image(848,150).src= pathSlide + "top_5.jpg";;
	/*slide1.src= pathSlide + "top_1.jpg";
	slide2.src= pathSlide + "top_2.jpg";
	slide3.src= pathSlide + "top_3.jpg";
	slide4.src= pathSlide + "top_4.jpg";
	slide5.src= pathSlide + "top_5.jpg";*/
	//alert(pathSlide);
	
	function doFade(){
		if(currentImg==5){
			currentImg=0;
			}
		
		opaco=document.getElementById('slide');
		
		//alert(opaco);
		//alert(opaco.style.filter)
		if(direction!=null){
			if(stato==0 && direction==0){
				currOpacity=99;
				limitOpacity=0;
				resetOpacity=0;
				operatore='meno';
				controllo='>=';
			}
			else if(stato==1 && direction==1){
				currOpacity=0;
				limitOpacity=99;
				resetOpacity=99;
				operatore='piu';
				controllo='<=';
			}
		}
		if (eval(currOpacity+controllo+limitOpacity)){
			//alert(currOpacity/100);
			if (operatore=='meno'){
				currOpacity=currOpacity-3;
			}
			else{
				currOpacity=currOpacity+3;
			}
			//alert(currOpacity);
			opaco.style.filter="alpha(opacity="+currOpacity+")";
			opaco.style.opacity=currOpacity/100;
			direction = null;
			timerID=window.setTimeout("doFade()",1);
			//complete=false;
			return;
			}
	complete=true;
	if (complete==true){
		//alert(currOpacity/100);
		
		if (currOpacity>0){
			opaco.style.filter="alpha(opacity=100)";
		    opaco.style.opacity=1;
			stato = 0;
			direction = 0;
			wait(15000);
			}
		else{
			stato = 1;
			direction = 1;
			currentImg=currentImg + 1;
			opaco.src= eval("slide" + currentImg);			 
			wait(10);
			}
		}
	}
	function wait(delay){
		var ritardo = setTimeout("doFade()", delay);
		}

