/******************************************************************************
 * Utility functions
 * author:      Kersing Huang <kh295@cornell.edu>
 * modified:    23 Jan 2009 
 *****************************************************************************/

/**
 * Highlights the main navigation link that corresponds to the current page
 */
function selectNav(id){
    var elem = document.getElementById(id);
    if(elem != null){
        var c = "#669966";
        var s = "solid 2px " + c;
        elem.style.borderTop = s;
        elem.style.borderLeft = s;
        elem.style.color = c;
    }
}

/**
 * Displays id and hides prev.
 */
function showHide(id, prevId){
    var elem = document.getElementById(id);
    var prevElem = document.getElementById(prevId);
    if(elem != null && prevElem != null && elem != prevElem){
        prevElem.style.display = "none";
        elem.style.display = "block";
        return id;
    }
	else if(prevId == ""){
		elem.style.display = "block";
		return id;
	}
    else{
        return prevId;
    }
}

/**
 * Randomly selects a photo from imgs and captions and displays it in 
 * banner and caption
 */
function nextPhoto(){
	var ind = Math.floor(Math.random()*imgs.length);
	while(prevInd == ind){
		ind = Math.floor(Math.random()*imgs.length);
	}
	prevInd = ind;
	var banner = document.getElementById("banner");
	var caption = document.getElementById("caption");
	banner.innerHTML = "<img src=\"images/banners/" + imgs[ind] + "\" class=\"banner\" />";
	caption.innerHTML = captions[ind];
	setTimeout("nextPhoto()",5000);
}