// 
// 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_2474.jpg",
    //Some Hawaiian themed artwork
    "100_2475.jpg",
    //Drinks painted along the outside Cadillac Diner area
    "100_2476.jpg",
    //The Hawai'i state flag
    "100_2477.jpg",
    //Closeup of the Hawai'i state flag
    "100_2478.jpg",
    //The United States flag alongside the Hawai'i state flag
    "100_2479.jpg",
    //Artwork along the stern, showing the Hawaiian islands
    "100_2480.jpg",
    //Our island, Maui
    "100_2481.jpg",
    //Flowers and surfer
    "100_2482.jpg",
    //Overall view of the stern area, level 6 promenade
    "100_2487.jpg",
    //More Hawaiian themes
    "100_2488.jpg",
    //More Hawaiian...
    "100_2489.jpg",
    //More...
    "100_2644.jpg",
    //A surfer
    "100_2483.jpg",
    //Outside the steakhouse, the theme is Hawaiian panioli (cowboys)
    "100_2484.jpg",
    //Hawaiian panioli decorate their cowboy hats with flower leis, also with other materials such as bird feathers.
    "100_2494.jpg",
    //Hawaiian fish. Is it the famous official state fish: Humuhumunukunukuapua'a?
    "100_2497.jpg",
    //Hawaiian kahili (royal standards). Hmmm, some strange guy is waving from his balcony.
    "100_2485.jpg",
    //Perhaps they thought there was a casino on the ship. Anyway, notice that the "2" is painted backwards.
    "100_2486.jpg",
    //The "9" is backwards on this playing card.
    "100_2495.jpg",
    //I guess this is a "cocktail bar" theme, but it looks to us more like a German "Reeperbahn District" image.
    "100_2496.jpg"
    //"Hello Sailor!"
    );
var total_photos = 21;
var narratives = Array(
    //"100_2474.jpg",
    "Some Hawaiian-themed artwork",
    //"100_2475.jpg",
    "Drink images along the outside Cadillac Diner area",
    //"100_2476.jpg",
    "The Hawai'i state flag near the stern",
    //"100_2477.jpg",
    "Closeup of the Hawai'i state flag",
    //"100_2478.jpg",
    "The United States flag alongside the Hawai'i state flag",
    //"100_2479.jpg",
    "Artwork along the stern shows each of the Hawaiian islands",
    //"100_2480.jpg",
    "Our island, Maui",
    //"100_2481.jpg",
    "Flowers and surfer",
    //"100_2482.jpg",
    "Overall view of the stern area, level 6 promenade",
    //"100_2487.jpg",
    "Palm trees and little grass shacks",
    //"100_2488.jpg",
    "Ukulele and flowers",
    //"100_2489.jpg",
    "Wider view of many Hawaiian themed images",
    //"100_2644.jpg",
    "One of many surfers",
    //"100_2483.jpg",
    "Outside the steakhouse, the theme is Hawaiian cowboys (panioli)",
    //"100_2484.jpg",
    "Hawaiian panioli decorate their cowboy hats with hand-made leis using flowers and even bird feathers",
    //"100_2494.jpg",
    "Hawaiian fish; is it the famous official state fish: Humuhumunukunukuapua'a?",
    //"100_2497.jpg",
    "Hawaiian kahili (royal standards); hmmm, some strange guy is waving from his balcony",
    //"100_2485.jpg",
    "Perhaps they thought there was a casino on the ship; notice that the '2' is painted backwards",
    //"100_2486.jpg",
    "The '9' is backwards on this playing card; no, we didn't reverse the photo",
    //"100_2495.jpg",
    "I guess this is a 'cocktail bar' theme, but it looks to us more like a German 'Reeperbahn District' image",
    //"100_2496.jpg",
    "Typical cruise passenger?"
);
var titles = Array(
    //"100_2474.jpg",
    "Hawaiian-themed Artwork",
    //"100_2475.jpg",
    "Drinks",
    //"100_2476.jpg",
    "Flag",
    //"100_2477.jpg",
    "Flag",
    //"100_2478.jpg",
    "Two Flags Together",
    //"100_2479.jpg",
    "Hawaiian Islands",
    //"100_2480.jpg",
    "Maui",
    //"100_2481.jpg",
    "Flowers and Surfer",
    //"100_2482.jpg",
    "Stern Area",
    //"100_2487.jpg",
    "Hawaiian Themes",
    //"100_2488.jpg",
    "Hawaiian Themes",
    //"100_2489.jpg",
    "Hawaiian Themes",
    //"100_2644.jpg",
    "Surfer",
    //"100_2483.jpg",
    "Hawaiian Panioli (Cowboys)",
    //"100_2484.jpg",
    "Hawaiian Panioli",
    //"100_2494.jpg",
    "Humuhumunukunukuapua'a?",
    //"100_2497.jpg",
    "Hawaiian Kahili (Royal Standards)",
    //"100_2485.jpg",
    "'2' Painted Backwards",
    //"100_2486.jpg",
    "'9' Painted Backwards",
    //"100_2495.jpg",
    "German 'Reeperbahn District' Image",
    //"100_2496.jpg",
    "Hello Sailor!"
);

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
}
