// 
// photo album handling
// copyright 2005, Bob Swanson
// You may use this code for your own
// slideshows, but please retain this
// copyright notice
//
var numbers = Array(
    "mvc-281f.jpg",
    //They Mean It -- Fresh Lava is Dangerous
    "mvc-282f.jpg",
    //End of Chain of Craters Road -- Covered with Recent Lava Flows
    "mvc-283f.jpg",
    //Recent Lava Flow Covering Road [note the offering to Pele on the left]
    "mvc-284f.jpg",
    //Bob Looking at Lava Flow [current road covering is from April 2003, photo from May, 2003]
    "mvc-287f.jpg",
    //Sandi at Lava Flow [gloves are to protect from the glass-sharp lava surface]
    "mvc-289f.jpg",
    //Sandi Says "Slow Down" 15 Miles/Hour!
    "mvc-285f.jpg",
    //Pahoehoe (Ropy Lava) [the surface is still sharp and glassy, dangerous footing]
    "mvc-290f.jpg",
    //More Pahoehoe [the shapes are fascinating]
    "mvc-291f.jpg",
    //Pahoehoe
    "mvc-286f.jpg",
    //Brush Fires Caused by Lava Flow
    "mvc-292f.jpg",
    //Recent Lava Flows Down a Cliff
    "mvc-295f.jpg",
    //That Small Cloud is the Lava Flow Entering the Ocean
    "mvc-296f.jpg",
    //Ohia Forest Near Kilauea Iki
    "mvc-297f.jpg",
    //Hapuu Fern in Ohia Forest
    "mvc-298f.jpg",
    //Closeup of Hapuu Fern
    "mvc-299f.jpg",
    //Hapuu Fern and Hiking Trail Near Kilauea Iki
    "mvc-301f.jpg",
    //Ohia Forest
    "mvc-340f.jpg",
    //Kilauea Iki Crater [erupted in 1959]
    "mvc-342f.jpg",
    //In 1959 That Vent Shot a "http://volcano.und.nodak.edu/vwdocs/Parks/hawaii/iki_trail/1menu.html", Fountain of Lava</a> Nearly 2,000 Feet High
    "mvc-341f.jpg",
    //Hiking Trail at Bottom of Kilauea Iki [in 1986, we walked it, an interesting hike, but tough climbing out at the end]
    "mvc-351f.jpg",
    //Kilauea Iki View
    "mvc-348f.jpg",
    //Boulder on Floor of Kilauea Iki
    "mvc-352f.jpg",
    //Closeup of Boulder [looks like it fell all the way from the rim and rolled onto the floor of the caldera]
    "mvc-343f.jpg",
    //Steam Vents at Kilauea Crater
    "mvc-345f.jpg",
    //Steam Vents at Kilauea Crater
    "gt005.jpg",
    //Road Sign in August 2002 [compare with the burned sign seen in May 2003]
    "gt003.jpg",
    //Steam from Lava Entering Ocean, August 2002
    "gt011.jpg"
    //Lava Flow, August 2002
    );
var total_photos = 28;
var narratives = Array(
    //mvc-281f.jpg",
    "This sign is true: fresh lava is dangerous; compare with same sign from 2002",
    //mvc-282f.jpg",
    "The end of Chain of Craters Road is now covered with recent lava flows",
    //mvc-283f.jpg",
    "The recent lava flow has covered the road; note the offering to Pele on the left",
    //mvc-284f.jpg",
    "Bob is taking a look at lava flow; the lava covering the road is from April 2003, photo taken in May, 2003",
    //mvc-287f.jpg",
    "Sandi at the lava flow; she is wearing gloves to protect from the glass-sharp lava surface",
    //mvc-289f.jpg",
    "Sandi says: 'Slow Down' 15 Miles/Hour!",
    //mvc-285f.jpg",
    "This is pahoehoe ('ropey' lava); the surface is still sharp and glassy, dangerous footing",
    //mvc-290f.jpg",
    "The shapes of pahoehoe are fascinating",
    //mvc-291f.jpg",
    "More pahoehoe",
    //mvc-286f.jpg",
    "There are forest and brush fires up the mountain, caused by lava flow",
    //mvc-292f.jpg",
    "The cliff shows evidence of recent lava flows",
    //mvc-295f.jpg",
    "That small cloud is the current lava flow entering the ocean several miles away",
    //mvc-296f.jpg",
    "The Kilauea Iki crater is surrounded by an Ohia forest",
    //mvc-297f.jpg",
    "The understory of the Ohia forest is the Hapuu Fern",
    //mvc-298f.jpg",
    "A closeup of the Hapuu Fern",
    //mvc-299f.jpg",
    "More Hapuu Fern near this hiking trail along the rim of Kilauea Iki",
    //mvc-301f.jpg",
    "More Ohia forest",
    //mvc-340f.jpg",
    "This is Kilauea Iki Crater; see the link on the page for spectacular images of the 1959 eruption",
    //mvc-342f.jpg",
    "In 1959 that vent shot a fountain of lava nearly 2,000 feet high",
    //mvc-341f.jpg",
    "The hiking trail at the bottom of Kilauea Iki; we walked it in 1986, an interesting hike, but tough climbing out at the end",
    //mvc-351f.jpg",
    "View of Kilauea Iki",
    //mvc-348f.jpg",
    "That is a lava boulder on the floor of Kilauea Iki",
    //mvc-352f.jpg",
    "Closeup of the lava boulder; it looks like it fell all the way from the rim and rolled onto the floor of the caldera",
    //mvc-343f.jpg",
    "Steam vents at Kilauea Crater",
    //mvc-345f.jpg",
    "More steam Vents at Kilauea Crater",
    //gt005.jpg",
    "The Chain of Craters road sign in August 2002; compare with the burned sign seen in May 2003",
    //gt003.jpg",
    "Steam from lava entering ocean, August 2002",
    //gt011.jpg",
    "Lava flow, August 2002"
);
var titles = Array(
    //mvc-281f.jpg",
    "Burned Sign",
    //mvc-282f.jpg",
    "Road Covered in Lava",
    //mvc-283f.jpg",
    "Offering to Pele",
    //mvc-284f.jpg",
    "Bob",
    //mvc-287f.jpg",
    "Sandi",
    //mvc-289f.jpg",
    "Slow Down!",
    //mvc-285f.jpg",
    "Pahoehoe",
    //mvc-290f.jpg",
    "Pahoehoe Shapes",
    //mvc-291f.jpg",
    "Pahoehoe",
    //mvc-286f.jpg",
    "Lava Fires",
    //mvc-292f.jpg",
    "Cliff",
    //mvc-295f.jpg",
    "Small Cloud",
    //mvc-296f.jpg",
    "Ohia Forest",
    //mvc-297f.jpg",
    "Hapuu Fern",
    //mvc-298f.jpg",
    "Hapuu Fern",
    //mvc-299f.jpg",
    "Hiking Trail",
    //mvc-301f.jpg",
    "Ohia Forest",
    //mvc-340f.jpg",
    "Kilauea Iki",
    //mvc-342f.jpg",
    "Major Lava Vent",
    //mvc-341f.jpg",
    "Hiking Trail",
    //mvc-351f.jpg",
    "Kilauea Iki",
    //mvc-348f.jpg",
    "Boulder",
    //mvc-352f.jpg",
    "Boulder",
    //mvc-343f.jpg",
    "Steam Vents",
    //mvc-345f.jpg",
    "Steam Vents",
    //gt005.jpg",
    "Road Sign, August 2002",
    //gt003.jpg",
    "Lava Entering Ocean, August 2002",
    //gt011.jpg",
    "Lava Flow, August 2002"
);

var current = 0;

var first_time = 1;

function first_pass()
{
    if (first_time === 1)
    {
      //  alert("first pass");
        load_picture(0); // load picture zero
        first_time = 0; // prevent re-invocation
    }
}

function build_selector()
{
    var selector = document.getElementById("picture_selector"); 
    
    for (i = 0 ; i < total_photos ; i++)
    {
        newtext = document.createTextNode(i + " - " + titles[i]); // text content
        newoption = document.createElement("option");
        newoption.setAttribute("value",i); // value is pic number only
        newoption.appendChild(newtext); // add text
        selector.appendChild(newoption);
    }
}

function create_selector()
{
    for (i = 0 ; i < total_photos ; i++)
    {
        document.write('<option value="' + i + '">' + 
                       i + " - " + titles[i] + '</option>');
    }
}

function get_thumb_url (position) {

    url = "http://www219.pair.com/swansonr/big_island/lthumbs/th_" + numbers[position];
    return url;
}

function get_picture_url (position) {

    url = "http://www219.pair.com/swansonr/big_island/" + numbers[position];
    return url;
}

//
// advance and load next if there is one
//
function load_next() {
    //alert(current);
    current = current + 1;
    if (current < total_photos)
    {
        load_picture(current);
    }
    else
    {
        current = current - 1;
        load_picture(total_photos - 1);
    }
}
//
// pop up window with current big photo
//
function load_current() {
    var the_picture_url = get_picture_url(current);
    window.open(the_picture_url,'hawaii_volcanoes_photo','resizable=yes,scrollbars=yes');
}

function load_selected()
{
    var selector = document.getElementById("picture_selector"); 
    var cur = selector.options[selector.selectedIndex].value;
    //alert("load: " + cur);
    current = parseInt(cur);
    load_picture(current);
}

//
// decrement and load previous if there is one
//
function load_previous() {
    current = current - 1;
    if (current >= 0)
    {
        load_picture(current);
    }
    else
    {
        current = 0;
        load_picture(0);
    }
}

function load_picture(at)
{
    var ximage = document.getElementById("thumb"); // the IMG tag
    var the_thumb_url = get_thumb_url(at);
    ximage.setAttribute("src",the_thumb_url);
    var the_picture_url = get_picture_url(at);
    set_text(the_picture_url);
    set_head_narrative(at);
}

function removeAllChildren(xxx)
{
    while (xxx.hasChildNodes()) 
    {
        xxx.removeChild(xxx.firstChild);
    }
}

//
// sets the prompt just below the photo with
// an anchor that loads the full-size photo
//
function set_text(text)
{
    var prompt = document.getElementById("prompt");
    removeAllChildren(prompt); // remove all content
    //
    // add back in
    //
    newtext = document.createTextNode("View Larger Photo"); // text for anchor
    newpara = document.createElement("p"); // new wrapper for anchor
    newpara.setAttribute("class","timestamp"); // make it smaller 
    anchor = document.createElement("a"); // new anchor
    anchor.setAttribute("href",text);
    anchor.appendChild(newtext); // add text to anchor
    newpara.appendChild(anchor); // put anchor inside paragraph
    // DO NOT DO THIS FOR NOW  prompt.appendChild(newpara); // put paragraph into div
}


function set_head_narrative(position)
{
    //
    // first the heading
    //
    var subh = document.getElementById("subhead");
    removeAllChildren(subh); // remove all content
    //
    // add back in
    //
    newtext = document.createTextNode(titles[position]); // text for title
    newhead = document.createElement("h2"); 
    newhead.setAttribute("class","heading2");
    newhead.appendChild(newtext); // add text to heading
    subh.appendChild(newhead); // put heading into div
    //
    // now the narrative below
    //
    var narr = document.getElementById("narrative");
    removeAllChildren(narr); // remove all content
    //
    // add back in
    //
    newtext = document.createTextNode("[Image: " + position + "] " + narratives[position]); // text for narrative
    newpara = document.createElement("p"); // new wrapper for narrative
    newpara.setAttribute("class","body"); // make it normal
    newpara.appendChild(newtext); // add text to paragraph
    narr.appendChild(newpara); // put paragraph into div
}
