//fading code based on script from www.clagnut.com
document.write("<style type='text/css'>#thephoto {visibility:hidden;} </style>");
window.onload = function() {switchChoose('1')}
poetList = new Array('1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg');
tempList = new Array();
imgList = new Array('photo1', 'photo2', 'photo3', 'photo4');
//choose image to fade out
function switchChoose(current){
	imgListLength = imgList.length;
	thisRand = 1 + Math.floor(Math.random() * imgListLength);
	thisPhoto = "photo" + thisRand;
	tempListLength = tempList.length;
	y = 0;
	for (x = 0; x < tempListLength; x++){
		if (tempList[x] == thisRand){
			y++;
		}
	}
	if (tempListLength == imgListLength){
		tempList = new Array();
		switchChoose(thisRand);
	}
	 else if (y > 0){
		switchChoose(current);
	} else {
		//tempList.push(thisRand);
		tempList[tempListLength] = thisRand;
		window.setTimeout("initImage(thisPhoto)", 2000);
	}
}
//choose image to replace fade-out
poetPosition = 4;
function switchImg(current){
	current_img = current;
	//increment the pointer
	if(poetPosition == (poetList.length-1)) {
		current_img.src = "images/"+poetList[poetPosition];
		poetPosition = 0;
	} else {
		current_img.src = "images/"+poetList[poetPosition];
		poetPosition++;
	}
}
function initImage(particular) {
  imageId = particular;
  image = document.getElementById(imageId);
  setOpacity(image, 100);
  image.style.visibility = 'visible';
  fadeOut(imageId,100);
}
function setOpacity(obj, opacity) {

  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}
function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
	//switchImg called to replace old image w/new, random
    if (opacity <= 99) {
      setOpacity(obj, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
    }
	else if (opacity > 99){
		switchChoose(objId);
	}
  }
}
function fadeOut(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity > 0) {
      setOpacity(obj, opacity);
      opacity -= 5;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
    }
	else if (opacity < 1){
		setOpacity(obj, 0);
		switchImg(obj);
		window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 400);
	}
  }
}