
document.writeln("");
function getCounterCookieVal(cookieName)
{
        var allCookies = document.cookie;
        if(allCookies == "")
        {
                return -1;
        }
        var start = allCookies.lastIndexOf(cookieName + "=");
        if(start == -1)
        {
                return -1;
        }
        start += (cookieName.length + 1);
        var end = allCookies.indexOf(';', start);
        if(end == -1)
        {
                end = allCookies.length;
        }
        if(isNaN(parseInt(allCookies.substring(start,end))))
        {
                return -1;
        }
        return allCookies.substring(start,end);
}
function writeCookie(szCookieName, nImageNum, nExpireDays)
{
        var expiration = new Date((new Date()).getTime() + nExpireDays*86400000);
        var szCookie = szCookieName + "=" + nImageNum + "; path=" + "/" + "; expires=" + expiration.toGMTString() + ";";
        document.cookie = szCookie;
}
function MD_random(r1, r2)
{
	if (r2 > r1) return (Math.round(Math.random()*(r2-r1))+r1);
	else return (Math.round(Math.random()*(r1-r2))+r2);
}
function runImageLookup()
{
	  var totalpix = 19;
        var pictureNum = 0 - 0;
	  var captions = new Array(
		"NULLVALUE",
		"View of the Luquillo Mountains (Luquillo Experimental Forest) in the 1990's",
		"2",
		"3",
		"4",
		"Students and technicians at LUQ-LTER in the debris pile at the bottom of a 20 x 20 m hurricane debris removal plot, end of September, 1989, about two weeks after Hurricane Hugo. photo: Jean Lodge",
		"A post-hurricane study site where it was found that debris, especially the woody debris, has a high carbon to nutrient ratio which delays recovery of the canopy trees if left on the ground  (Zimmerman et al., Oikos, 1995).",
		"7",
		"8",
		"9",
		"10",
		"Stream gauge near El Verde Research Station, Luquillo Experimental Forest LTER site, Puerto Rico (Photo: Charles A. Simenstad).",
		"12",
		"Studying vegetation recovery following hurricane disturbance in the tropical rainforest at Luquillo Experimental Forest LTER site, Puerto Rico (Photo: Robert B. Waide)",
		"14",
		"From El Toro",
		"Graduate Student's project, snail hand-picking-JFB",
		"Graduate Student's project, snails migrating upstream-JFB.jpg",
		"View from the top of the Torrecilla (Barranquitas, Puerto Rico) Mountain near the research plot set by the LUQ LTER Schoolyard Pablo Colon High since 1987",
		"LUQ LTER Schoolyard Pablo Colon High Students and Teacher near their research plot in Torrecilla, Barranquitas, Puerto Rico",
		"View of the Luquillo Mountains in the 1960's (photo from the Center for Energy and Environmental Research, San Juan site)"
		);

        var cookieVal = getCounterCookieVal("cas_image");
        if((cookieVal < 0) || (cookieVal > totalpix))
        {
                cookieVal = MD_random(1,totalpix);
        }
        pictureNum = cookieVal; // to make pictureNum an integer
        document.writeln("<td valign=top width=\"350\" class=\"yellow\"><p><img src= \"/images/frontpix/pix" + pictureNum + ".jpg\" width=350 height=235 border=0 alt=\"Book Cover\"><br>" + captions[pictureNum] + "</td>");
        pictureNum = pictureNum - 0 + 1; // -0 to force addition over concatenation
        if(pictureNum > totalpix) pictureNum = 1;
        writeCookie("cas_image", pictureNum, 5);
}

