var slideshow;
$(document).ready(function() {
	slideShow('#photo');
	lightbox('.lightbox');
	window.makeMailLinks()?makeMailLinks():null;
});

function slideShow(element) {
	$(element).children('img').not(':last').hide();
	if($(element).length>0){
		slideshow = setInterval(function() {
			if($(element).children('img:visible:eq(0)').prev().size()>0) {
				$(element).children('img:visible:eq(0)').prev().show(function(){
					$(element).children('img:visible:eq(1)').fadeOut(1500);
					});
			}
			else {
				$(element).children('img:last').fadeIn(1000, function() {
					$(element).children('img:visible').not(':last').fadeOut(1500);
				});
			}
		}, 3000);
	}
}
function lightbox(e){
	$(e).click(function(){
		clearInterval(slideshow); //stop slideshow
		$('body').append('<div id="overlay"></div><div id="lightboxcontainer"><div id="close"></div><div id="lightboxcontent"></div></div>');
		$('#overlay').height($(document).height());
		$('#close,#overlay').click(function(){
			$('#overlay,#lightboxcontainer').remove();
			slideShow('#photo'); //restart slideshow
			});
		$('#lightboxcontent').load($(this).attr('href'),{'lightbox':'true'});
		return false;
		});
	}
	
/* <span class="email">x (at) x.com</span> becomes <a href="x@x.com">x@x.com</a> 
* this is an anti-spam measure
*/
function makeMailLinks(){
		$('span.email').each(function(){
			var theAddress = $(this).text().replace(/ \(at\) /, "@");
			$(this).replaceWith($('<a href="mailto:'+theAddress+'">'+theAddress+'</a>'));
			});
	}


