
/*
Copyright (c) 2006 Ylab, http://www.ylab.nl

Function to replace the large photo on the page; returns:
: False in case of success
: True  in case of an error

example usage:
<a href="http://www.flickr.com/photos/yohancreemers/296229828"
   onclick="if(showPhoto){return showPhoto('http://static.flickr.com/121/296229828_fe716db5e3.jpg');}">
   <img alt="Sony Centre" src="http://static.flickr.com/121/296229828_fe716db5e3_s.jpg" />
</a>
*/
var img;
var downloadlinks;

function showPhoto(sUrl){
	if(downloadlinks || findDownloadlinks()){
		var pos = sUrl.lastIndexOf('.jpg');
		sUrlDownload = sUrl.substring(0, pos);
		downloadlinks[0].href = sUrlDownload + '_d.jpg';
		downloadlinks[1].href = sUrlDownload + '_b_d.jpg';
		downloadlinks[2].href = sUrlDownload + '_o_d.jpg';
	}
	if(img || findImg()){
		img.src = sUrl;
		//prevent execution of the link
		return false;
	}
	//failure, follow the link
	return true;
}

function findImg(){
	if(!img){
		//find the <img> containing the large photo
		try{
			var div = document.getElementById('largePhotoContainer');
			//it's the first image within the container
			img = div.getElementsByTagName('img')[0];
			//test setting a property of the element
			img.alt = '';
		}
		catch(e){
			return false;
		}
	}
	//success
	return true;
}

function findDownloadlinks(){
	if(!downloadlinks){
		//find the <a> referring to the downlaod
		try{
			var div = document.getElementById('downloadlinks');
			//it's the first image within the container
			downloadlinks = div.getElementsByTagName('a');
		}
		catch(e){
			return false;
		}
	}
	//success
	return (downloadlinks != undefined);
}