
xmlhttp="";
run=false;
slideshow=false;
busy=false;
halt=false;
function getXML(url){
	xmlhttp=null;
	if (window.XMLHttpRequest){
  		xmlhttp=new XMLHttpRequest();
  	}
	else if (window.ActiveXObject){
 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	if (xmlhttp!=null){
    	xmlhttp.onreadystatechange=state_Change;
 		xmlhttp.open("GET",url,true);
   		xmlhttp.send(null);
    }
	else{
   		alert("Your browser does not support XMLHTTP.");
    }
}

function state_Change(){
if (xmlhttp.readyState==4){
    if (xmlhttp.status==200){
			passResult(xmlhttp.responseXML);	
			//alert(xmlhttp.responseText);				
    }
    else{
    	alert("xml request mislukt");
    }
  }
}

function getNextPic(pid,op){
	
	//alert(document.getElementById('currentpic').src);
	if(op=="<"){
		dirnow="fw";
	}
	else{
		dirnow="rw"
	}
	if(dirnow!=direction && direction.length){		
		document.getElementById('currentpic').src=prev_pic;		
		changedirection=true;
	}
	else{
		changedirection=false;
	}		
	direction=dirnow;
	prp=document.getElementById('currentpic').src;
	prev_pic=prp;
	if(!halt){
		busy=true;
		url="index.php?fuseaction=pict.nextPic&operator=" + op +  "&pid=" + pid;
		action="next";
		getXML(url);
	}
	else{
		halt=false;	
	}
	//alert(res);
}
function passResult(xml){
	
	//alert(changedirection + " - " + direction + " - " + dirnow);
	/*if(changedirection){
		document.getElementById('currentpic').src=prev_pic;	
	}*/
	if(action=="next"){
		keys=new Array("pic_id","album_id","volgorde","naam","email","titel","beschrijving","slagzin","leeftijd","fotonaam","width","height","score","album_name","bgpict","bgwidth","bgheight","bgid");
		foto=new Array();
		//alert(xmlhttp.responseText);
		for(i=0; i<keys.length; i++){
			if(xml.getElementsByTagName(keys[i])[0].firstChild){
				foto[keys[i]]=xml.getElementsByTagName(keys[i])[0].firstChild.nodeValue;
			}
			else{
				foto[keys[i]]="";
			}
		}		
		if(run){
			if(changedirection){
				document.getElementById('currentpic').src=prev_pic;	
			}
			else{
				document.getElementById('currentpic').src=bgpicsrc;			
			}
		}
		
		picsrc=foto["album_name"] + '/medium/' + foto["fotonaam"];
		bgpicsrc=foto["album_name"] + '/medium/' + foto["bgpict"];
		pic_id=xml.getElementsByTagName("pic_id")[0].firstChild.nodeValue;		
		
		if(!run){
			document.getElementById('currentpic').src=picsrc;
			if(foto["height"]>foto["width"]){
				document.getElementById('picture').style.backgroundImage='url(dialandscape.gif)';
			}
			else{
				document.getElementById('picture').style.backgroundImage='url(diaportret.gif)';
			}
			run=true;
		}
			
			opacity("frontcurrentpic/frontdia",100,0,1500);
			if(slideshow){
				setTimeout("getNextPic(" + pic_id +  ",'<','slideshow')",4000);
			}
	}	
}
function openOrig(pid){
	window.open('index.php?fuseaction=pict.original&pic_id=' + pid,'origineel_formaat','width=800,height=600,resizable=yes,scrollbars=yes');
}
