// JavaScript Document
// Joshua Simmons
// April 3, 2008

var divs;
var opac1;
var opac2;
var sty;
var doRotate = true;


// Hide the divs for stacking if there is javascript enabled, otherwise they will just stack
// have to do a try catch block because IE 
try {
sty = document.createElement('<style type = "text/css">#portfolio { visibility: hidden; }</style>');
}
catch(e) {
sty = document.createElement('style');
sty.type = "text/css";
sty.appendChild(document.createTextNode("#rotation { visibility: hidden; }"));
}
 
//append the style to the header 
document.getElementsByTagName("head")[0].appendChild(sty);
 
 
//Called to start the program, grabs all of the ps 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('p');
	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)", 500);
   
}

//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 ( doRotate ) {
	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)+")", 2250);
	}

     }

}

