// 
// 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_2523.jpg",
    //Approaching Cabo San Lucas
    "100_2525.jpg",
    //The setting is beautiful, showing quite a rugged coastline.
    "100_2527.jpg",
    //Typical water excursion boat, with Land's End rocks in background.
    "100_2528.jpg",
    //Lots of new resort development around Cabo.
    "100_2543.jpg",
    //More development on Land's End itself.
    "100_2529.jpg",
    //Plenty of water sports here, such as parasailing.
    "100_2532.jpg",
    //Anyone who wanted to visit the shore, had to tender from the ship.
    "100_2534.jpg",
    //Bob relaxing on his "floating resort", the Pride.
    "100_2539.jpg",
    //Old Glory with Cabo in the background.
    "100_2540.jpg",
    //We had a security boat around us during our short visit.
    "100_2553.jpg",
    //The famous arch in Land's End.
    "100_2556.jpg",
    //Closeup of arch with waves breaking behind the arch. Notice the jetskis buzzing around the rocks.
    "100_2562.jpg",
    //As afternoon approaches, the light glitters off the water",
    "100_2563.jpg"
    //Our escort sees us off from Cabo San Lucas",
    );
var total_photos = 14;
var narratives = Array(
    //100_2523.jpg",
    "Approaching Cabo San Lucas",
    //100_2525.jpg",
    "The setting is beautiful, displaying the rugged coastline of Mexico",
    //100_2527.jpg",
    "Typical water excursion boat; the rocks of Land's End are in the background",
    //100_2528.jpg",
    "Lots of new resort development around Cabo",
    //100_2543.jpg",
    "More development on Land's End itself",
    //100_2529.jpg",
    "Water sports are very popular here, such as parasailing",
    //100_2532.jpg",
    "This was our only 'tendering' port of the cruise",
    //100_2534.jpg",
    "Bob relaxing on his own 'floating resort': the Pride",
    //100_2539.jpg",
    "Old Glory with Cabo in the background",
    //100_2540.jpg",
    "The security boat was close by all day",
    //100_2553.jpg",
    "The famous arch in Land's End",
    //100_2556.jpg",
    "Closeup of arch with waves breaking behind the arch; notice the jetskis buzzing around the rocks",
    //100_2562.jpg",
    "As afternoon approaches, the light glitters off the water",
    //100_2563.jpg",
    "Our escort sees us off from Cabo San Lucas"
);
var titles = Array(
    //100_2523.jpg",
    "Cabo San Lucas",
    //100_2525.jpg",
    "Rugged Coastline",
    //100_2527.jpg",
    "Excursion Boat",
    //100_2528.jpg",
    "New Resort Development",
    //100_2543.jpg",
    "More Development",
    //100_2529.jpg",
    "Parasailing",
    //100_2532.jpg",
    "Tendering to Shore",
    //100_2534.jpg",
    "Bob",
    //100_2539.jpg",
    "Old Glory",
    //100_2540.jpg",
    "Security Boat",
    //100_2553.jpg",
    "Los Arcos",
    //100_2556.jpg",
    "Breaking Waves",
    //100_2562.jpg",
    "Glitter",
    //100_2563.jpg",
    "Our Escort"
);

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
}
