// 
// 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_2583.jpg",
    //We arrive at the Los Angeles breakwater.
    "100_2584.jpg",
    //Light at the end of the breakwall.
    "100_2586.jpg",
    //A fireboat is waiting for the Pride, and gives us a salute.
    "100_2601.jpg",
    //The Los Angeles harbor area seems to be a forest of container cranes.
    "100_2604.jpg",
    //We have a security escort too.
    "100_2611.jpg",
    //Ah, here is the official welcome.
    "100_2612.jpg",
    //More container cranes.
    "100_2615.jpg",
    //Security also provided by police helicopter.
    "100_2616.jpg",
    //The Coast Guard station at the harbor.
    "100_2617.jpg",
    //Coast Guard boat with more of those container cranes in the background.
    "100_2621.jpg",
    //Ah, this brings back memories from when we lived in the LA area.
    "100_2624.jpg",
    //The helicopter again, but note that the image is distorted by the Pride's huge exhaust plume.
    "100_2626.jpg",
    //Another San Pedro landmark.
    "100_2627.jpg",
    //There is another cruise ship in port...
    "100_2629.jpg",
    //The Monarch of the Seas
    "100_2630.jpg",
    //The Pride must make a complete rotation, in order to get into the cruise pier.
    "100_2635.jpg",
    //Starting to turn...
    "100_2636.jpg",
    //We are getting very close to two ships during the turn...
    "100_2637.jpg",
    //A container ship...
    "100_2639.jpg",
    //And the Monarch...
    "100_2640.jpg"
    //Well, we made it around; next stop, cruise pier and debarkation.
    );
var total_photos = 21;
var narratives = Array(
    //100_2583.jpg",
    "The Pride arrives at the Los Angeles breakwater",
    //100_2584.jpg",
    "Lighthouse at the end of the breakwall",
    //100_2586.jpg",
    "A fireboat is waiting for the Pride, complete with salute",
    //100_2601.jpg",
    "The Los Angeles harbor area seems to be a forest of container cranes",
    //100_2604.jpg",
    "The Pride gets a security escort",
    //100_2611.jpg",
    "The official welcome sign",
    //100_2612.jpg",
    "More container cranes in the Port of Los Angeles",
    //100_2615.jpg",
    "Security included a police helicopter",
    //100_2616.jpg",
    "The Coast Guard station at the Port of Los Angeles",
    //100_2617.jpg",
    "Coast Guard boat; and there are more of those container cranes in the background",
    //100_2621.jpg",
    "'Ports of Call' Restaurant; now that brings back memories from when we lived in the LA area",
    //100_2624.jpg",
    "The helicopter again, but note that the image is distorted by the Pride's huge exhaust plume",
    //100_2626.jpg",
    "The fireboat pier is another San Pedro landmark",
    //100_2627.jpg",
    "There is another cruise ship in port",
    //100_2629.jpg",
    "The other cruise ship is the RCCL 'Monarch of the Seas'",
    //100_2630.jpg",
    "The Pride must make a complete rotation, in order to get into the cruise pier",
    //100_2635.jpg",
    "Starting to turn",
    //100_2636.jpg",
    "We are getting very close to two ships during the turn",
    //100_2637.jpg",
    "We get close to a container ship",
    //100_2639.jpg",
    "We get close to the 'Monarch'",
    //100_2640.jpg",
    "Well, we made it around; next stop: cruise pier and debarkation"
);
var titles = Array(
    //100_2583.jpg",
    "Los Angeles Breakwater",
    //100_2584.jpg",
    "Lighthouse",
    //100_2586.jpg",
    "Saluting Fireboat",
    //100_2601.jpg",
    "Container Cranes",
    //100_2604.jpg",
    "Security Escort",
    //100_2611.jpg",
    "Welcome Sign",
    //100_2612.jpg",
    "Container Cranes",
    //100_2615.jpg",
    "Police Helicopter",
    //100_2616.jpg",
    "Coast Guard Station",
    //100_2617.jpg",
    "Coast Guard Boat",
    //100_2621.jpg",
    "'Ports of Call'",
    //100_2624.jpg",
    "Distorted Helicopter",
    //100_2626.jpg",
    "San Pedro Landmark",
    //100_2627.jpg",
    "Cruise Ship",
    //100_2629.jpg",
    "'The Monarch of the Seas'",
    //100_2630.jpg",
    "Ready to Turn",
    //100_2635.jpg",
    "Turning",
    //100_2636.jpg",
    "Very Close",
    //100_2637.jpg",
    "Container Ship",
    //100_2639.jpg",
    "The 'Monarch'",
    //100_2640.jpg",
    "Time for Debarkation"
);

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
}
