// 
// 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_2430.jpg",
    //     Our cabin door decorated for the 4th.
    "100_2431.jpg",
    //     Closeup of 'Nalani', our cruising mascot, along with various red-white-blue items.
    "100_2432.jpg",
    //     Bob, trying on his Uncle Sam hat. This proved to be a big hit with passengers and crew.
    "100_2439.jpg",
    //     Sunset, July 3rd, at sea off the Mexican coast.
    "100_2457.jpg",
    //     Even the bear in the Goldrush Saloon is wearing a patriotic hat.
    "100_2507.jpg",
    //    Bob and our cabin attendant Jenny holding the flags we'll display later in the evening.
    "100_2508.jpg",
    //    Jenny took this photo of Bob and Sandi dressed up for dinner with flags and hat.
    "100_2509.jpg",
    //    Our dining table in the Liberty Restaurant had a few patriotic items.
    "100_2510.jpg",
    // Bob did take his hat off to dine.
    "100_2516.jpg",
    //   The fountain/display at the front of the Liberty Restaurant is quite patriotic.
    "100_2517.jpg",
    // The lights on the 'flag' switch on and off.
    "100_2519.jpg",
    //   The Skyline Restaurant had a July 4th theme, unlike any other part of the ship.
    "100_2520.jpg",
    // More bunting decorates the Skyline Restaurant.
    "100_2521.jpg"
    //   Bob after a 'walkthrough' of the ship.  He got a lot of attention, including salutes from the WW II vets on the cruise.
    
);
var total_photos = 14;
var narratives = Array(
    // "100_2430.jpg",
 "Our cabin door decorated for the 4th",
    // "100_2431.jpg",
    "Closeup of 'Nalani', our cruising mascot, along with various red-white-blue items",
    // "100_2432.jpg",
    "Bob, trying on his Uncle Sam hat; this proved to be a big hit with passengers and crew",
    // "100_2439.jpg",
    "Sunset, July 3rd, at sea off the Mexican coast",
    // "100_2457.jpg",
    "Even the bear in the Goldrush Saloon is wearing a patriotic hat",
    // "100_2507.jpg",
    "Bob and our cabin attendant Jenny holding the flags we'll display later in the evening",
    // "100_2508.jpg",
    "Jenny took this photo of Bob and Sandi dressed up for dinner with flags and hat",
    // "100_2509.jpg",
    "Our dining table in the Liberty Restaurant had a few patriotic items",
    // "100_2510.jpg",
    "Bob did take his hat off to dine",
    // "100_2516.jpg",
    "The fountain/display at the front of the Liberty Restaurant is quite patriotic",
    // "100_2517.jpg",
    "The lights on the 'flag' switch on and off",
    // "100_2519.jpg",
    "The Skyline Restaurant had a July 4th theme, unlike any other part of the ship",
    // "100_2520.jpg",
    "More bunting decorates the Skyline Restaurant",
    // "100_2521.jpg",
    "Bob after a 'walkthrough' of the ship; he got a lot of attention, including salutes from the WW II vets on the cruise"
    
);
var titles = Array(
    // "100_2430.jpg",
    "Cabin Door",
    // "100_2431.jpg",
    "Closeup of Door Decorations",
    // "100_2432.jpg",
    "Bob in the Hat",
    // "100_2439.jpg",
    "Sunset",
    // "100_2457.jpg",
    "Patriotic Bear",
    // "100_2507.jpg",
    "Bob and Jenny",
    // "100_2508.jpg",
    "Bob and Sandi",
    // "100_2509.jpg",
    "Ready for Dinner",
    // "100_2510.jpg",
    "Our Dining Table",
    // "100_2516.jpg",
    "Liberty Restaurant",
    // "100_2517.jpg",
    "'Flag' Decoration",
    // "100_2519.jpg",
    "July 4th Theme",
    // "100_2520.jpg",
    "Decorations",
    // "100_2521.jpg",
    "Bob"
);

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
}
