BrowserDetect.init();
frameOver=new Image(); frameOver.src="img/frame-over.png";
frameOut=new Image(); frameOut.src="img/frame.png";
function setFrameOver(obj) { obj.src = frameOver.src; }
function setFrameOut(obj) { obj.src = frameOut.src; }

function showAlbum(album)
{
	try
	{
		var url = "albums/" + album + "/album.xml";
		makeSyncRequest(url, generateAlbum);
	}
	catch(err)
	{
		alert("Can't show album \"" + album + "\":\n" + err);
	}
}

function photo(id, width, height)
{
	this.id = id;
	this.width = width;
	this.height = height;	
}

var photoRegex = /(.+)(?:-l(?:w|b|g{1}))(\..+)/i;
function generateAlbum(httpRequest)
{
	try
	{
		document.write("<div class='album'>");
		var xmldoc = httpRequest.responseXML;
		var rootElement = xmldoc.documentElement;
		var album = rootElement.attributes.getNamedItem('id').value;
		var elements = xmldoc.getElementsByTagName('photo');
		for(var i = 0; i < elements.length; i++)
		{
			var element = elements[i];
			var p = new photo(
				element.getAttribute('id'),
				element.getAttribute('width'),
				element.getAttribute('height'));
			var match = photoRegex.exec(p.id);
			var littlePhoto = match[1] + match[2];
			if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7)
			{
				document.write("<div class='thumb'><a href='photo.html?album=" + album + "&amp;photo=" + p.id + "&amp;placeValuesBeforeTB_=savedValues&amp;TB_iframe=true&amp;height=800&amp;width=810&amp;modal=true' class='thickbox'><img src='albums/" + album + "/" + littlePhoto + "' width='103' height='103' alt=''/></a></div>");
			}
			else
			{
				document.write("<div class='thumb' style='background-image:url(albums/" + album + "/" + littlePhoto + ")'><a href='photo.html?album=" + album + "&amp;photo=" + p.id + "&amp;placeValuesBeforeTB_=savedValues&amp;TB_iframe=true&amp;height=800&amp;width=810&amp;modal=true' class='thickbox'><img src='img/frame.png' width='103' height='103' onmouseover='setFrameOver(this)' onmouseout='setFrameOut(this)' alt=''/></a></div>");
			}
		}
	}
	finally
	{
		document.write("</div>");
	}
}

