// 
// 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_1930.jpg",
    //Approaching Puerto Limon, Costa Rica
    "100_1931.jpg",
    //Definitely a working port. Costa Rica produces a lot of fruit, including bananas.
    "100_1934.jpg",
    //Tug alongside to help us in
    "100_1935.jpg",
    //Masses of passengers trying to debark to their shore excursions. We were told that the hold-up was getting the gangway set up.
    "100_1939.jpg",
    //Music and food were available at the canal excursion dock.
    "100_2113.jpg",
    //Lovely torch ginger growing near the canal excursion dock
    "100_1940.jpg",
    //Getting onboard our canal boat. The boat was narrow, so allowing everyone a pretty good view.
    "100_1941.jpg",
    //Large tree near the dock
    "100_1942.jpg",
    //Bob and Sandi enjoying their canal excursion.
    "100_1943.jpg",
    //Three-toed sloth. Easy to photograph, because they don't move much!
    "100_1944.jpg",
    //Lush jungle along the canal. We ended up with a lot of photos like this, because the animals would disappear before we could get the camera trained on them.
    "100_1946.jpg",
    //A Jesus Christ lizard. When alarmed, they run very quickly across the top of the water.
    "100_1951.jpg",
    //We saw far more birds than other animals. Costa Rica is home (temporary or otherwise) to a wide variety of birds.
    "100b2070.jpg",
    //A water bird drying its feathers, before the next fishing expedition.
    "100b2050.jpg",
    //Another wader
    "100b2000.jpg",
    //An egret
    "100b1960.jpg",
    //A bird wading in the water, while another comes in for a landing.
    "100b2031.jpg",
    //There were spider monkeys in this very tall tree.  You can just see them in the area slightly below center of the photo.
    "100_1953.jpg",
    //A local man approaches our boat
    "100_1955.jpg",
    //Ah, we see, he's been fishing for crabs! [what a remarkable face]
    "100_1956.jpg",
    //Another boat approaches, and it's some of our Cruisecritic friends, taking their own private canal tour.
    "100_1959.jpg",
    //More waterfowl
    "100_2090.jpg",
    //Floating water plants are home to a variety of wildlife...
    "100_2091.jpg",
    //Including wading birds. This bird is standing on the floating mat of plants.
    "100_2110.jpg"
    //Iguanas seem to be everywhere in Central America
    );
var total_photos = 25;
var narratives = Array(
    //100_1930.jpg",
    "Approaching Puerto Limon, Costa Rica",
    //100_1931.jpg",
    "Limon is definitely a working port; Costa Rica produces a lot of fruit, including bananas",
    //100_1934.jpg",
    "Tug alongside to help us in",
    //100_1935.jpg",
    "Masses of passengers trying to debark to their shore excursions; we were told that the hold-up was getting the gangway set up",
    //100_1939.jpg",
    "Music and food were available at the canal excursion dock",
    //100_2113.jpg",
    "Lovely torch ginger growing near the canal excursion dock",
    //100_1940.jpg",
    "Getting onboard our canal boat; the boat was narrow, so allowing everyone a pretty good view",
    //100_1941.jpg",
    "Large tree near the dock",
    //100_1942.jpg",
    "Bob and Sandi enjoying their canal excursion",
    //100_1943.jpg",
    "The three-toed sloth is easy to photograph, because they don't move much!",
    //100_1944.jpg",
    "Lush jungle along the canal; we ended up with a lot of photos like this, because the animals would disappear before we could get the camera trained on them",
    //100_1946.jpg",
    "A Jesus Christ lizard; when alarmed, they run very quickly across the surface of the water",
    //100_1951.jpg",
    "We saw far more birds than other animals; Costa Rica is home (temporary or otherwise) to a wide variety of birds",
    //100b2070.jpg",
    "A water bird drying its feathers, before the next fishing expedition",
    //100b2050.jpg",
    "Another wader",
    //100b2000.jpg",
    "An egret",
    //100b1960.jpg",
    "A bird wading in the water, while another comes in for a landing",
    //100b2031.jpg",
    "There were spider monkeys in this very tall tree; you can just see them in the area slightly below center of the photo",
    //100_1953.jpg",
    "A local man approaches our boat",
    //100_1955.jpg",
    "Ah, we see, he's been fishing for crabs! [what a remarkable face]",
    //100_1956.jpg",
    "Another boat approaches, and it's some of our Cruisecritic friends, taking their own private canal tour",
    //100_1959.jpg",
    "More waterfowl",
    //100_2090.jpg",
    "Floating water plants are home to a variety of wildlife",
    //100_2091.jpg",
    "There are many wading birds; this bird is standing on the floating mat of plants",
    //100_2110.jpg"
    "Iguanas seem to be everywhere in Central America"
);
var titles = Array(
    //100_1930.jpg",
    "Approaching",
    //100_1931.jpg",
    "A Working Port",
    //100_1934.jpg",
    "Tug",
    //100_1935.jpg",
    "Traffic Problem",
    //100_1939.jpg",
    "Local Music",
    //100_2113.jpg",
    "Torch Ginger",
    //100_1940.jpg",
    "Canal Boat",
    //100_1941.jpg",
    "Tree",
    //100_1942.jpg",
    "Bob and Sandi",
    //100_1943.jpg",
    "Sloth",
    //100_1944.jpg",
    "Lush Jungle",
    //100_1946.jpg",
    "Lizard",
    //100_1951.jpg",
    "Birds",
    //100b2070.jpg",
    "Bird",
    //100b2050.jpg",
    "Wading Bird",
    //100b2000.jpg",
    "Egret",
    //100b1960.jpg",
    "Wading Bird",
    //100b2031.jpg",
    "Spider Monkeys",
    //100_1953.jpg",
    "Local Man",
    //100_1955.jpg",
    "What a Face!",
    //100_1956.jpg",
    "Cruisecritic Folks",
    //100_1959.jpg",
    "Waterfowl",
    //100_2090.jpg",
    "Water Plants",
    //100_2091.jpg",
    "Wading Bird",
    //100_2110.jpg"
    "Iguanas"
);

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
}
