var photos=new Array()
var photoslink=new Array()
var textimgs=new Array()
var which=0
var xOpacity=.99;
var incOpacity = .05;

var strDirection = "";
var blnDisplayComplete = false;

//var prevIndex = "0";
var curIndex = "0";
var nextIndex = "1";

var strArrImages = "images/chicago_pasadena1.jpg,images/chicago_pasadena2.jpg,images/chicago_pasadena3.jpg";
var delay = parseInt(new String("5000"));
var transition = parseInt(new String("80"));

var photos = strArrImages.split(',');
//var photoslink = strArrLinks.split(',');
//var textimgs = strArrTextImg.split(',');

//Specify whether images should be linked or not (1=linked)
var linkornot=0
var autoTimeout=null;

var preloadedimages=new Array()
for (i=0;i<photos.length;i++){
  preloadedimages[i]=new Image();
  preloadedimages[i].src=photos[i];
}

//var preloadedtextimages=new Array()
//for (i=0;i<textimgs.length;i++){
//  preloadedtextimages[i]=new Image();
//  preloadedtextimages[i].src=textimgs[i];
//}

function delayfade() {
  autoTimeout = setTimeout(autoforward,delay);
}

delayfade();

function setOpacity() {
	if(xOpacity>.99) {
		xOpacity = .99;
		return;
	}
	
	//myButtonDiv = document.getElementById("sliderbuttons");
	curImage = document.getElementById("photoslider"+curIndex);
	
	//document.images.photoslider.style.opacity = xOpacity;
	curImage.style.opacity = xOpacity;
	//myButtonDiv.style.opacity = xOpacity;
	//document.images.textrotator.style.opacity = xOpacity;

	//document.images.photoslider.style.MozOpacity = xOpacity;
	curImage.style.MozOpacity = xOpacity;
	//myButtonDiv.style.MozOpacity = xOpacity;		
	//document.images.textrotator.style.MozOpacity = xOpacity;

	//document.images.photoslider.style.filter = "alpha(opacity=" + (xOpacity*100) + ")";
	curImage.style.filter = "alpha(opacity=" + (xOpacity*100) + ")";
	//myButtonDiv.style.filter = "alpha(opacity=" + (xOpacity*100) + ")";
	//document.images.textrotator.style.filter = "alpha(opacity=" + (xOpacity*100) + ")";
}

function onOpacity() {
  if (xOpacity >= .05) {  
    xOpacity -= incOpacity;
    setOpacity();
    setTimeout(onOpacity,transition);
  }
  else {
    xOpacity = 0;
    setOpacity();
    
    //switch images.
    // only goes forward.
	if (strDirection == "forward") {
	    //switch the index
		//if prev=0, cur=1, next=2.
		// forward prev=1, cur=2, next=0.
		// forward2 prev=2, cur=0, next=1.
	    tmpCurIndex = curIndex;
	    //tmpPrevIndex = prevIndex;
    	//prevIndex = tmpCurIndex;
	    curIndex = nextIndex;
	    nextIndex = tmpCurIndex;
    	//nextIndex = tmpPrevIndex;
	}
	//else {
		//if prev=0, cur=1, next=2.
		// backward prev=2, cur=0, next=1.
		// forward2 prev=1, cur=2, next=0.
	//    tmpCurIndex = curIndex;
	//    tmpPrevIndex = prevIndex;
    //	prevIndex = nextIndex;
	//    curIndex = tmpPrevIndex;
    //	nextIndex = tmpCurIndex;	
	//}

	curImage = document.getElementById("photoslider"+curIndex);
	nextImage = document.getElementById("photoslider"+nextIndex);
    //prevImage = document.getElementById("photoslider"+prevIndex);

	curImage.style.border = "0px solid #ccc";
	nextImage.style.border = "0px solid #ccc";
	//prevImage.style.border = "0px solid #ccc";

    nextImage.style.display = "none";
	curImage.style.display = "block";
	//prevImage.style.display = "none";
        
    //document.images.textrotator.src=textimgs[which];
    //document.images.textrotator.src=preloadedtextimages[which].src;
	
	//waitFor(document.images.photoslider);	
	
	offOpacity();
  }
}

function preloadimage() {
	nextImage = document.getElementById("photoslider"+nextIndex);
	nextImage.style.border = "1px solid #ccc";
	nextImage.style.opacity = 0;
	nextImage.style.MozOpacity = 0;
	nextImage.style.filter = "alpha(opacity=" + (0*100) + ")";
	//nextImage.src=photos[which];
	nextImage.src=preloadedimages[which].src;
}

function preloadnextimages() {
//alert("got preloadnext next='"+nextIndex+"' prev='"+prevIndex+"' curIndex='"+curIndex+"'");
	nextImage = document.getElementById("photoslider"+nextIndex);
	//nextImage.style.border = "1px solid #ccc";
	nextImage.style.opacity = .99;
	nextImage.style.MozOpacity = .99;
	nextImage.style.filter = "alpha(opacity=" + (.99*100) + ")";
	intNext = which + 1;
	if (intNext>photos.length-1){
    	intNext=0;
  	}
	//nextImage.src=photos[intNext];
	nextImage.src=preloadedimages[intNext].src;

	//prevImage = document.getElementById("photoslider"+prevIndex);
	//prevImage.style.border = "1px solid #ccc";
	//prevImage.style.opacity = .99;
	//prevImage.style.MozOpacity = .99;
	//prevImage.style.filter = "alpha(opacity=" + (.99*100) + ")";
	//intPrev = which - 1;
  	//if (intPrev<0) {
    //	intPrev=photos.length-1;
  	//}
	//prevImage.src=photos[intPrev];
	//prevImage.src=preloadedimages[intPrev].src;
}

function offOpacity() {
  if (xOpacity <= .95) {
    xOpacity += incOpacity;
    setOpacity();
    setTimeout(offOpacity,transition);
  }
  else {
    xOpacity = .99;
    setOpacity();
    
    //after the next image is turned on.  Turn the delay
    // transition back on.
    delayfade();
 
 	//and then preloadnextimages.
    preloadnextimages();
  }
}

//function backward(){

//  clearTimeout(autoTimeout);

  //alert("got to backward starting at "+which);
//  if (which>0){
//    which--;
//  }
//  else {
//    which=photos.length-1;
//  }
  //alert("got to backward ending at "+which);
//  preloadimage();
//  strDirection = "backward";
//  onOpacity();
//}

//function forward(){
//  
//  clearTimeout(autoTimeout);

  //alert("got to forward starting at "+which);
//  if (which<photos.length-1){
//    which++;
//  }
//  else {
//    which=0;
//  }
//  preloadimage();
  //alert("got to forward ending at "+which);
//  strDirection = "forward";
//  onOpacity();
//}

function autoforward(){
//alert("got autoforward prev='"+prevIndex+"' curIndex='"+curIndex+"' next='"+nextIndex+"'");
  if (which<photos.length-1){
    which++;
  }
  else {
    which=0;
  }
  //preloadimage();
  strDirection = "forward";
  onOpacity();
}

function waitForLoadComplete(){
	if(blnLoadComplete){ 
		setTimeout('waitForLoadComplete()', transition); 
	}
	else{ 
		offOpacity();
	} 
}


function transport(){
  //window.location=photoslink[which];
}