$(document).ready(function(){

	// make category photos clickable
	$('ul.cat ul img').click(function(){
		// get the h3
		document.location = $(this).parents('ul.cat').find('h3 a').attr('href');
	})
	
	$('ul.overview li img').click(function(){
		// get the h3
		document.location = $(this).parents('li').find('h3 a').attr('href');
	})
	
	// if for some kind of reason an anchor has slipped in, remove the functionality
	$('ul.cat ul li a, ul.overview li a').click(function(e){
		e.preventDefault();
	})
	
	// make the arrow keys work!
	if($('.postnav').length){
		$(window).keyup(function(event) {
			switch (event.keyCode){
				case 39:
					if($('.postnav .prev a').length){
						document.location = $('.postnav .prev a').attr('href');
					}
					break;
				case 37:
					if($('.postnav .next a').length){
						document.location = $('.postnav .next a').attr('href');
					}
					break;
			}
		});
	}

})

$(window).load(function(){
	if ($('.photos')){
		// do this when there's more than one picture
		if($('.photos li').length > 1){
			slideShow();
		}
	}
	
	function slideShow(){
		// clone the last child and append it as first child
		var _li = $('.photos li:last-child');
		_li.clone().insertBefore($('.photos li:first-child'));
		_li.delay(6000).fadeOut(550, function(){
			// when done, remove this node
			_li.remove();
			// recall slideShow
			slideShow();
		});
		/*
		var li = $('.photos li:last-child');
		// first clone the li we will fade out and append it as last child
		li.clone().insertBefore($('.photos li:first-child'));
		// fade out
		$('.photos li:last-child').delay(6000).fadeOut(500, function(){
			// drop this node
			$('.photos li:last-child').remove();
			// recall slideshow
			slideShow();
		})
		*/
	}
});
