$(document).ready(function(){
	slideShow('.photo');
	makeMailLinks($('span.email'));
	$('ul.photolist>li>a').lightBox();
	$('a.lightbox').lightBox();

});

function slideShow(selector){
	
	var element = $(selector);
	
	element.each(function(){
		
		var current = $(this);
		var delay	= current.attr('rel');
	
		var imgStack 		= current.find('img');
		var imgStackSize 	= imgStack.size();
		
		if(imgStackSize>0){
			
			var randomEq 		= Math.floor(Math.random()*imgStackSize);
			
			var imgShow = current.find('img').eq(randomEq);
			
			imgShow.show();
		
			if(delay){
				setTimeout(function(){
					loopImages(current);
				}, delay);
			}
			else
			{
				loopImages(current);
			}
		
		}
		
	});
	
}

function loopImages(object){

	var fadeSpeed 		= 2000;
	var fadeInterval	= 6000;

	if(object.length>0){
		setInterval(function(){
			if(object.children('img:visible:eq(0)').prev().size()>0){
				object.children('img:visible:eq(0)').prev().show();
				object.children('img:visible:eq(1)').fadeOut(fadeSpeed);
			}
			else {
				object.children('img:last').fadeIn(fadeSpeed, function(){
					object.children('img:visible').not(':last').hide();
				});
			}
		}, fadeInterval);
	}
	
}
