// 
// 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(
    "100_1847.jpg",
    //Approaching Roatan Island
    "100_1848.jpg",
    //Homes near the port at Coxen Hole
    "100_1849.jpg",
    //Debarking from the Pride of America [note lens fogging]
    "100_1851.jpg",
    //The Pride of America sits for her portrait at Coxen Hole.
    "100_1855.jpg",
    //Long view of the harbor from our perch in the mountains above Coxen Hole.
    "100_1860.jpg",
    //Sandi with the Pride of America in the background
    "100_1858.jpg",
    //Our tour bus
    "100_1861.jpg",
    //Shipwreck along coast of Roatan
    "100_1862.jpg",
    //Closeup of shipwreck
    "100_1866.jpg",
    //We stopped at a private 'zoo' with several cages of animals. The iguanas were allowed to wander freely, much to Sandi's discomfort.
    "100_1865.jpg",
    //  There were many colorful parrots.
    "100_1869.jpg",
    //  They had a tidepool fenced off, with many sea creatures. This was a very large lobster.  Roatan is a major exporter of fish and lobster.
    "100_1871.jpg",
    //  Sea turtle
    "100_1872.jpg",
    //  Excursion boats just offshort, inside the extensive reefs of Roatan. This island is a major scuba and snorkling destination.
    "100_1873.jpg",
    //  Hermet crab scuttling across the concrete
    "100_1874.jpg",
    //Another parrot
    "100_1876.jpg",
    //  Long view of those famous reefs, you can just see the lighter color in the water.
    "100_1877.jpg",
    //  Coastline of Roatan
    "100_1878.jpg",
    //  Hilltop restaurant
    "100_1883.jpg",
    //  Pride of America at Roatan
    "100_1897.jpg",
    //  Beautiful clear water of Roatan
    "100_1898.jpg",
    //  Leaving the pier in Roatan
    "100_1899.jpg",
    //  Looking back at Coxen Hole
    "100_1900.jpg",
    //Airport control tower is high on the mountain, while the airport is at sea level!
    "100_1901.jpg"
    //   Roatan is now astern of us
    
);
var total_photos = 25;
var narratives = Array(
    // "100_1847.jpg",
    "Approaching Roatan Island",
    // "100_1848.jpg",
    "Homes near the port at Coxen Hole",
    // "100_1849.jpg",
    "Debarking from the Pride of America; note the lens fogging we experienced",
    // "100_1851.jpg",
    "The Pride of America sits for her portrait at Coxen Hole",
    // "100_1855.jpg",
    "Long view of the harbor from our perch in the mountains above Coxen Hole",
    // "100_1860.jpg",
    "Sandi with the Pride of America in the background",
    // "100_1858.jpg",
    "Our tour bus",
    // "100_1861.jpg.jpg",
    "Shipwreck along coast of Roatan",
    // "100_1862.jpg",
    "Closeup of shipwreck",
    // "100_1866.jpg",
    "We stopped at a private 'zoo' with several cages of animals; the iguanas were allowed to wander freely, much to Sandi's discomfort",
    // "100_1865.jpg",
    "There were many colorful parrots",
    // "100_1869.jpg",
    "They had a tidepool fenced off, with many sea creatures; this was a very large lobster; Roatan is a major exporter of fish and lobster",
    // "100_1871.jpg",
    "Sea turtle",
    // "100_1872.jpg",
    "Excursion boats just offshort, inside the extensive reefs of Roatan; this island is a major scuba and snorkling destination",
    // "100_1873.jpg",
    "Hermet crab scuttling across the concrete",
    // "100_1874.jpg",
    "Another parrot",
    // "100_1876.jpg",
    "Long view of those famous reefs, you can just see the lighter color in the water.",
    // "100_1877.jpg",
    "Coastline of Roatan",
    // "100_1878.jpg",
    "Hilltop restaurant",
    // "100_1883.jpg",
    "Pride of America at Roatan",
    // "100_1897.jpg",
    "Beautiful clear water of Roatan",
    // "100_1898.jpg",
    "Leaving the pier in Roatan",
    // "100_1899.jpg",
    "Looking back at Coxen Hole",
    // "100_1900.jpg",
    "Airport control tower is high on the mountain, while the airport is at sea level!",
    // "100_1901.jpg",
    "Roatan is now astern of us"    
);
var titles = Array(
    // "100_1847.jpg",
    "Roatan Island",
    // "100_1848.jpg",
    "Coxen Hole",
    // "100_1849.jpg",
    "Debarking",
    // "100_1851.jpg",
    "Portrait of the Pride",
    // "100_1855.jpg",
    "Harbor",
    // "100_1860.jpg",
    "Sandi and the Pride",
    // "100_1858.jpg",
    "Tour Bus",
    // "100_1861.jpg.jpg",
    "Shipwreck",
    // "100_1862.jpg",
    "Shipwreck",
    // "100_1866.jpg",
    "Iguanas",
    // "100_1865.jpg",
    "Parrot",
    // "100_1869.jpg",
    "Lobster",
    // "100_1871.jpg",
    "Sea Turtle",
    // "100_1872.jpg",
    "Excursion Boats",
    // "100_1873.jpg",
    "Hermet Crab",
    // "100_1874.jpg",
    "Parrot",
    // "100_1876.jpg",
    "Coastline with Reefs",
    // "100_1877.jpg",
    "Coastline of Roatan",
    // "100_1878.jpg",
    "Hilltop Restaurant",
    // "100_1883.jpg",
    "Pride of America at Roatan",
    // "100_1897.jpg",
    "Clear Water",
    // "100_1898.jpg",
    "Leaving Roatan",
    // "100_1899.jpg",
    "Coxen Hole",
    // "100_1900.jpg",
    "Airport Control Tower",
    // "100_1901.jpg",
    "Leaving Roatan"    
);

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/pics/panama2005/lthumbs/th_" + numbers[position];
    return url;
}

function get_picture_url (position) {

    url = "http://www219.pair.com/swansonr/pics/panama2005/" + 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,'panama_canal_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
}
