function cycleLearn() {
    if(document.getElementById('learn_bug')) {
        var rand = Math.floor(Math.random()*4)
        document.getElementById('learn_bug').style.backgroundImage = "url(assets/css/images/learn_"+rand+".jpg)";
    }
}

function cycleSpotlight() {
	spotlight_captions = new Array();
	
	// captions: (link-url,image-path,title,text-block)
	spotlight_captions[0] = Array('about/spotlight/','spotlight-kronos-quartet.jpg','Kronos Quartet','Students in chamber music program participate in quartet master class');
	spotlight_captions[1] = Array('faculty-and-staff/alphabetical-directory/haimo-ethan/','spotlight-ethan.jpg','Ethan Haimo','Ethan Haimo, professor of music, recently published <em>Schoenberg\'s Transformation of Musical Language <em>');
	spotlight_captions[2] = Array('about/spotlight/orchestra/','spotlight-PaulAppleby.jpg','Vocal performance alumnus wins national opera award','');
	spotlight_captions[3] = Array('about/spotlight/john-blacklow/','spotlight-john-blacklow.jpg','John Blacklow','Pianist John Blacklow is performing concert tours throughout 2009-2010');
	
	// DO NOT CHANGE ANYTHING BELOW
	var num = spotlight_captions.length;
	spotlight_output = "";
	spotlight_number  = Math.floor(Math.random()*(num));
	if (spotlight_captions[spotlight_number][1] != "") {
		spotlight_output = '<a href="' + spotlight_captions[spotlight_number][0] + '"><img src="images/' + spotlight_captions[spotlight_number][1] + '" width="95" height="95" alt="' + spotlight_captions[spotlight_number][2] + '"" border="0" /></a>';
	}
	spotlight_output +=
		'<div id="spotlight-content">' +
		'<h3>' + spotlight_captions[spotlight_number][2] + '</h3>' +
		'<p>' + spotlight_captions[spotlight_number][3] + ' ' +
		'<a href="' + spotlight_captions[spotlight_number][0] + '">More &gt;</a></p>' +
		'</div>';
	
	document.write(spotlight_output);
}

function cycleFeature() {
    img_captions = new Array();

// captions: (link-url,image-path,title,text-block)
//    img_captions[n] = Array('#','http://music.nd.edu/assets/images/some.jpg','','');   

    img_captions[0] = Array('#','/assets/images/2.jpg','Student lesson','');
    img_captions[1] = Array('#','/assets/images/3.jpg','Students play piano and sing','');
    img_captions[2] = Array('#','/assets/images/4.jpg','A student playing piano','');
    img_captions[3] = Array('#','/assets/images/7.jpg','Crowley Hall of Music','');
    img_captions[4] = Array('#','/assets/images/8.jpg','Crowley Hall of Music','');
0

// DO NOT CHANGE ANYTHING BELOW
var num = img_captions.length;
    img_number  = Math.floor(Math.random()*(num));
    img_output =
        '<a href="' + img_captions[img_number][0] + '"><img src="' + img_captions[img_number][1] + '" alt="' + img_captions[img_number][2] + '" border="0" /></a>';

    document.write(img_output);

}


function cycleSub_img() {
    img_captionssub = new Array();
// captions: (link-url,image-path,title,text-block)
//    img_captions[n] = Array('#','http://music.nd.edu/assets/images/some.jpg','','');   

    img_captionssub[0] = Array('#','/assets/images/sub_img.jpg','Student playing the piano','');
    img_captionssub[1] = Array('#','/assets/images/chalkboard.jpg','A faculty member draws notes on a board','');
0

// DO NOT CHANGE ANYTHING BELOW
 var num = img_captionssub.length;
 img_numbersub  = Math.floor(Math.random()*(num));
    img_outputsub =
        '<a href="' + img_captionssub[img_numbersub][0] + '"><img src="' + img_captionssub[img_numbersub][1] + '" alt="' + img_captionssub[img_numbersub][2] + '" border="0" /></a>';

    document.write(img_outputsub);

}



function currentNav() {
    strCurrPage = getCurrentPath();
    navdiv = document.getElementById("nav-sidebar")
    if (!navdiv){return false;}
    navli = navdiv.getElementsByTagName("li")
   
    if ((typeof(strCurrPage[0])=="undefined")||strCurrPage[0].length<2){
        currPage = new Array();
        currPage[0] = strCurrPage;
    }
    else
    {
         currPage = strCurrPage;   
    }

    for (var i = 0; i < currPage.length; i++) {
        for (var j = 0; j < navli.length; j++) {
            strTestPath = getPath(navli[j].firstChild.href);
            if ((typeof(strTestPath[0])=="undefined")||strTestPath[0].length<2){
                testPath = new Array();
                testPath[0] = strTestPath;
            }
            else
            {
                testPath = strTestPath;   
            }

            for (var k = 0; k < testPath.length; k++) {
                if (cleanLastSlash(currPage[i]) == cleanLastSlash(testPath[k])) {
                    // alert(currPage[i] + ' == ' + testPath[k]);
                    navli[j].className = 'nav-current';
                }
                else
                {
                    // alert(currPage[i] + ' != ' + testPath[k]);
                }
            }
        }
    }
}


function getPath(someurl){
 d = document;
 csite = d.domain;
 sp = someurl.indexOf(csite) + csite.length;
 cpath = someurl.substring(sp);
 if (cpath.search(/index/)!=-1){
  re = "(.*?)\/index.shtml";
  myRe = new RegExp(re);
  cpath = cpath.match(myRe);
 }
return cpath;
}

function cleanLastSlash(someurl){
 lastchar = someurl.length-1;
  if (someurl!="") {
    if (someurl.charAt(lastchar)=="/"){someurl = someurl.substring(0,(someurl.length-1))}
  }
return someurl;

}

function getCurrentPath(){
 d = document;
 cpage = d.URL;
 csite = d.domain;
 sp = cpage.indexOf(csite) + csite.length;
 cpath = cpage.substring(sp);
 if (cpath.search(/index/)!=-1){
  re = "(.*?)\/index.shtml";
  myRe = new RegExp(re);
  cpath = cpath.match(myRe);
 }
return cpath;
}

window.onload = init;

function init(){
    currentNav();
    cycleLearn();
}