xfade=function(fadeType) {
  if(fadeType=="next") {
	if(currentPhoto>=photosArray.length-1) currentPhoto=-1;
	document.getElementById('photonew').src=photosArray[currentPhoto+1];
	currentPhoto++;
	if(currentPhoto>=photosArray.length-1) {
		preloaderObject=photosArray[0];
	} else {
		preloaderObject=photosArray[currentPhoto+1];
	}
  }
  if(fadeType=="prev") {
	if(currentPhoto<=0) currentPhoto=photosArray.length;
	document.getElementById('photonew').src=photosArray[currentPhoto-1];
	currentPhoto--;
	if(currentPhoto<=0) {
		preloaderObject=photosArray.length;
	} else {
		preloaderObject=photosArray[currentPhoto-1];
	}
  }
  if(fadeType=="pic") {
	currentPhoto=pic-1;
	document.getElementById('photonew').src=photosArray[currentPhoto];
  }
  if(photoOpacity>0) {
	photoOpacity-=5;
	setTimeout("xfade()",10);
	document.getElementById('photo').style.opacity=photoOpacity/100;
	document.getElementById('photo').style.filter="alpha(opacity="+photoOpacity+")";
  } else {
	document.getElementById('photo').src=document.getElementById('photonew').src;
	photoOpacity=100;
	document.getElementById('photo').style.opacity=1;
	document.getElementById('photo').style.filter="alpha(opacity=100)";
	humanCurrentPhoto=currentPhoto+1;
	if(document.getElementById('photocounter')) document.getElementById('photocounter').innerHTML=humanCurrentPhoto+"/"+photosArray.length;
  }
}
