var fadetimeout = null;

function setOpacity(obj_id, level) {
  $(obj_id).style.opacity = level;
  $(obj_id).style.MozOpacity = level;
  $(obj_id).style.KhtmlOpacity = level;
  $(obj_id).style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function slideshow()
{
	//while (true)
	//{
	if (count > 1) //slideshow only if there are more than one pics
	{
	elem = $('prod_foto');
	if (elem.FadeInt) window.clearInterval(elem.FadeInt);
	elem.FadeInt = window.setInterval(
		function() {
			obj = $('prod_foto');
			fadeOut('prod_foto');
			nextFoto();
			fadeIn('prod_foto');
			}, 3000);
	//}
	}
}

function fadeIn(obj_id, i){

	if (!i) {
		i = 0;
		clearTimeout(fadetimeout);
	}
//	setTimeout("setOpacity(\""+obj_id+"\", " + i + ")", duration/steps);

	setOpacity(obj_id, i);
	if ( i < 1 )
	{
		fadetimeout = setTimeout("fadeIn(\""+obj_id+"\", " + (i+1/steps) + ")", duration/steps);
	}
}

function fadeOut(obj_id, i){
	if (!i) {
		i = 1;
		clearTimeout(fadetimeout);
	}
//	setTimeout("setOpacity(\""+obj_id+"\", " + i + ")", duration/steps);

	setOpacity(obj_id, i);
	if ( i > 0 )
	{
		fadetimeout = setTimeout("fadeOut(\""+obj_id+"\", " + (i-1/steps) + ")", duration/steps);
	}
}
