// 
// photo album handling
// copyright 2005, 2006, Bob Swanson
// You may use this code for your own
// slideshows, but please retain this
// copyright notice
//
var numbers = Array(
"clipper_ready.jpg", 
    // "Star Clipper ready at the dock on Barbados",
"at_anchor.jpg",     
    // "Star Clipper at anchor",
"at_anchor2.jpg",    
    // "Distance view of Star Clipper anchored at Carriacou",
"exterior.jpg",  
    // "View of the hull",
"mast.jpg",   
    // "Looking up at the beautiful masts of the Star Clipper",
"mast2.jpg", 
    // "You can see all of the modern electronic gear on the mast",
"sails.jpg",          
    // "The majestic sails of the Star Clipper",
"sails2.jpg",           
    // "Another view of the sails full of wind",
"sails3.jpg",           
    // "The sails fill and drive us along on our cruise",
"sails4.jpg",        
    // "Another view of the Star Clipper sails",
"sailing.jpg", 
    // "The Star Clipper sailing along through the Caribbean",
"sailing2.jpg",   
    // "Looking forward, you can see that she heels over when sailing",
"sunset.jpg",           
    // "Beautiful sunset seen through the sails",
"bob_cabin.jpg",      
    // "Bob checks out the cabin, a pretty typical cruise ship size",
"sandi_n_bear.jpg",   
    // "Sandi won't cruise without her bear!",
"bob_cabin2.jpg",     
    // "Bob contemplates the expanse of the cabin",
"bob_n_sandi.jpg",   
    // "Bob and Sandi relax on deck",
"formal_dinner.jpg", 
    // "We had a great dinner with some British friends we met",
"crew.jpg",    
    // "The crew brings up the anchor",
"crew2.jpg",         
    // "The crew experiences sailing the old-fashioned way",
"crew3.jpg",       
    // "Modern machinery make it easier to haul the sheets",
"crew4.jpg",      
    // "Sometimes they still have to walk out on the spars",
"crew5.jpg",   
    // "Splicing remains a chore on a sailing ship",
"tender.jpg",            
    // "Crew runs the tender in and out of port",
"grand_piton.jpg"
    // "Grand Piton on St. Lucia, an imposing rock",
    );
var total_photos = 25;
var narratives = Array(
// "clipper_ready.jpg", 
    "Star Clipper ready at the dock on Barbados",
// "at_anchor.jpg",     
    "Star Clipper at anchor",
// "at_anchor2.jpg",    
    "Distance view of Star Clipper anchored at Carriacou",
// "exterior.jpg",  
    "View of the hull",
// "mast.jpg",   
    "Looking up at the beautiful masts of the Star Clipper",
// "mast2.jpg", 
    "You can see all of the modern electronic gear on the mast",
// "sails.jpg",          
    "The majestic sails of the Star Clipper",
// "sails2.jpg",           
    "Another view of the sails full of wind",
// "sails3.jpg",           
    "The sails fill and drive us along on our cruise",
// "sails4.jpg",        
    "Another view of the Star Clipper sails",
// "sailing.jpg", 
    "The Star Clipper sailing along through the Caribbean",
// "sailing2.jpg",   
    "Looking forward, you can see that she heels over when sailing",
// "sunset.jpg",           
    "Beautiful sunset seen through the sails",
// "bob_cabin.jpg",      
    "Bob checks out the cabin, a pretty typical cruise ship size",
// "sandi_n_bear.jpg",   
    "Sandi won't cruise without her bear!",
// "bob_cabin2.jpg",     
    "Bob contemplates the expanse of the cabin",
// "bob_n_sandi.jpg",   
    "Bob and Sandi relax on deck",
// "formal_dinner.jpg", 
    "We had a great dinner with some British friends we met",
// "crew.jpg",    
    "The crew brings up the anchor",
// "crew2.jpg",         
    "The crew experiences sailing the old-fashioned way",
// "crew3.jpg",       
    "Modern machinery make it easier to haul the sheets",
// "crew4.jpg",      
    "Sometimes they still have to walk out on the spars",
// "crew5.jpg",   
    "Splicing remains a chore on a sailing ship",
// "tender.jpg",            
    "Crew runs the tender in and out of port",
// "grand_piton.jpg", 
    "Grand Piton on St. Lucia, an imposing rock"
);
var titles = Array(
// "clipper_ready.jpg", 
    "Ready to Sail",
// "at_anchor.jpg",     
    "At Anchor",
// "at_anchor2.jpg",    
    "Anchored at Carriacou",
// "exterior.jpg",  
    "Clipper Hull",
// "mast.jpg",   
    "Masts",
// "mast2.jpg", 
    "Electronics",
// "sails.jpg",          
    "Majestic Sails",
// "sails2.jpg",           
    "Sails Full of Wind",
// "sails3.jpg",           
    "Sails",
// "sails4.jpg",        
    "Sails",
// "sailing.jpg", 
    "Sailing",
// "sailing2.jpg",   
    "She Heels Over",
// "sunset.jpg",           
    "Beautiful Sunset",
// "bob_cabin.jpg",      
    "Bob in Cabin",
// "sandi_n_bear.jpg",   
    "Sandi and Bear",
// "bob_cabin2.jpg",     
    "Bob",
// "bob_n_sandi.jpg",   
    "Kickin' Back",
// "formal_dinner.jpg", 
    "Dinner with New Friends",
// "crew.jpg",    
    "Up Anchor",
// "crew2.jpg",         
    "Sailing the Old-Fashioned Way",
// "crew3.jpg",       
    "Modern Machinery",
// "crew4.jpg",      
    "Out on the Spars",
// "crew5.jpg",   
    "Splicing",
// "tender.jpg",            
    "Tender",
// "grand_piton.jpg", 
    "An Imposing Rock"
);

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()
{
    document.write('<select id="picture_selector" name="picture_selector">');
        
    for (i = 0 ; i < total_photos ; i++)
    {
        document.write('<option value="' + i + '">' + 
                       i + " - " + titles[i] + '</option>');
    }
    document.write('</select>');
}

function get_thumb_url (position) {

    url = "http://www219.pair.com/swansonr/star_clipper/th_" + numbers[position];
    return url;
}

function get_picture_url (position) {

    url = "http://www219.pair.com/swansonr/star_clipper/" + 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,'star_clipper_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
}
