var intvl;

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	// determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		} 
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
	
// change the opacity for different browsers
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 + ")";
}

function crossfade(prevnext, millisec, suspendslideshow) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	var fadeout = 'feature' + currFeature;
	var fadein = 'feature' + (prevnext == 'prev' ? prevFeature() : nextFeature());
	
	changeOpac(100, fadeout);
	changeOpac(0, fadein);
	document.getElementById(fadein).style.display = "block";
	
	if (suspendslideshow)
		stopslideshow();
	
	// fade one feature in and the other out
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + fadein + "')",(timer * speed));
		setTimeout("changeOpac(" + (100 - i) + ",'" + fadeout + "')",(timer * speed));
		timer++;
	}
	if (suspendslideshow)
		startslideshow();
}

function startslideshow() {
	intvl = window.setInterval("crossfade('next', 700, false)", 10000);
}

function stopslideshow() {
	window.clearInterval(intvl);
}

function nextFeature() {
	return (currFeature < maxFeature ? ++currFeature : (currFeature = 1));
}

function prevFeature() {
	return (currFeature > 1 ? --currFeature : maxFeature);
}

// thanks, http://brainerror.net/scripts/javascript/blendtrans/
