$(document).ready(function(){

	//toggle visibility of work sample
	var $viewOne = $("div.info-block.one b.view-more");
	var $sampleOne = $("div.info-block.one div.sample");
	$sampleOne.hide();
	
	$viewOne.click(function(){
		
		$(this).text($(this).text() == 'View work sample' ? 'Hide work sample' : 'View work sample');
		$sampleOne.animate({opacity: 'toggle', height: 'toggle'}, 400);
		return;

	});
	
	var $viewTwo = $("div.info-block.two b.view-more");
	var $sampleTwo = $("div.info-block.two div.sample");
	$sampleTwo.hide();
	
	$viewTwo.click(function(){
		
		$(this).text($(this).text() == 'View work sample' ? 'Hide work sample' : 'View work sample');
		$sampleTwo.animate({opacity: 'toggle', height: 'toggle'}, 400);
		return;

	});
	
	var $viewThree = $("div.info-block.three b.view-more");
	var $sampleThree = $("div.info-block.three div.sample");
	$sampleThree.hide();
	
	$viewThree.click(function(){
		
		$(this).text($(this).text() == 'View work sample' ? 'Hide work sample' : 'View work sample');
		$sampleThree.animate({opacity: 'toggle', height: 'toggle'}, 400);
		return;

	});
	
	var $viewFour = $("div.info-block.four b.view-more");
	var $sampleFour = $("div.info-block.four div.sample");
	$sampleFour.hide();
	
	$viewFour.click(function(){
		
		$(this).text($(this).text() == 'View work sample' ? 'Hide work sample' : 'View work sample');
		$sampleFour.animate({opacity: 'toggle', height: 'toggle'}, 400);
		return;

	});
	
	//fancybox lightbox
	$("a.sample-link").fancybox();
	
	//Google Reader feed
	$('#googleshareditems').rssfeed('http://www.google.com/reader/public/atom/user%2F15167073887160809467%2Fstate%2Fcom.google%2Fbroadcast', {
		limit: 4
	});
	
	//Twitter Feed
	$.fn.tweets = function(options) {
		$.ajaxSetup({ cache: true });
		var defaults = {
			username: "MDWickham",
			tweets: 4,
			before: "<p class='tweet'>",
			after: "</p>"
		};
		var options = $.extend(defaults, options);
		return this.each(function() {
			var obj = $(this);
			$.getJSON('http://search.twitter.com/search.json?callback=?&rpp='+options.tweets+'&q=from:'+options.username,
		        function(data) {
		            $.each(data.results, function(i, tweet) {
		                if(tweet.text !== undefined) {
		                    $(obj).append(options.before+tweet.text+options.after);
		                }
		            });
		        }
		    );
		});
	};
	
	//Show latest Tweets at #tweets
	$('#tweets').tweets();

});

