// 
// 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(
    "canalzone.jpg",
//    Canal map
    "100_2280.jpg",
    //We approach the Pedro Miguel Locks.
    "100_2283.jpg",
    //The big arrow directs us to enter the left-hand lock.
    "100_2286.jpg",
    //Line handling is started with men in a rowboat; low-tech but it works.
    "100_2287.jpg",
    //Approach as seen from our cabin balcony.
    "100_2290.jpg",
    //We turn the corner and approach the lock.
    "100_2292.jpg",
    //The excitement is too much for Bob.
    "100_2293.jpg",
    //The tug is positioning the Ludwigshafen Express for the right-hand lock.
    "100_2294.jpg",
    //We are entering the lock.
    "100_2295.jpg",
    //Panama Canal employees
    "100_2296.jpg",
    //The waiting rowboats
    "100_2297.jpg",
    //The waiting mules
    "100_2298.jpg",
    //The arrow has already switched for the next ship.
    "100_2299.jpg",
    //Tiles indicate the position along the lock. This lock is 1200 feet long.
    "100_2300.jpg",
    //The mule is attached to the Pride.
    "100_2301.jpg",
    //Positioning the mule.
    "100_2302.jpg",
    //Cable rig on the mule.
    "100_2303.jpg",
    //Quite possibly the world's narrowest bathroom.
    "100_2305.jpg",
    //The Express entering the other lock.
    "100_2310.jpg",
    //Continuing her entrance.
    "100_2312.jpg",
    //Among the many containers is what appears to be a very LARGE engine!
    "100_2313.jpg",
    //Closer look...
    "100_2316.jpg",
    //This mule has a very shiny bell.
    "100_2317.jpg",
    //Mule operator.
    "100_2318.jpg",
    //Our next door neighbors, watching the action in the locks.
    "100_2320.jpg",
    //The Express is fully inside the lock now.
    "100_2327.jpg",
    //When the mules are done, they are sent back to the other end of the lock on the other track.
    "100_2323.jpg",
    //The lock building.
    "100_2324.jpg",
    //A large ship, anchored alongside the lock.
    "100_2326.jpg",
    //Another one.
    "100_2328.jpg",
    //The Mireflores Lock building, decorated for the anniversary of the Panama Canal.
    "100_2329.jpg",
    //Large banners on the lock building show old photographs of the Panama Canal.
    "100_2330.jpg",
    //The Canal in the "old days".
    "100_2331.jpg",
    //Detail from the banner, showing the older mules.
    "100_2332.jpg",
    //The upper lock is full, ready to drain into the lower lock.
    "100_2333.jpg",
    //Small waterfall from lock gate.
    "100_2334.jpg",
    //Notice the cameras; some of these are used for the live feeds shown on the Web.
    "100_2335.jpg",
    //The stonework dates from 1913, but the mules are modern.
    "100_2337.jpg",
    //Another mule with a shiny bell.
    "100_2339.jpg",
    //Reeling in the cables used to connect to the ship. We are done, another Canal transit has been completed. The Pride of America will now spend her time entirely in the Hawaiian Islands.
    "100_2340.jpg",
    //A dredge ship holding just below the lock. Dredging is an on-going activity in the canal.
    "100_2341.jpg",
    //Yep, she's a dredge all right. [international day signal]
    "100_2343.jpg"
    //As is typical, she is from the Netherlands, where they are experts in dredging.
);
var total_photos = 43;
var narratives = Array(
    //"canalzone.jpg",
    "Useful map for following our narrative",
//    "100_2280.jpg",
    "We approach the Pedro Miguel Locks",
    //"100_2283.jpg",
    "The big arrow directs us to enter the left-hand lock",
    //"100_2286.jpg",
    "Line handling is started with men in a rowboat; low-tech but it works",
    //"100_2287.jpg",
    "Approach as seen from our cabin balcony",
    //"100_2290.jpg",
    "We turn the corner and approach the lock",
    //"100_2292.jpg",
    "The excitement is too much for Bob",
    //"100_2293.jpg",
    "The tug is positioning the Ludwigshafen Express for the right-hand lock",
    //"100_2294.jpg",
    "We are entering the lock",
    //"100_2295.jpg",
    "Panama Canal employees",
    //"100_2296.jpg",
    "The waiting rowboats",
    //"100_2297.jpg",
    "The waiting mules",
    //"100_2298.jpg",
    "The arrow has already switched for the next ship",
    //"100_2299.jpg",
    "Tiles indicate the position along the lock; the lock is 1200 feet long",
    //"100_2300.jpg",
    "The mule is attached to the 'Pride'",
    //"100_2301.jpg",
    "Positioning the mule",
    //"100_2302.jpg",
    "Cable rig on the mule",
    //"100_2303.jpg",
    "Quite possibly the world's narrowest restroom",
    //"100_2305.jpg",
    "The Express entering the other lock",
    //"100_2310.jpg",
    "Continuing her entrance",
    //"100_2312.jpg",
    "Among the many containers is what appears to be a very LARGE engine!",
    //"100_2313.jpg",
    "Closeup of the large engine",
    //"100_2316.jpg",
    "This mule has a very shiny bell",
    //"100_2317.jpg",
    "Mule operator",
    //"100_2318.jpg",
    "Our next door neighbors, watching the action in the locks",
    //"100_2320.jpg",
    "The 'Express' is fully inside the lock now",
    //"100_2327.jpg",
    "When the mules are done, they are sent back to the other end of the lock on the far track",
    //"100_2323.jpg",
    "The lock building",
    //"100_2324.jpg",
    "A large ship, anchored alongside the lock",
    //"100_2326.jpg",
    "Another ship anchored alongside the lock",
    //"100_2328.jpg",
    "The Mireflores Lock building, decorated for the anniversary of the Panama Canal",
    //"100_2329.jpg",
    "Large banners on the lock building show old photographs of the Panama Canal",
    //"100_2330.jpg",
    "The Canal in the 'old days'",
    //"100_2331.jpg",
    "Detail from the banner, showing the older mules",
    //"100_2332.jpg",
    "The upper lock is full, ready to drain into the lower lock",
    //"100_2333.jpg",
    "Small waterfall from lock gate",
    //"100_2334.jpg",
    "Notice the cameras; some of these are used for the live feeds shown on the Web",
    //"100_2335.jpg",
    "The stonework dates from 1913, but the mules are modern",
    //"100_2337.jpg",
    "Another mule with a shiny bell",
    //"100_2339.jpg",
    "Reeling in the cables used to connect to the ship. We are done, another Canal transit has been completed. The Pride of America will now spend her time entirely in the Hawaiian Islands",
    //"100_2340.jpg",
    "A dredge ship holding just below the lock. Dredging is an on-going activity in the canal",
    //"100_2341.jpg",
    "Yep, she's a dredge all right; note the international day signal",
    //"100_2343.jpg",
    "As is typical, she is from the Netherlands, where they are experts in dredging"
);
var titles = Array(
    //"canalzone.jpg",
    "Canal Zone Map",
    //    "100_2280.jpg",
    "Pedro Miguel Locks",
    //"100_2283.jpg",
    "The Big Arrow",
    //"100_2286.jpg",
    "Rowboat",
    //"100_2287.jpg",
    "Approaching Lock",
    //"100_2290.jpg",
    "Turning the Corner",
    //"100_2292.jpg",
    "Too Much Excitement",
    //"100_2293.jpg",
    "Tug and 'Express'",
    //"100_2294.jpg",
    "Entering the Lock",
    //"100_2295.jpg",
    "Employees",
    //"100_2296.jpg",
    "Rowboats",
    //"100_2297.jpg",
    "Mules",
    //"100_2298.jpg",
    "The Big Arrow",
    //"100_2299.jpg",
    "Position Tiles Along Lock",
    //"100_2300.jpg",
    "Mule Attached to the 'Pride'",
    //"100_2301.jpg",
    "Positioning the Mule",
    //"100_2302.jpg",
    "Cable Rig",
    //"100_2303.jpg",
    "World's Narrowest Restroom",
    //"100_2305.jpg",
    "The 'Express'",
    //"100_2310.jpg",
    "Her Entrance",
    //"100_2312.jpg",
    "A Very Large Engine",
    //"100_2313.jpg",
    "Closeup",
    //"100_2316.jpg",
    "Mule With Shiny Bell",
    //"100_2317.jpg",
    "Mule Operator",
    //"100_2318.jpg",
    "Watching the Action",
    //"100_2320.jpg",
    "The 'Express'",
    //"100_2327.jpg",
    "Mule Returning for Next Trip",
    //"100_2323.jpg",
    "Lock Building",
    //"100_2324.jpg",
    "Anchored Alongside the Lock",
    //"100_2326.jpg",
    "Another Ship",
    //"100_2328.jpg",
    "Building Decorations",
    //"100_2329.jpg",
    "Large Banners",
    //"100_2330.jpg",
    "The Canal in the 'Old Days'",
    //"100_2331.jpg",
    "Image of Older Mules",
    //"100_2332.jpg",
    "Lock Ready to Drain",
    //"100_2333.jpg",
    "Small Waterfall",
    //"100_2334.jpg",
    "Webcams",
    //"100_2335.jpg",
    "Older Stonework",
    //"100_2337.jpg",
    "Another Mule with a Shiny Bell",
    //"100_2339.jpg",
    "Reeling In",
    //"100_2340.jpg",
    "Dredge Ship",
    //"100_2341.jpg",
    "International Day Signal",
    //"100_2343.jpg",
    "From the Netherlands"
);

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
}
