/* Accordion functionality tutorial (code has been edited):
		http://designreviver.com/tutorials/jquery-examples-horizontal-accordion/
*/

$(document).ready(function() {
	
	// Vertical Accordion Effects
	
	lastBlock = $("#current");
    maxHeight = 458;
    minHeight = 50;
    
    $("#announcement li:last").css({
    	"border-bottom" : "0px"
    });

    $("#announcement li .order").click(function() {
        $(lastBlock).animate({
        	height: minHeight+"px"
        }, { queue:false, duration:403 }).attr("id", "");
        
	$(this).parent().animate({
		height: maxHeight+"px"
	}, { queue:false, duration:398}).attr("id", "current");
		
	lastBlock = $(this).parent();
		
	return false;
    });
    
    // Recent Posts Fade
    
    $("#featured_post_slider").innerfade({
		continuous: true,
		auto: true,
		speed: 800,
		timeout: 3000
	});
    
    // Flickr Code
	
	// Adapted from tutorial: http://www.richardshepherd.com/how-to-use-jquery-with-a-json-flickr-feed-to-display-photos/
	
	apiKey = $("#flickr_feed_url").text();
	
	$.getJSON(apiKey+"&lang=en-us&format=json&jsoncallback=?", displayImages);
	
	function displayImages(data) {
	
	    // Start putting together the HTML string
	    var htmlString = "";
	    
	    // Now start cycling through our array of Flickr photo details
	    $.each(data.items, function(i,item) {
	    
	        // 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 title="' + item.title + '" src="' + sourceSquare;
	        htmlString += '" alt="'; htmlString += item.title + '" />';
	        htmlString += '</a></li>';
	        
	        if(i == 9) return false; // Limits number of items to 10
	    });
	    
	    // Pop our HTML in the #images DIV
	    $('#flickr_area, #widget_flickr_stream').html(htmlString);
	    
	    // Close down the JSON function call
	}
});