// JavaScript Document
<!--

//top picture refresh
//set switch for new browsers

//set top picture variables
var pics = new Array();
pics[0] = "top-pic01.jpg";
pics[1] = "top-pic02.jpg";
pics[2] = "top-pic03.jpg";
pics[3] = "top-pic04.jpg";
pics[4] = "top-pic05.jpg";
pics[5] = "top-pic06.jpg";

var picCaps = new Array();
picCaps[0] = "SEM of Zr- based bulk metallic glass foam fabricated by densifying BMG powders and tungsten spaceholders using equal channel angular extrusion. (Arrow indicates direction of extrusion.) Cox, Mathaudhu, Hartwig, and Dunand, 2009";
picCaps[1] = "Sculpture by Picasso (Fernande Head) from the Art Institute of Chicago whose composition was measured by Marcus Young at NU as part of a study on 20th century sculpture composition.  Image courtesy and copyright: the Art Institute of Chicago. Young, et al., 2009";
picCaps[2] = "NiTi powders (NTP) densified by eutectic phase, consisting of a NiTi matrix (NT) containing bright Nb-rich phase, which are either elongated (N1) or blocky (N2). Bansiddhi and Dunand, 2009";
picCaps[3] = "Optical micgrograph of an E-Brite (Fe-based) alloy sandwich with a dense core and 50% porous faces. This structure is being examined for use in solid-oxide fuel cell interconnects, where the incorporated porosity can significantly reduce the weight of the stack and provide additional functionality as the fluid flow channels.";
picCaps[4] = "Superconducting MgB2 specimen deformed to 67% in four stages at 1000 C without any cracking. Initial and final MgB2 specimen heightsare 6.0 and 2.0 mm.  DeFouw and Dunand, 2009";
picCaps[5] = "Current Dunand Research Group members on the Northwestern University campus.";




var picCount = -1;

//check whether IE browser
	var isMSIE = -1;
	var browserNumber = 1;
	var browserName = navigator.appVersion;
	var firstLetter = browserName.indexOf("MSIE");
	if (firstLetter > -1){
	browserNumber = browserName.substring(firstLetter + 5, firstLetter + 8);
	}
	if(parseInt(browserNumber) >= 5.5)
	{
	isMSIE = 1}
	
start = function(){
//load the pictures
img1 = new Image(550,375) 
img1.onload = showDone; 
img1.src = "top-pic01.jpg"

img2 = new Image(550,375) 
img2.onload = showDone; 
img2.src = "top-pic02.jpg"

img3 = new Image(550,375) 
img3.onload = showDone; 
img3.src = "top-pic03.jpg"

img4 = new Image(550,375) 
img4.onload = showDone; 
img4.src = "top-pic04.jpg"

img5 = new Image(550,375) 
img5.onload = showDone; 
img5.src = "top-pic05.jpg"

img6 = new Image(550,375) 
img6.onload = showDone; 
img6.src = "top-pic06.jpg"
}
var loadCount = 0;
var wait = 5000;

function showDone(){
loadCount++;
if (loadCount == 6){
document.images["pic"].src = pics[5];
if(document.getElementById("pic")){
document.getElementById("stopButton").innerHTML = "Stop Pictures Above";
setTimeout("changePicture()", wait);
}
}
}

var stopCode = "no";

function changePicture() {
picCount++;
if (picCount > 5){
picCount = 0;
wait = wait + 2000}
if (wait < 6000){wait = 10000}
if (stopCode == "no"){
	if (isMSIE == 1){
document.getElementById("pic").filters.item(0).Apply();
document.getElementById("pic").src=pics[picCount];
document.getElementById("pic").filters.item(0).Play();
setTimeout ("document.getElementById('caption').innerHTML=picCaps[picCount]", 2000);
setTimeout("changePicture()", wait);
}
else
{
//document.getElementById("pic").filters.item(0).Apply();
document.getElementById("pic").src=pics[picCount];
//document.getElementById("pic").filters.item(0).Play();
setTimeout ("document.getElementById('caption').innerHTML=picCaps[picCount]", 50);
setTimeout("changePicture()", wait);

}

}
}

function stopPics(){
if (stopCode == "no"){
stopCode = "yes";
if (1){
document.getElementById("stopButton").innerHTML = "Start Pictures Above";
}
} else
if (stopCode == "yes"){
stopCode = "no";
document.getElementById("stopButton").innerHTML = "Stop Pictures Above";
changePicture();
}
}

function getPrevImage() {
		imageNum = (imageNum-1) % totalImages;
		var new_image = get_ImageItemLocation(imageArray[imageNum]);
		return(new_image);
	}
	
window.onload=start;

var COLLAPSABLE_PARENT_NAME = "collapsable";
var COLLAPSABLE_PARENT_TYPE = "div";
var COLLAPSABLE_CHILD_TYPE = "p";

var COLLAPSABLE_EXPAND = "[+]";
var COLLAPSABLE_SHRINK = "[-]";

init = function() {
    if(document.getElementById && document.createTextNode) {
        var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE);
        for(i=0;i<entries.length;i++)
            if (entries[i].className==COLLAPSABLE_PARENT_NAME)
                assignCollapse(entries[i]);
    }
}

assignCollapse = function (div) {
    var button = document.createElement('a');
    button.style.cursor='pointer';
    button.setAttribute('expand', COLLAPSABLE_EXPAND);
    button.setAttribute('shrink', COLLAPSABLE_SHRINK);
    button.setAttribute('state', -1);
    button.innerHTML='dsds';
    div.insertBefore(button, div.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0]);

    button.onclick=function(){
        var state = -(1*this.getAttribute('state'));
        this.setAttribute('state', state);
        this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block';
        this.innerHTML = this.getAttribute(state==1?'expand':'shrink');
    };                   
    button.onclick();
}


window.onload=init;

window.onload=function(){
start();
init();
}
