// JavaScript Document

$(document).ready(function(){
	$("span.dayTwitter:last")
	.css({
		 'background' : 'none'
	});
	
	//$("#navUl li:eq(1)")
//	.css({
//		 'margin-right' : '7px'
//	});
	
	$("#navUl li:last")
	.css({
		 'margin-right' : '0'
	});
	
	/*Start Flickr*/
	// 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=43803387@N02&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 (8) minus 6 (we are displaying 6 photos). Depends on how many pics I have.
		var iStart = Math.floor(Math.random()*(2));	
		
		// Reset our counter to 0
		var iCount = 0;								
		
		// Start putting together the HTML string
		var htmlString = "<ul>";					
		
		// 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 + 7)) {
				
				// 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 += '<li><a href="' + item.link + '" target="_blank">';
				htmlString += '<img src="' + sourceSquare + '" alt="' + item.title + '" title="' + item.title + '"/>';
				htmlString += '</a></li>';
			}
			// Increase our counter by 1
			iCount++;
		});		
		
	// Pop our HTML in the #images DIV	
	$('#flickrImages').html(htmlString + "</ul>");
	
	// Close down the JSON function call
	}
	/*End Flickr*/
	
});
