// JavaScript Document
// Joshua Simmons
// April 3, 2008

var divs;
var opac1;
var opac2;
var sty;

//Called to start the program, grabs all of the divs underneath the Element with id Rotation
//sets the style to be visible, and starts the rotation
function start() {
	var rotate = document.getElementById('rotation');
	divs = rotate.getElementsByTagName('div');
	for (i=0; i<divs.length; i++) {
	setOpacity(i,0);
	divs[i].style.zIndex = divs.length - i ;
	}
   
rotate.style.visibility = 'visible';
   
opac1 = 100;
opac2 = 0;
setOpacity(0, opac1);
setTimeout("fade(1, 0)", 400);
   
}

//Makes sure the opacity is set right in all the different browsers
function setOpacity(num, opacity) {
	var obj = divs[num];
	obj.style.filter = "alpha(opacity:"+opacity+")";
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}


//works on fading the pictures - as one fades in the other fades out - increments the count and mods it to make 
//sure we are counting correctly - then proceeds to increase the z-index so that the one fading in will
//be on top and able to be clicked
function fade(num, num2) {
	if ( opac1 > 0 ) {
		opac1 -= 10;
		opac2 += 10;
		if (opac1 < 100 ) {
			setOpacity(num2, opac1);
		}
		else {
		setOpacity(num2, 99.999);
		}
		if (opac2 < 100 ) {
			setOpacity(num, opac2);
		}
		else {
			setOpacity(num, 99.999);
		}
		setTimeout("fade("+num+", "+num2+")", 75);
	}
	else {
		opac1 = 100;
		opac2 = 0;
		divs[parseInt(num)].style.zIndex = parseInt(divs[parseInt(num2)].style.zIndex) + 1;
		setTimeout("fade("+((num+1)%divs.length)+", "+((num2+1)%divs.length)+")", 7500);
	}

}

function doAjax()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById('rotation').innerHTML = xmlHttp.responseText;
      start();
      }
    }
  xmlHttp.open("GET","/testimonials.php",true);
  xmlHttp.send(null);
  }


window.onload = doAjax;
