// FIND ALL OF THE NEWS DIVS WITH AN ID OF "STORY_" AND COUNT THEM
// THEN RETURN THE NUMBER OF DIVS

function findStoryDiv()
	{
		var highestStory = "0";
		var divName ="";
		var divCounter = 0;
		var divCollection = document.getElementsByTagName("div");
		for (var i=0; i<divCollection.length; i++) {
			
			divName = String(divCollection[i].getAttribute("id"));			
						
			var temp = new Array();
			
			if(divName.substring(0,6) == "story_") {
				
				temp = divName.split('_');
				
				if(temp[1] > highestStory) { highestStory = temp[1];}

			} 
		}

		return highestStory;

	}

    
    
// HANDLER.JS
// SCRIPT FILE FOR THE MYERS SCHOOL OF ART SITE


function randomEvent(){

	var storyNumber = findStoryDiv();	
	var randomNum = Math.round(Math.random());
	
		if(randomNum == 1){
			var randomStory = Math.round(4*Math.random())+1;
			
			var storyNum = "story_" + randomStory;
			document.getElementById(storyNum).className = "active"
			
			var imageLinkNum = "image_" + randomStory;		
		}
		else if(randomNum == 0){	
			
			var randomStory = 0;
			while (randomStory < storyNumber){
				randomStory = Math.floor((storyNumber-3)*Math.random()) + 4;
			}
			
					
			var storyNum = "story_" + randomStory;
			if(storyNum){
				document.getElementById(storyNum).className = "active"
			}
			else{
				generateStory();
			}
			
			var imageLinkNum = "image_" + randomStory;		
		}
	
	var imageURL = document.getElementById(imageLinkNum).innerHTML;
	var toWrite = "<style>#banner {width: 950; height:  500px; background: url(" + encodeURI(imageURL) + ") center center; z-index: 1;}</style>";
	document.write(toWrite);
}



startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}

window.onload=startList();