/*

	    $Id: RotateImagesMain.js,v 1.4 2008/05/22 14:17:46 jre Exp $
	Purpose: To rotate images on the Main page

*/
									//Don't rotate the images on the first call
var rotate = false;
									//Create array of available pictures
var Images = new Array();
var num = 0;

Images[num++] = new ImageObject("../Images/BarnardObservatory_95x93.gif", "Barnard Observatory on the Ole Miss Campus");
Images[num++] = new ImageObject("../Images/CollegeHillChurch_95x93.gif", "College Hill Church");
Images[num++] = new ImageObject("../Images/CottonField_95x93.gif", "Lafayette County Cotton Field");
Images[num++] = new ImageObject("../Images/DoubleDeckerBus_95x93.gif", "Double Decker Bus");
Images[num++] = new ImageObject("../Images/Farmland_95x93.gif", "Lafayette County Farmland");
Images[num++] = new ImageObject("../Images/FarmWithSilo_95x93.gif", "Lafayette County Farm");
Images[num++] = new ImageObject("../Images/LafayetteCourthouse_95x93.gif", "Lafayette County Courthouse");
Images[num++] = new ImageObject("../Images/LafayetteLibrary_95x93.gif", "Oxford/Lafayette Public Library");
Images[num++] = new ImageObject("../Images/Lyceum_95x93.gif", "Lyceum on the Ole Miss Campus");
Images[num++] = new ImageObject("../Images/PuskusLakeSunset_95x93.gif", "Puskus Lake at Sunset");
Images[num++] = new ImageObject("../Images/RowanOak_95x93.gif", "Rowan Oak");
Images[num++] = new ImageObject("../Images/SardisInDistance_95x93.gif", "Sardis");
Images[num++] = new ImageObject("../Images/TaylorCottonGin_95x93.gif", "Taylor Cotton Gin");
Images[num++] = new ImageObject("../Images/VentressHall_95x93.gif", "Ventress Hall on the Ole Miss Campus");
Images[num++] = new ImageObject("../Images/YoconaCommunityCenter_95x93.gif", "Yocona Community Center");
Images[num++] = new ImageObject("../Images/YoconaRiver_95x93.gif", "Yocona River");
Images[num++] = new ImageObject("../Images/ChanceryCourt_95x93.gif", "Lafayette County Chancery Court");
Images[num++] = new ImageObject("../Images/DetentionCenter_95x93.gif", "Lafayette County Detention Center");
Images[num++] = new ImageObject("../Images/Faulkner_95x93.gif", "William Faulkner on the Square");
Images[num++] = new ImageObject("../Images/Grader_95x93.gif", "Historic Grader");

// Purpose: To provide an image object to add to array
function ImageObject(source, description) {
	this.image = new Image();
	this.image.src = source;
	this.image.alt = description;
	this.image.title = description;
}

// Purpose: To Replace image with new image
function RotateImage(location, index) {

	setOpacity(document[location], 0);
	
	document[location].src = Images[index].image.src;
	document[location].alt = Images[index].image.alt;
	document[location].title = Images[index].image.title;
	
	fadeIn(location, 0);
	
}

// Purpose: To returns a random number between 1 an n
function rand ( n ){
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

// Purpose: Fade image into view
function fadeIn(location, opacity) {

    if (opacity <= 100) {
    
		setOpacity(document[location], opacity);
		opacity += 10;
		setTimeout("fadeIn('"+location+"',"+opacity+")", 150);
		
    }
}

// Purpose: Set opacity of object
function setOpacity(obj, opacity) {

	opacity = (opacity == 100)?99.999:opacity;
  
  	// IE/Win
  	obj.style.filter = "alpha(opacity:"+opacity+")";
  
  	// Safari<1.2, Konqueror
  	obj.style.KHTMLOpacity = opacity/100;
  
  	// Older Mozilla and Firefox
  	obj.style.MozOpacity = opacity/100;
  
  	// Safari 1.2, newer Firefox and Mozilla, CSS3
  	obj.style.opacity = opacity/100;
  	
}

// Purpose: To create a list of unique number from the 1 to range
function CreateUniqueList(list, size, range){
	
	var addNum;
	var newNum;
	var n;
	
	while (list.length < size){
	
		addNum = true;
		newNum = rand(range);
		
		for (n in list){
		
			if (list[n] == newNum){
			
				addNum = false;
				break;
			}
		}
		if (addNum){
		
			list.push(newNum);
		
		}
	}
}

// Purpose: To rotate the pictures on the web page every 30 seconds
function RotatePictures() {
	
	if (rotate){
	
		var list = new Array()
		
		CreateUniqueList(list, 8, Images.length - 1);
		
		RotateImage("BottomPicture1Image", list[0]);
		RotateImage("BottomPicture2Image", list[1]);
		RotateImage("BottomPicture3Image", list[2]);
		RotateImage("BottomPicture4Image", list[3]);
		RotateImage("BottomPicture5Image", list[4]);
		RotateImage("BottomPicture6Image", list[5]);
		RotateImage("BottomPicture7Image", list[6]);
		RotateImage("BottomPicture8Image", list[7]);
	
	}
	else{
	
		rotate = true;
		
	}
	
	setTimeout("RotatePictures()", 30000);
}