// 
// 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-314f.jpg",
    //Looking down at pocket beach near Waipi'o Valley on North Shore
    "mvc-315f.jpg",
    //Awesome mountains above North Shore area near Waipi'o Valley
    "mvc-316f.jpg",
    //Looking across Waipi'o Valley from the overlook
    "mvc-317f.jpg",
    //Ancient lava flow becomes a tongue of land sticking into the ocean; from the Waipi'o Valley overlook 
    "mvc-318f.jpg",
    //The green, green Waipi'o Valley seen from the overlook 
    "mvc-321f.jpg",
    //More of this beautiful valley, as seen from the overlook 
    "mvc-319f.jpg",
    //Black sand beach at the mouth of the Waipi'o Valley 
    "mvc-323f.jpg",
    //Bob and Sandi with Waipi'o Valley in the background
    "mvc-322f.jpg",
    //The Chapelle's with Waipi'o Valley in the background
    "mvc-324f.jpg",
    //This gives you an idea of how steep it is, just from the parking lot to the overlook for Waipi'o Valley; the road down into the valley is VERY steep
    "mvc-325f.jpg",
    //Lush tropical setting near Akaka Falls
    "mvc-326f.jpg",
    //A stream runs along the pathways near Akaka Falls
    "mvc-327f.jpg",
    //Tropical flower (banana?) near Akaka Falls
    "mvc-330f.jpg",
    //Tropical flower among the lush vegetation near Akaka Falls
    "mvc-331f.jpg",
    //Even the trees are in flower near Akaka Falls
    "mvc-333f.jpg",
    //Colorful flowers along the pathways near Akaka Falls
    "mvc-334f.jpg",
    //Colorful flowers along the pathways near Akaka Falls
    "mvc-335f.jpg",
    //Colorful flowers along the pathways near Akaka Falls
    "mvc-338f.jpg",
    //Colorful flowers along the pathways near Akaka Falls
    "mvc-337f.jpg",
    //A huge banyan tree near Akaka Falls
    "mvc-328f.jpg",
    //Akaka Falls
    "mvc-329f.jpg",
    //Bottom of Akaka Falls
    "mvc-332f.jpg",
    //??? Falls, just a short hike from Akaka Falls
    "mvc-339f.jpg",
    //Sandi ran all the way up the hill back to the parking lot
    "mvc-346f.jpg",
    //After a long day sightseeing, we get a beautiful sunset in Kamuela
    "mvc-347f.jpg"
    //After a long day sightseeing, we get a beautiful sunset in Kamuela
    );
var total_photos = 26;
var narratives = Array(
    //mvc-314f.jpg",
    "Looking down at pocket beach near Waipi'o Valley on North Shore",
    //mvc-315f.jpg",
    "Awesome mountains above North Shore area near Waipi'o Valley",
    //mvc-316f.jpg",
    "Looking across Waipi'o Valley from the overlook",
    //mvc-317f.jpg",
    "Ancient lava flow becomes a tongue of land sticking into the ocean; from the Waipi'o Valley overlook",
    //mvc-318f.jpg",
    "The green, green Waipi'o Valley seen from the overlook",
    //mvc-321f.jpg",
    "More of this beautiful valley, as seen from the overlook", 
    //mvc-319f.jpg",
    "Black sand beach at the mouth of the Waipi'o Valley",
    //mvc-323f.jpg",
    "Bob and Sandi with Waipi'o Valley in the background",
    //mvc-322f.jpg",
    "The Chapelle's with Waipi'o Valley in the background",
    //mvc-324f.jpg",
    "This gives you an idea of how steep it is, just from the parking lot to the overlook for Waipi'o Valley; the road down into the valley is VERY steep",
    //mvc-325f.jpg",
    "Lush tropical setting near Akaka Falls",
    //mvc-326f.jpg",
    "A stream runs along the pathways near Akaka Falls",
    //mvc-327f.jpg",
    "Tropical flower (banana?) near Akaka Falls",
    //mvc-330f.jpg",
    "Tropical flower among the lush vegetation near Akaka Falls",
    //mvc-331f.jpg",
    "Even the trees are in flower near Akaka Falls",
    //mvc-333f.jpg",
    "Colorful flowers along the pathways near Akaka Falls",
    //mvc-334f.jpg",
    "Colorful flowers along the pathways near Akaka Falls",
    //mvc-335f.jpg",
    "Colorful flowers along the pathways near Akaka Falls",
    //mvc-338f.jpg",
    "Colorful flowers along the pathways near Akaka Falls",
    //mvc-337f.jpg",
    "A huge banyan tree near Akaka Falls",
    //mvc-328f.jpg",
    "Akaka Falls",
    //mvc-329f.jpg",
    "Base of Akaka Falls",
    //mvc-332f.jpg",
    "Kahuna Falls, just a short hike from Akaka Falls",
    //mvc-339f.jpg",
    "Sandi ran all the way up the hill back to the parking lot",
    //mvc-346f.jpg",
    "After a long day sightseeing, we get a beautiful sunset in Kamuela",
    //mvc-347f.jpg"
    "After a long day sightseeing, we get a beautiful sunset in Kamuela"
);
var titles = Array(
    //mvc-314f.jpg",
    "Pocket Beach",
    //mvc-315f.jpg",
    "Awesome Mountains",
    //mvc-316f.jpg",
    "Waipi'o Valley",
    //mvc-317f.jpg",
    "Ancient Lava Flow",
    //mvc-318f.jpg",
    "Green, Green Valley",
    //mvc-321f.jpg",
    "Waipi'o Valley", 
    //mvc-319f.jpg",
    "Black Sand Beach",
    //mvc-323f.jpg",
    "Bob and Sandi",
    //mvc-322f.jpg",
    "The Chapelle's",
    //mvc-324f.jpg",
    "Very Steep",
    //mvc-325f.jpg",
    "Lush Tropical Setting",
    //mvc-326f.jpg",
    "Stream",
    //mvc-327f.jpg",
    "Tropical Flower",
    //mvc-330f.jpg",
    "Tropical Flower",
    //mvc-331f.jpg",
    "Trees in Flower",
    //mvc-333f.jpg",
    "Colorful Flowers",
    //mvc-334f.jpg",
    "Colorful Flowers",
    //mvc-335f.jpg",
    "Colorful Flowers",
    //mvc-338f.jpg",
    "Colorful Flowers",
    //mvc-337f.jpg",
    "Banyan Tree",
    //mvc-328f.jpg",
    "Akaka Falls",
    //mvc-329f.jpg",
    "Akaka Falls",
    //mvc-332f.jpg",
    "Kahuna Falls",
    //mvc-339f.jpg",
    "Nyah, Nyah!",
    //mvc-346f.jpg",
    "Kamuela Sunset",
    //mvc-347f.jpg"
    "Kamuela Sunset"
);

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
}
