// Add classes to html 
$(document).ready(function(){
	$("ul.lst li:last, ul.press li:last, body.home div.entry:last, body.archive div.entry:last, ol.comment-list li:last").addClass("last");
	$("li.twitter-item").addClass("group");
});

// The Konami Easter Egg 
$(document).ready(function(){
(function($) {

	$.fn.konami = function(callback, code) {
		if(code == undefined) code = "38,38,40,40,37,39,37,39,66,65";
		
		return this.each(function() {
			var kkeys = [];
			$(this).keydown(function(e){
				kkeys.push( e.keyCode );
				if ( kkeys.toString().indexOf( code ) >= 0 ){
					$(this).unbind('keydown', arguments.callee);
					callback(e);
				}
			}, true);
		});
	}

})(jQuery);

	$(window).konami(function(){
		window.location = "http://shawnville.com/konami-code/";
	});
});

// Lightbox image selection 
$(document).ready(function() { 

	/* This is basic - uses default settings */ 

	$("a#single_image").fancybox(); 
	
	/* Using custom settings */ 

	$("a#inline").fancybox({ 
		'hideOnContentClick': true 
	}); 

	$("a.img").fancybox({ 
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': false 
	}); 
}); 

// Flickr stream for footer
// Thanks to Richard Shepherd @
// http://www.richardshepherd.com/how-to-use-jquery-with-a-json-flickr-feed-to-display-photos/
$(document).ready(function(){					
						   
	// Our very special jQuery JSON fucntion call to Flickr, gets details of the most recent 20 images			   
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=21891297@N04&lang=en-us&format=json&jsoncallback=?", displayImages);
	
	function displayImages(data) {																																   
		// Randomly choose where to start. A random number between 0 and the number of photos we grabbed (20) minus 9 (we are displaying 9 photos).
		var iStart = Math.floor(Math.random()*(11));	
		
		// Reset our counter to 0
		var iCount = 0;								
		
		// Start putting together the HTML string
		var htmlString = "";

		
		// Now start cycling through our array of Flickr photo details
		$.each(data.items, function(i,item){
									
			// Let's only display 9 photos (a 3x3 grid), starting from a random point in the feed					
			if (iCount > iStart && iCount < (iStart + 9)) {
				
				// I only want the ickle square thumbnails
				var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");	
								
				// Here's where we piece together the HTML
				htmlString += '<a href="' + item.link + '" target="_blank">';
				htmlString += '<img src="' + sourceSquare + '" alt="' + item.title + '" title="' + item.title + '"/>';
				htmlString += '</a>';
			}
			// Increase our counter by 1
			iCount++;
		});		
		
	// Insert our HTML
	$('dd.flickr-images').html(htmlString);
	
	// Close down the JSON function call
	}
	
// The end of our jQuery function	
});