// 
// 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_1748.jpg",
    //Bob and Sandi onboard the Pride of America. Miami in background, along with the Imagination.
    "100_1754.jpg",
    //Just Bob with Miami skyline.
    "100_1758.jpg",
    //The RCCL Majesty of the Seas, berthed near us. This was one of only two other ships in Miami that day.
    "100_1777.jpg",
    //Lifeboat drill: our muster station was the beautiful Liberty dining room, one of two main dining rooms.
    "100_1778.jpg",
    //Conning the ship out of Miami; photo taken from the lovely balcony of our CruiseCritic team leader, 'livermorenancy'; John and Nancy had splurged on this very nice Grand Suite, and were kind enough to invite us other CC'ers up to watch the departure",
    "100_1780.jpg",
    //Equipment for the old airlines that used to ply between Miami and Caribbean islands.
    "100_1781.jpg",
    //The bridge between downtown and Miami Beach. We had to turn around here, since the Pride of America was pointing in, not out.
    "100_1783.jpg",
    //Turning...
    "100_1784.jpg",
    //Still turning...
    "100_1785.jpg",
    //Nearly there...
    "100_1788.jpg",
    //Looking back at the cruise port area, where we were berthed; now we can head to sea through the channel.
    "100_1789.jpg",
    //Bob and Sandi, taken as we left Miami.
    "100_1790.jpg",
    //Near Miami harbor mouth.
    "100_1791.jpg",
    //Big development near Miami harbor mouth; must be a bit of a drive to the grocery store!
    "100_1792.jpg",
    //The Cruisecritic gang. We had a lot of fun on this cruise.
    "100_1793.jpg"
    //Miami a long ways off now. We're cruising!!
    );
var total_photos = 16;
var narratives = Array(
    //"100_1748.jpg",
    "Bob and Sandi onboard the Pride of America with Miami in background; also in the background is the cruise ship 'Imagination'",
    //"100_1754.jpg",
    "Just Bob with Miami skyline",
    //"100_1758.jpg",
    "The RCCL Majesty of the Seas was berthed near us; this was one of only two other ships in Miami that day",
    //"100_1777.jpg",
    "Lifeboat drill: our muster station was the beautiful Liberty dining room, one of two main dining rooms",
    //"100_1778.jpg",
    "Conning the ship out of Miami; photo taken from the spacious balcony of our CruiseCritic team leader, 'livermorenancy'; John and Nancy had splurged on this very nice Grand Suite, and were kind enough to invite us other CC'ers up to watch the departure",
    //"100_1780.jpg",
    "Equipment for the old airlines that used to ply between Miami and Caribbean islands",
    //"100_1781.jpg",
    "The bridge between downtown and Miami Beach; this was our turning spot, since the Pride of America was pointing in, not out",
    //"100_1783.jpg",
    "Starting our turn",
    //"100_1784.jpg",
    "Continuing to turn, with Miami skyline in the background",
    //"100_1785.jpg",
    "We are nearly there",
    //"100_1788.jpg",
    "Now we are pointed in the right direction; these buildings are part of the cruise port",
    //"100_1789.jpg",
    "Bob and Sandi, taken as we left Miami",
    //"100_1790.jpg",
    "Near Miami harbor entrance",
    //"100_1791.jpg",
    "Big development near Miami harbor entrance; must be a bit of a drive to the grocery store!",
    //"100_1792.jpg",
    "Some of the Cruisecritic gang; we had a lot of fun on this cruise",
    //"100_1793.jpg",
    "Miami a long ways off; NOW we're cruising!!"
);
var titles = Array(
    //"100_1748.jpg",
    "Bob and Sandi",
    //"100_1754.jpg",
    "Bob",
    //"100_1758.jpg",
    "RCCL 'Majesty of the Seas'",
    //"100_1777.jpg",
    "Lifeboat Drill",
    //"100_1778.jpg",
    "Leaving Miami",
    //"100_1780.jpg",
    "Airplane",
    //"100_1781.jpg",
    "Bridge",
    //"100_1783.jpg",
    "Turning Around",
    //"100_1784.jpg",
    "Turning Around",
    //"100_1785.jpg",
    "Nearly There",
    //"100_1788.jpg",
    "Cruise Port",
    //"100_1789.jpg",
    "Bob and Sandi",
    //"100_1790.jpg",
    "Miami Harbor Entrance",
    //"100_1791.jpg",
    "Miami Harbor Entrance",
    //"100_1792.jpg",
    "Cruisecritic Gang",
    //"100_1793.jpg",
    "We're Cruising!!"
);

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
}
