jQuery(document).ready(function($) {
	
	// Series Accordion 
	$('#series ol').hide();
	$('#series h4').css('cursor', 'pointer').addClass('closed');
	$('#series h4').click(function(){
		$('#series h4').toggleClass('closed');
		$('#series ol').slideToggle('fast');
	});
	
	// J/K Navigation for Photoblog
	$(window).bind('keydown', function(e) {
						
		if($(e.target).is('input') || $(e.target).is('textarea')) return;
		
		if($('.post.photographs').length === 0) return;
		
		var key = e.keyCode || e.charCode || e.which;
		switch(key) {
			case 74:
				document.location = $('#recent a:first').attr('href') + '#content';
				break;
			case 75:
				document.location = $('#earlier a:first').attr('href') + '#content';
				break;
			return;
		}
	});

	$('#post-2766').jkNavigation();
	$('#post-2911').jkNavigation();
		
});



// 	J/K Navigation Plugin for Image Lists
(function($) {
	
	$.fn.extend({
		jkNavigation: function(options) {
			return this.each(function() {
				new $.JKNavigation(this, options);
			});
		}
	});
	
	$.JKNavigation = function(element, options) {
		
		var defaults = {
			// no options at the moment
		};
		this.options		= $.extend({}, defaults, options || {});
		this.element		= $(element);
		this.images			= $('img', this.element);
		this.currentImage	= null;
		this.run();
	};
	
	$.extend($.JKNavigation.prototype, {
		
		run: function() {
			
			self = this;
			
			$(window).bind('keydown', function(event) {
				
				if($(event.target).is('input') || $(event.target).is('textarea')) return;
								
				var key = event.keyCode;
				
				switch(key) {
					case 74:
						if(self.currentImage == null) {
							self.currentImage = 0;
						} else if(!(self.currentImage == self.images.length - 1)) {
							self.currentImage++;
						}
						break;
					case 75:
						if(self.currentImage == null) {
							return;
						} else if(!(self.currentImage == 0)) {
							self.currentImage--;
						}
						break;
					default:
					return;
				}
				
				var img = self.images.eq(self.currentImage);
				var pos = img.offset().top;
				
				$('html, body').scrollTop(pos);
				
			});
			
		}
		
	});
	
})(jQuery);

