// JavaScript Document

//global variables for moving images and the timer on the main page
num = 0;
var timerID = 0;
var timerID2 = 0;
var picNum=0;
var brighter = false;
var pausetimer = 5;
var pagereload = false;

//global variable for the font size increase on the gallery pages
var timerIDs = new Array();// = 0;
timerIDs = 0;
var ogSize= 15;
var lgSize = 30;

//global vars for the gallery pages
var currentContext = "";
var svcCounter = 0;
var svcCount = 0;
double=false;


/****************************************************
 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 updateTimer()
{
	
	//getting the image and caption elements
	var currentImage = document.getElementById("viewer");
	var currentCaption = document.getElementById("caption");
	
	//Image array created
	var myImage = new Array();
	var alt = new Array();
	var caption = new Array();
	
	//Image Pool
	myImage[0] = "images/earth.gif";
	myImage[1] = "images/lightning.jpg";
	myImage[2] = "images/bug.gif";
	myImage[3] = "images/chemistry.gif";
	myImage[4] = "images/dna.jpg";
	
	alt[0] = "Picture of the Earth";
	alt[1] = "Picture of Lightning";
	alt[2] = "Picture of a Bug-Shaped Fractal";
	alt[3] = "Picture of Chemical Solutions";
	alt[4] = "Picture of a Double Helix (DNA Strand)";
	
	//Caption Pool
	caption[0] = "The Scientific World!";
	caption[1] = "Physical Science!";
	caption[2] = "Math and Science!";
	caption[3] = "Chemistry!";
	caption[4] = "Genetics!";
	
	//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 != 4)	picNum++;
				else picNum=0;
			
            	currentImage.src=myImage[picNum];
				currentImage.alt=alt[picNum];
				currentCaption.value = caption[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
			}
		}

        /*//changing picture 
        if(num==100) 
        {	
			if(picNum != 3)	picNum++;
			else picNum=0;
			
            currentImage.src=myImage[picNum];			
        }*/
        
        //assigning new opacity
        currentImage.style.filter = opac;
		currentCaption.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 != 4) picNum++;
				else picNum=0;
				
				currentImage.src=myImage[picNum];
				currentCaption.value = caption[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;
		currentCaption.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(){updateTimer();},50);
		}
		//advancing timer closer to 0
		else
			pausetimer--;
		
}

function changeme(what)
{
	//alert(what);
	document.getElementById(what).src = "images/buttons/blk_"+what+".gif";
}
function changebk(what)
{
	document.getElementById(what).src = "images/buttons/wht_"+what+".gif";	
}

function getCurrentMonth()
{
	var d = new Date();
	var month = new Array();
	
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	currentMonth = month[d.getMonth()].toLowerCase();
	
	window.location = "assignments/" + currentMonth + ".html";
}