// 
// photo album handling
//
var numbers = Array(
    "100_2373.jpg",
    "100_2376.jpg",
    "100_2375.jpg",
    "100_2377.jpg",
    "100_2424.jpg",
    "100_2379.jpg",
    "100_2382.jpg",
    "100_2381.jpg",
    "100_2384.jpg",
    "100_2385.jpg",
    "100_2386.jpg",
    "100_2389.jpg",
    "100_2391.jpg",
    "100_2392.jpg",
    "100_2400.jpg",
    "100_2403.jpg",
    "100_2412.jpg"
);
var total_photos = 17;
var narratives = Array(
    // 100_2373.jpg
    "We arrived in Puntarenas next to a bulk carrier.",
    // 100_2376.jpg
    "The busses lined up early to take people on shore excursions.",
    // 100_2375.jpg
    "A view of the beach at Puntarenas from our cabin.",
    // 100_2377.jpg
    "Due to the tide level, they had to create a rather fancy gangway. This took much time to complete.",
    // 100_2424.jpg
    "The security on the pier included sniffer dogs.",
    // 100_2379.jpg
    "The busses had all the amenities!",
    // 100_2382.jpg
    "The bulk carrier...",
    // 100_2381.jpg
    "is from India!",
    // 100_2384.jpg
    "The beautiful Gulf of Nicoya is a very large inlet of the Pacific Ocean. Puntarenas is the primary port town.",
    // 100_2385.jpg
    "There are many islands and beaches aound this Gulf.",
    // 100_2386.jpg
    "High mountains rise up on the landward side.",
    // 100_2389.jpg
    "You can see the mountains rising behind the coastline.",
    // 100_2391.jpg
    "Puntarenas means 'sand point' in English, and it is just that, a spit of sand.",
    // 100_2392.jpg
    "Looking down the pier towards the town.",
    // 100_2400.jpg
    "The Pride tied up at Puntarenas",
    // 100_2403.jpg
    "Distance photo of the Pride, taken from the beach area.",
    // 100_2412.jpg
    "Remember that photo of the gangway? Well, now everyone is trying to get back on board..."
);
var titles = Array(
    // 100_2373.jpg
    "Bulk Carrier Next to the Pride",
    // 100_2376.jpg
    "Busses for Shore Excursions",
    // 100_2375.jpg
    "Puntarenas Beach and Pier",
    // 100_2377.jpg
    "Improvised Gangway",
    // 100_2424.jpg
    "Doggie Van",
    // 100_2379.jpg
    "All the Amenities",
    // 100_2382.jpg
    "Bulk Carrier",
    // 100_2381.jpg
    "Our Indian Companion",
    // 100_2384.jpg
    "Gulf of Nicoya",
    // 100_2385.jpg
    "Gulf of Nicoya Islands",
    // 100_2386.jpg
    "High Mountains in the Distance",
    // 100_2389.jpg
    "Coast and Mountains",
    // 100_2391.jpg
    "Puntarenas [sand point]",
    // 100_2392.jpg
    "Looking Towards Town",
    // 100_2400.jpg
    "Stern View of Pride",
    // 100_2403.jpg
    "Pride Viewed From the Beach",
    // 100_2412.jpg
    "Passengers Return"
);

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,'Puntarenas_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
}
