// JavaScript Document
var quote_timer = setInterval(startAnimateQuote, 3900);	// animation timer
var animate_timer = null;
var opacity = 100;
var fade = true;
var customerIndex = Math.round((customer_quote.length-1)*Math.random());

// preload all thumbnails, since they are so small
var images = new Array ();
for (i=0; i < customer_quote.length; i++)
{
	images[i] = new Image();
	images[i].src = customer_thumb_src[i];
}

function startAnimateQuote ()
{
	if (animate_timer != null)
	{
		clearInterval (animate_timer);
		animate_timer = null;
	}
	animate_timer = setInterval(animateQuote, 40);
}

function animateQuote ()
{
	if (fade)
	{
		opacity -= 20;
		if (opacity <= 0)
		{
			opacity = 0;
			fade = false;
			
			// switch the image and text
			customerIndex ++;
			if (customerIndex >= customer_quote.length) 
			{
				customerIndex = 0;
			}
			document.getElementById('customer_thumb').src = customer_thumb_src[customerIndex];
			document.getElementById('customer_quote').innerHTML = customer_quote[customerIndex];
		}
	}
	else
	{
		opacity += 20;
		if (opacity >= 100)
		{
			// stop animation
			opacity = 100;
			fade = true;
			if (animate_timer != null)
			{
				clearInterval (animate_timer);
				animate_timer = null;
			}
		}
	}
	setOpacity ('customer_thumb', opacity/100.0);
	setOpacity ('customer_quote', opacity/100.0);
}

function setOpacity(element, opacity)
{
  e = document.getElementById(element);
  e.style['opacity'] = opacity;	// standard CSS3
  e.style.filter = "alpha(opacity:"+(100*opacity)+")";	// IE
  e.style.KHTMLOpacity = opacity;	// KDE
  e.style.MozOpacity = opacity;		// Mozilla 
}