function getPhotoEssayId() { // sets photo essay id
cid=getCookie('cid'); // get last photo essay from cookie
if (cid) if (!pe_home[cid]) cid=false; // if cookie value is not within the current range of photo essays, clear it
if (!cid) cid=Math.ceil(Math.random()*pe_home.length-1); // if cookie was never set, start with a random photo essay id
cid++; // increment the photo essay id by 1
if (cid>pe_home.length-1) cid=0; // if current photo essay id is greater than the max number of photo essays, start at 1 again
setCookie('cid',cid); // set the cookie to the current photo essay id
return cid;
};

function fillPhotoEssay(id) { // fills in the photo essay using the current photo essay id
if (!id) id=pe_home[getPhotoEssayId()]; // get the current photo essay id
for (i=1;i<4;i++) document.getElementById('essPan'+i+'t').innerHTML=pe[id]['c'+i]; // fill the captions
if (document.getElementById('essayCategory')) document.getElementById('essayCategory').innerHTML=pe[id]['cat']; // fill the essay category
if (document.getElementById('essayCategory2')) document.getElementById('essayCategory2').innerHTML=pe[id]['cat']; // fill the essay category
for (i=1;i<4;i++) if (document.getElementById('essPan'+i)) document.getElementById('essPan'+i).style.backgroundImage='url(http://www.duke.edu/photoessays/'+pe[id]['id']+'/'+i+'.jpg)'; // fill the main images
if (document.getElementById('bottomHalf')) document.getElementById('bottomHalf').style.backgroundImage='url(http://www.duke.edu/photoessays/'+pe[id]['id']+'/background.jpg)'; // fill the background image
if (document.getElementById('bottomfail')) document.getElementById('bottomfail').style.visibility='visible'; // fill the background image
if (document.getElementById('essNoScript')) document.getElementById('essNoScript').style.visibility='hidden'; // fill the background image
};