$(document).ready(function(){
	slideShow('#photo');
	if($().fancybox){
		$("a.tntbox").fancybox({
			'titlePosition'  : 'inside'
		});
	}
	thumbHover();
	defaultTitle = $('h1').text();
	window.makeMailLinks()?makeMailLinks():null;
});

function thumbHover(){
	$('ul.imglist li a').hover(function(){
		replaceTitle('h1', defaultTitle+' - '+$(this).attr('title'));
	}, function(){
		replaceTitle('h1', defaultTitle);
	});
}

function replaceTitle(element, string){
	$(element).html(string);
}

function slideShow(element){
	var selector = $(element);
	if(selector.length>0){
		selector.children('img:gt(0)').hide();
		var slideshow = window.setInterval(function() {
			if(selector.children('img:visible:eq(0)').prev().size()>0) {
				selector.children('img:visible:eq(0)').prev().show(function(){
					selector.children('img:visible:eq(1)').fadeOut();
					});
			}
			else {
				selector.children('img:last').fadeIn('default', function() {
					selector.children('img:visible').not(':last').fadeOut();
				});
			}
		}, 3000);
	}
}
/*
function tntBox(element){
	
	var overlay = $('div#overlay');
	var box 	= $('div#boxcontent');
	var data	= $('div#boxcontent div#data');
	var body	= $('body');
	var close	= $('div#boxcontent a.close');
	var title	= $('div#boxcontent h2');
	
	element.click(function(){
		openBox($(this).attr('href'), $(this).attr('title'));
		return false;
	});
	
	overlay.click(function(){
		closeBox();
		return false;
	});

	close.click(function(){
		closeBox();
		return false;
	});

	function openBox(imgPath, titlestring){
		overlay.css({'height': $(document).height()}).show();
		box.fadeTo('def', 100, function(){
			var img = new Image();
			$(img).load(function(){					
				positionBox(this.width, this.height+30, function(){
					$('div#boxcontent img').fadeIn();
					close.show();
					title.html(titlestring);
				});
				$(this).hide();
				data.append(this);
			});
			$(img).attr('src', imgPath);
		});
	}
	
	function closeBox(){
		box.stop();
		overlay.fadeOut(200);
		box.hide().css({'width': 20, 'height': 20, 'marginLeft': -10, 'marginTop': -10});
		data.empty();
		close.hide();
		title.empty();
	}
	
	function positionBox(imgWidth, imgHeight, callback){
		box.animate({width: imgWidth, height: imgHeight, marginLeft: -imgWidth/2, marginTop: -imgHeight/2}, function(){
			callback();
		});
	}
	
}
*/
/* <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()
	{
	if (!document.getElementsByTagName && !document.createElement && !document.createTextNode)
		return;
	var spans = document.getElementsByTagName("span");
	for(var i=0;i<spans.length;i++)
		{
		if (spans[i].className=="email")
			{
			var theNode = spans[i];
			var theAddress = theNode.firstChild.nodeValue;
			var s = theNode.getAttribute('style');

			theAddress = theAddress.replace(/ \(at\) /, "@");
			theAddressNode = document.createElement('A');
			theAddressNode.setAttribute("href", "mailto:" + theAddress);

			if(typeof s == 'object') {
				s=s.cssText;
				theAddressNode.style.cssText= s;
			}else{
				theAddressNode.setAttribute("style", s);
			}

			
			theAddressNode.appendChild(document.createTextNode(theAddress));
			theNode.parentNode.replaceChild(theAddressNode, theNode);
			i--; //because we implicitly removed a <span> from the spans array by making it an <a>; Otherwise it'll skip the next span
			}
		}
	}
