// JavaScript Document
num = 0;
var timerID = 0;
var timerID2 = 0;
var picNum=0;
var brighter = false;
var pausetimer = 5;


/****************************************************
 load()
 function called when page loads.  
 begins the rotating image event on main page
 ****************************************************/
function load()
{
	pauseTimer(); //starting rotating images
}


/***************************************************
 updateTimer()
 function to advance timer and rotate images
 called by pause()
 ***************************************************/
function updatePicTimer()
{
	//getting the image and caption elements
	var currentImage = document.getElementById("me");
	
	//Image array created
	var myImage = new Array();
	var alt = new Array();
	
	//Image Pool
	myImage[0] = "../images/aaron/Aaron.jpg";
	myImage[1] = "../images/aaron/Aaron1.jpg";
	myImage[2] = "../images/aaron/Aaron2.jpg";
	myImage[3] = "../images/aaron/Aaron3.jpg";
	myImage[4] = "../images/aaron/Aaron4.jpg";
	myImage[5] = "../images/aaron/Aaron5.jpg";
	
	alt[0] = "Aaron and PK (cat)";
	alt[1] = "Aaron and King (cat)";
	alt[2] = "Aaron cooking/camping";
	alt[3] = "Aaron graduating";
	alt[4] = "Aaron at Grand Canyon";
	alt[5] = "Aaron & Wife at Grand Canyon";
	
	//opacity variable for IE only and FF
    var opac = "alpha(opacity=0)";
	var FFopac = 0;
	

    //handling IE
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        //fading out image
        if(!brighter)
		{
			num += 5;
			//diminishing image opacity
        	if(num<101) 
				opac = "alpha(opacity=" + (100-num) + ")";
			
			//changing to increasing image opacity
			else 
			{
				brighter = true;
				num=100;
			}
		}
		
		//fading in image 
		else
		{
			//changing image
			if(num==100)
			{	
				if(picNum != 5)	picNum++;
				else picNum=0;
			
            	currentImage.src=myImage[picNum];
				currentImage.alt=alt[picNum];
				
				
        	}
			
			num -= 5;
			
			//increasing image opacity
			if(num>0)
				opac = "alpha(opacity=" + (100 - num) + ")";
				
			//pausing the timer to give the image a few seconds of full opacity before
			//changing to decreasing image opacity and 
			else
			{
				brighter = false;
				num=0;
				opac = "alpha(opacity=" + (100 - num) + ")";
				clearInterval(timerID); //stopping the current timer		
				pauseTimer(); //starting the pause timer that will eventually start the fade-in/fade-out process over
			}
		}
        
        //assigning new opacity
       currentImage.style.filter = opac;
		
    }    
	
    //firefox(netscape)
    else
    {
        if(!brighter)
		{	
			num += .05;
        
			if(num<1.01) 
			{
				FFopac = 1-num;
			}
			else
			{
				brighter = true;
				num = 1;
			}
        }
		else
		{
			//changing picture and caption
			if(num==1) 
			{
				if(picNum != 5) picNum++;
				else picNum=0;
				
				currentImage.src=myImage[picNum];
				currentImage.alt=alt[picNum];
			}
			num -= .05;
			if(num>0)
				FFopac = 1-num;
			else
			{
				brighter=false;
				num = 0;
				FFopac = 1;
				clearInterval(timerID); //stopping the current time
				pauseTimer(); //starting the pause timer that will eventually start the fade-in/fade-out process over
			}
		}
		
		//setting opacity
		currentImage.style.MozOpacity = FFopac;
		
    }
}

/***************************************************
 pauseTimer()
 function to put a pause on rotating images on main 
 page.  called by pause()
 ***************************************************/
function pauseTimer()
{
	if(timerID2) clearInterval(timerID2); //clear rotating timer
    timerID2 = setInterval(function(){pause();},500);	//starting pause timer
}

/***************************************************
 pause()
 function to that calls function to stop image rotation
 for 2.5 seconds on main page
 ***************************************************/
function pause()
{
	
		//testing for the timer running down to 0
		if(pausetimer==0)
		{
			//reset the timer
			pausetimer=5;

			//clearing pause timer and beginning image rotation timer
			clearInterval(timerID2);
			if(timerID) clearInterval(timerID);
		    timerID = setInterval(function(){updatePicTimer();},50);
		}
		//advancing timer closer to 0
		else
			pausetimer--;
		
}