



//when document is loaded and ready

$(document).ready(function() {
	//Slide Scroll to Element
	$("a.anchorLink").anchorAnimate()
	
	// Declare variables to hold twitter API url and user name
	  var twitter_api_url = 'http://search.twitter.com/search.json';
	  var twitter_user    = 'seagoat';

	  // Enable caching
	  $.ajaxSetup({ cache: true });

	  // Send JSON request
	  // The returned JSON object will have a property called "results" where we find
	  // a list of the tweets matching our request query
	  $.getJSON(
	    twitter_api_url + '?callback=?&rpp=4&q=from:' + twitter_user,
	    function(data) {
	      $.each(data.results, function(i, tweet) {
	        // Uncomment line below to show tweet data in Fire Bug console
	        // Very helpful to find out what is available in the tweet objects
	        //console.log(tweet);

	        // Before we continue we check that we got data
	        if(tweet.text !== undefined) {
	          // Calculate how many hours ago was the tweet posted
	          var date_tweet = new Date(tweet.created_at);
	          var date_now   = new Date();
	          var date_diff  = date_now - date_tweet;
	          var hours      = Math.round(date_diff/(1000*60*60));

	          // Build the html string for the current tweet
	          var tweet_html = '<div class="tweet_text">';
	          tweet_html    += '<a target="_blank" href="http://www.twitter.com/';
	          tweet_html    += twitter_user + '/status/' + tweet.id_str + '">';
	          tweet_html    += tweet.text + '<\/a><\/div>';
	          tweet_html    += '<div class="tweet_hours">' + hours;
	          tweet_html    += ' hours ago<\/div>';

	          // Append html string to tweet_container div
	          $('#tweet').append(tweet_html);
	        }
	      });
	    }
	  );
	
	//flickr API pull
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=43102927@N00&tags=instagramapp&lang=en-us&format=json&jsoncallback=?", function(data){
	  $.each(data.items, function(i,item){
	    $("<img/>").attr("src", item.media.m).appendTo("#instagram")
	    	.wrap("<a target='_blank' href='" + item.link + "'></a>");
			if (i==5) {
				return false;
			};
	  });
	});
	
});

//isotope activate

$('#masonTime').isotope({
  // options
	animationOptions: {
	     duration: 750,
	     easing: 'linear',
	     queue: false
	   },
  	itemSelector : '.workitem',
  	layoutMode : 'masonry'
});
		

//filter work items

$('#workFilters li').click(function() {
	var cname = $(this).attr('class');
	if ($(this).hasClass('selected')) {
		return false;
	} else {
		$('#workFilters li').removeClass('selected');
		$('#masonTime').isotope({ filter: '.'+cname+'' });
		$(this).addClass('selected');
	};
});

//work overlay to show description
$('.workitem').hover(function() {
	//toggle display on overlay class
	$(".overlay", this).fadeToggle("fast", "linear");
});



//animate scroll to named anchors
jQuery.fn.anchorAnimate = function(settings) {
 	settings = jQuery.extend({
		speed : 1100
	}, settings);	

	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")

			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination - 70}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
};


