var istegoweb = {};
istegoweb.DivRotation = {};
//istegoweb.DivRotation.DivList=['div_a', 'div_b', 'div_c'];
istegoweb.DivRotation.FadeSpeed = 20; // The rate of animation
istegoweb.DivRotation.FadeChange = 3; // The size of increments between animate steps
istegoweb.DivRotation.ChangeInterval = 10; // Every 5 seconds change a picture
istegoweb.DivRotation.idx = 0;
istegoweb.DivRotation.DivPrev = null;

istegoweb.DivRotation.SetOpacity = function(obj, opacity)
{
	// Fix for math error in some browsers
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Windows
	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;

	if (opacity === 0) {
		obj.style.visibility = 'visible';
	}
};

/* Gradually increase the opacity of the obj
 * opacity: starting opacity of element
 * change: the size of the increments between steps
 * speed: the rate of the animation	
 */
istegoweb.DivRotation.FadeIn = function(id, opacity, change, speed)
{
	var  obj = document.getElementById(id);
	
	// We don't use "alpha(opacity)" here because some
	// pictures might have "white spot" in the black area
	// of the picture
	if (-1 != navigator.userAgent.indexOf('MSIE')) {
		obj.style.filter="blendTrans(duration=0.5)";
		// Make sure the filter is not playing.
		if (obj.filters.blendTrans.status != 2) {
			obj.filters.blendTrans.apply();
			obj.style.visibility="visible";
			obj.filters.blendTrans.play();
		}
	} else {
		if (opacity <= 100) {
			this.SetOpacity(obj, opacity);
			opacity += change;
			setTimeout('istegoweb.DivRotation.FadeIn("'+obj.id+'", '+opacity+', '+change+', '+speed+')', speed);
		} else {
			this.SetOpacity(obj, 100);
		}
	}
};
/* Gradually decrease the opacity of the obj
 * opacity: starting opacity of element
 * change: the size of the increments between steps
 * speed: the rate of the animation	
 */
istegoweb.DivRotation.FadeOut = function(id, opacity, change, speed)
{
	var  obj = document.getElementById(id);

	if (opacity > 0) {
		this.SetOpacity(obj, opacity);
		opacity -= change;
		setTimeout('istegoweb.DivRotation.FadeOut("'+obj.id+'", '+opacity+', '+change+', '+speed+')', speed);
	} else {
		this.SetOpacity(obj, 0);
		obj.style.visibility = 'hidden';
	}
};

istegoweb.DivRotation.PhotoSlideStart = function()
{
	var div_curr;
	var i;

    if (!this.DivPrev) {
      this.idx = Math.floor(Math.random()*this.DivList.length);
     }
 
	div_curr = document.getElementById(this.DivList[this.idx]);
	this.idx = (this.idx+1) % this.DivList.length;

	if (this.DivPrev) {
		this.FadeOut(this.DivPrev.id, 100, this.FadeChange, this.FadeSpeed);
	}
	this.FadeIn(div_curr.id, 0, this.FadeChange, this.FadeSpeed);
	
	this.DivPrev = div_curr;
	setTimeout("istegoweb.DivRotation.PhotoSlideStart();", this.ChangeInterval * 1000);
};
