gallery = { 	   
    
	init:function(){ 
	    
	    // Check for javascript compatibility
		if (!document.getElementById || !document.createTextNode) {
		    return;
        }
        		    		                 
        // Grab all the lists in the document        		    		                         		    		                 
		var lists = document.getElementsByTagName('ul');
		                                     
        // Find all the lists classed as 'gallery' and initialize them		                                     
		for (var i = 0; i < lists.length; i++) {
			if (!DOMhelp.cssjs('check', lists[i], 'gallery')) {
			    continue;
			}
			gallery.initShow(lists[i]);
		}
	},	     
	
	initShow:function(o) {                                     
	    // Create the elements required to display the large photo and caption
		var newli  = document.createElement('li');
		var newimg = document.createElement('img');
		var newp   = document.createElement('p');

        // Add the img and p elements as children of the li
		newli.appendChild(newimg);
		newli.appendChild(newp);
		                                   
        // Assign the css class 'photo' to the newly created li		                                   
		DOMhelp.cssjs('add', newli, 'photo'); 
		                                                                  
        // Grab a list of our thumbnail links for later 
        var links = o.getElementsByTagName('a');		                                                                  
		                                                                  
        // Grab the first thumbnail pic in the list and retrieve some info		                                              
		var firstPic = o.getElementsByTagName('img')[0];                  
		var alt      = firstPic.getAttribute('alt');
		
		// Set our attributes on the new image
		newimg.setAttribute('alt', alt);
		newimg.setAttribute('width', '464');
		newimg.setAttribute('height', '268');
		newimg.setAttribute('src', links[0].href);
		
		// Add in the caption to our new p element
		var caption = document.createTextNode(alt);
		newp.appendChild(caption); 

        // Insert the new li as the first child in the list		
		o.insertBefore(newli, o.firstChild);		
		
		// Loop through our links and add our click event						
		for (i = 0; i < links.length; i++) {
			DOMhelp.addEvent(links[i], 'click', gallery.showPic, false);
			links[i].onclick = function() {
			    return false;
			} // safari 
		}          
		      
        // Store a reference to our new img and p elements		      
		o.photo = newimg;
		o.cap   = newp;
	},      
	
	showPic:function(e) {             
	    
		var t      = DOMhelp.getTarget(e);
		var oldimg = t.parentNode.parentNode.parentNode.photo;
		var oldcap = t.parentNode.parentNode.parentNode.cap;
		oldimg.setAttribute('alt', t.getAttribute('alt'));
		oldimg.setAttribute('src', t.parentNode.getAttribute('href'));
		oldcap.innerHTML = t.getAttribute('alt');
		DOMhelp.cancelClick(e);
	}	
}	              

DOMhelp.addEvent(window, 'load', gallery.init, false);
