//function below makes quicklink dropdown appear on mouseover
sfHover = function() {
    var sfEls = document.getElementById("quicklinks").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
	sfEls[i].onmouseover=function() {
	    this.className+=" sfhover";
	}
	sfEls[i].onmouseout=function() {
	    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
	}
    }
}
    if (window.attachEvent) window.attachEvent("onload", sfHover);


// uses md5 hash to check for correct password; passes output to
// specified element id, 'outId'
//
// depends on 'hex_md5' function defined in "./md5.js"
function passwdCheck(outId){
    var input = document.passwdForm.passwd.value;
    var passwd = input.toLowerCase();
    var hash = hex_md5(hex_md5(passwd)+hex_md5(passwd));
    document.passwdForm.passwd.value = '';
    if (hash=='1df9ec6f6cd55eb6fda529ac034df6d8'){	
	document.getElementById('passwdHelp').innerHTML = 'Correct! My address is';
	document.getElementById(outId).innerHTML = 'n'+passwd+'&#64;math.uga.edu';
    }
    else {
	document.getElementById('passwdHelp').innerHTML = 'sorry, \''+input+'\' is not the correct name; for help, see the <a href="contact.html">contact page</a>';
	document.getElementById(outId).innerHTML = '';
	    }
}



// cycle pictures in col 3
var IDpicVar = 0;
var picArray = new Array(
			 "Niles1.png",
			 "Niles2.png",
			 "Niles3.png",
			 "Niles4.png",
			 "Niles5.png",
			 "Niles6.png",
			 "Niles7.png",
			 "Niles1m1.png",
			 "Niles2m1.png",
			 "Niles3m1.png",
			 "Niles1m2.png",
			 "Niles2m2.png",
			 "Niles3m2.png",
			 "Niles5m2.png",
			 "TourEiffel.png",
			 "Niles1-draw.png",
			 "Niles2-math.png",
			 "Niles6-oil.png",
			 "Niles6-sponge.png"
			 );

var mod = picArray.length;
function IDpicNavForward(){
    IDpicVar ++;
    IDpicVar = IDpicVar % mod;
    document.getElementById('IDpicture').src = "IDpics/"+picArray[IDpicVar];
    return false;
}
function IDpicNavBackward(){
    IDpicVar --;
    IDpicVar = (IDpicVar + mod) % mod;
    document.getElementById('IDpicture').src = "IDpics/"+picArray[IDpicVar];
    return false;
}
function IDpicRandom(){
    // hour of day (measured from 6 am)
    var hour = new Date().getHours() - 6 % 24;

    var seed = Math.floor(Math.max(hour-4,0)/19*mod*Math.random());
    // use non-uniform distribution:

    // random number ge 0 and lt hour
//     if (Math.floor(hour*Math.random()) < 5){
// 	// before 11am, this condition is always true
// 	// at 4pm, this is true with probability 1/2
// 	// at 9pm, true with probability 1/3
// 	// at 2am, true with probability 1/4
// 	// at 5am, true with probability 5/23
// 	var step1 = "day";
// 	IDpicVar = 0;
//     }
//     else {
// 	var step1 = "night";
// 	IDpicVar = 
//     }
    IDpicVar = seed;
    document.getElementById('IDpicture').src = "IDpics/"+picArray[IDpicVar];
    document.getElementById('picNo').innerHTML += " "+seed;
    document.getElementById('randomInfo').innerHTML = "Current number of hours away from 6 AM: "+hour+".<br />"+
	"You will see pictures 0 - "+(Math.floor(Math.max(hour-4,0)/19*mod))+" using the 'o' button";

    return false;
}
