var imgList=new Array();
var i=0;
var current=0;
var toID=0;
var done=true;

// Set the order of the  rotation after the baby
imgList[i++]="fishpic2.jpg";
imgList[i++]="fishpic3.jpg";
imgList[i++]="fishpic4.jpg";
imgList[i++]="fishpic10.jpg";
imgList[i++]="fishpic5.jpg";
imgList[i++]="fishpic-6.jpg";
imgList[i++]="fishpic6.jpg";
imgList[i++]="fishpic9.jpg";
imgList[i++]="fishpic7.jpg";
imgList[i++]="fishpic8.jpg";
imgList[i++]="fishpic1.jpg";

// Set speed of fade and interval between fades
var dissolvespeed=2000;
var interval=8000;

function setCrossfade() {
	setTimeout("blendimage('main','bass',0," + dissolvespeed + ")",interval);
}

function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
    
    if (opacity<99) {
		done=false;
	} else {
		done=true;
	}
}

function nextFade() {
	if (done==true) {
		clearTimeout(toID);
		blendimage('main', 'bass', current, dissolvespeed);
	}
}

function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     
    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
     
    //make image transparent 
    changeOpac(0, imageid); 
     
    //make new image 
    document.getElementById(imageid).src = "images/" + imgList[imagefile] + "?" + Math.random(); 

    //fade in image 
    for(i = 0; i <= 99; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
        timer++;
    } 
    
    //setTimeout('document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"',(timer*speed));
    if (imagefile==imgList.length-1) {
    	imagefile=-1;
    }
    
    toID=setTimeout("blendimage('main','bass'," + ++imagefile + "," + dissolvespeed + ")",interval);
    current=imagefile;
}
