// File: readXML.js

// Start function when DOM has completely loaded 
$(document).ready(function(){ 
	// get the page name and build the xml file name
	var address = location.href;
	var lastSlash = address.lastIndexOf( "/" );
	var lastDot = address.lastIndexOf( ".asp" );
	var filename = address.substring( lastSlash+1, lastDot );
	
	// Open the students.xml file
	$.get("xml/" + filename + ".xml",{},function(xml){
      	
		// Build an HTML string
		myHTMLOutput = "";
	 	myHTMLOutput += "<ul>";
	  	
		// Run the function for each student tag in the XML file
		$( "photo", xml ).each(function(i) {
			medHREF = $(this).find("med").text();
			title = $(this).find("title").text();
			smlHREF = $(this).find("sml").text();
			w = $(this).find("w").text();
			h = $(this).find("h").text(); 
			
			// Build row HTML data and store in string
			mydata = buildImageStrip( medHREF, title, smlHREF, w, h );
			myHTMLOutput = myHTMLOutput + mydata;
		});
		myHTMLOutput += "</ul>";
		
		// Update the DIV called Content Area with the HTML string
		$("#gallery").append(myHTMLOutput);
		$('#gallery a').lightBox({fixedNavigation:true});
	});
	
	// call the lightbox code?
	
});
 
 
 
function buildImageStrip( medHREF, title, smlHREF, w, h )
{	
	// Build HTML string and return
	output = "";
	output += "<li>\n";
	output += "\t<a href=\"" + medHREF + "\" title=\"" + title + "\" >\n";
	output += "\t\t<img src=\"" + smlHREF + "\" width=\"" + w + "\" height=\"" + h + "\" alt=\"\" >\n";
	output += "\n</a>";
	output += "</li>";
	return output;
}
	 
