//Allow IE4 to work with us.
if(!document.getElementById && document.all){
	document.getElementById = function(id) {return document.all[id];}
}

//boolean of required object support
var objs_supported = (document.childNodes && document.getElementById) ? true : false;

//Perform show/hides and set up thumbnail onclicks
function setup_gallery(){

    //Gallery object to store last item and method to update gallery
    var obj_gallery = {
        last_item_displayed : "",    
        
        //show gallery item using passed-in id and set border of thumnail
        show_item : function(id){
            //if there's an item showing, hide it first and set thumb border to white
            if (this.last_item_displayed){            
                document.getElementById(this.last_item_displayed).style.display = "none";
                document.getElementById("t_" + this.last_item_displayed).style.borderColor = "#ffffff";
            }
            //display item and set corresponding thumb border colour
            document.getElementById(id).style.display = "block";
            document.getElementById("t_" + id).style.borderColor = "#27384A";
            //store id of current item displayed
            this.last_item_displayed = id;        
         }    
     }    
   
    
    /* apply an onclick to all the links around the thumbnails to display corresponding gallery item, 
    and apply an id to the thumbnails so their border colour can be set */
    
    var i = document.getElementById('photothumbs').childNodes;     
    var A_count = 1;   
    for (var j = 0; j < i.length; j++){       
        if (i[j].nodeName && i[j].nodeName == "A"){          
            //set name of A tag (this will correspond to id of gallery item div)                 
           i[j].name = "item" + (A_count);
           //set id of image within A tag
           i[j].childNodes[0].id = "t_item" + (A_count); 
           //set onclick of A tag to function 
           i[j].onclick = function() {
                            obj_gallery.show_item(this.name);                            
                            return false;
                          };
           A_count ++;          
         }                 
     }  
     
     //when page first loads, display first gallery item
    obj_gallery.show_item("item1");   
     
    //show the thumnails (so only JS users see it)  
    document.getElementById("photothumbs").style.display = "block";
}

if (objs_supported) { window.onload = setup_gallery; }