// masthead functions for Fall 2008 2.009 WebSite
// MM_findObj is in menu_functions.js
// load masthead_functions.js after menu_functions.js

// 21 Sep 08 added function to randomize professor image w/event handlers
//           implemented in JavaScript so that dreamweaver template does not need to be updated

var preloadFlag = false;

function loadMasthead(path_to_root) {  
  // initialize variables
  image_dir = path_to_root+"imagesMasthead/"

  // sneak in a call to change the professor image - change in Fall 2009 to be a separate call in onLoad
  randomizeProfessor(path_to_root, image_dir);
  
  if (document.images) {
		ideas0 = newImage(image_dir+"ideas_0.jpg");
		ideas1 = newImage(image_dir+"ideas_1.jpg");
		ideas2 = newImage(image_dir+"ideas_2.jpg");
		sketch0 = newImage(image_dir+"sketch_0.jpg");
		sketch1 = newImage(image_dir+"sketch_1.jpg");
		sketch2 = newImage(image_dir+"sketch_2.jpg");
		mockup0 = newImage(image_dir+"mockup_0.jpg");
		mockup1 = newImage(image_dir+"mockup_1.jpg");
		mockup2 = newImage(image_dir+"mockup_2.jpg");
		tech0 = newImage(image_dir+"tech_0.jpg");
		tech1 = newImage(image_dir+"tech_1.jpg");
		tech2 = newImage(image_dir+"tech_2.jpg");
		final0 = newImage(image_dir+"final_0.jpg");
		final1 = newImage(image_dir+"final_1.jpg");
		final2 = newImage(image_dir+"final_2.jpg");
		preloadFlag = true;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// functions for event handlers cannot have parameters if they are to be added to the object dynamically (via Javascript)
function showWally() {
	var wally = document.getElementById("wally")
	wally.src = wally.imgPath+"wallyA.jpg"
}

function showWallyBlink() {
	var wally = document.getElementById("wally")
	wally.src = wally.imgPath+"wallyB.jpg"
}

function showWallyPoint() {
	var wally = document.getElementById("wally")
	wally.src = wally.imgPath+"wallyC.jpg"
}

function randomizeProfessor(path_to_root, image_dir) {
	var randomInt=Math.floor(Math.random()*10) // gnerate random integer 0-9 inclusive
	if (randomInt < 5) { // default professor image 50% of time	
		return;
	}
	
	// otherwise, adjust page for wally
	
	// shift search box down
	document.getElementById('search').style.top = '334px'
	
	// substitute professor with wally and event handlers
	prof_div = document.getElementById('professor')
	prof_div.innerHTML='<a href="'+path_to_root+'index.html"> \
          <img id="wally" src="'+image_dir+'wallyA.jpg" width="146" height="289" border="0" alt="Professor" \
		  onMouseOver="showWallyBlink()" onMouseOut="showWally()"> \
       </a>'
	   
	// save the path to the image directory with the image object
	document.getElementById("wally").imgPath = image_dir
	
	// add event handler to class name image
	courseNameImg = document.getElementById('courseName').getElementsByTagName('img')[0]
	courseNameImg.onmouseover=showWallyPoint  // must be reference to a no-parameter function
    courseNameImg.onmouseout=showWally        // must be reference to a no-parameter function
}
