// dom ready
$(document).ready(function(){
	//bottom news crap
	$('#rarr').bind('click', function(){
		$('.news_content .wrap').next().fadeIn(function(){
			$(this).prev().fadeOut();
		});
	});
	
	$('#larr').bind('click', function(){
		$('.news_content .wrap').prev().fadeIn(function(){
			$(this).next().fadeOut();
		});
	});
	
	
	$('.latest_news').css({ 'bottom' : -1 });
	$('.header, #frameworks, #projects, .project_list, .framework_list').css({ 'opacity' : 0, 'background' : '#efefef' });
});

//window load
$(window).load(function(){
	$('.contact_nav ul').animate({
		'left' : 0
	}, 'slow');
	setTimeout(function(){
		//twitter
		$.ajax({
			url : 'http://twitter.com/statuses/user_timeline/keepitscottie.json?callback=?',
			dataType : 'jsonp',
			success : function(data) {
				tweet = data[0];
				date = tweet.created_at;
				new_date = new Date(date);
				timestamp = new_date.toDateString();
				//timestamp = new Date(timestamp);
				//console.log(new_date.toDateString())

				$('.latest_tweet').html(tweet.text + '<br/>' + '<span><a style="color: #26A9E0;" href="http://twitter.com/#!/keepitscottie/status/' + tweet.id_str + '">' + timestamp + '</a></span>'); 
				$('.latest_tweet').fadeIn(function(){
					$('#loader').fadeOut();
				});
			}
		});
		//fsq
		$.ajax({
			url : 'https://api.foursquare.com/v2/users/672474?oauth_token=TU23VPTFCHT2JZ2MEFAZE4SV2QZRPNIFPPQ0JOE42LXTFH0Z&callback=?',
			dataType : 'jsonp',
			success : function(data) {				
				checkins = data.response.user.checkins.count; //number of checkins
				place = data.response.user.checkins.items[0].venue.name; //last checkin location
				date = new Date(data.response.user.checkins.items[0].createdAt);
				timestamp = date.toDateString();
				city = data.response.user.checkins.items[0].venue.location.city;
				state = data.response.user.checkins.items[0].venue.location.state;
				
				$('.latest_checkin').html(place + '<br/>' + '<span style="color: #26A9E0;">' + city + ', ' + state + '</span>');
			}
		});
	}, 1000);
	
	setTimeout(function(){
		$('.header').animate({ 'opacity' : 1 });
	}, 500);
	
	setTimeout(function(){
		$('#projects, .project_list').animate({ 'opacity' : 1 });
	}, 1000);
	
	setTimeout(function(){
		$('#frameworks, .framework_list').animate({ 'opacity' : 1 });
	}, 1500);
	
	setTimeout(function(){
		$('.latest_news').animate({ 'bottom' : -90 });
		$('.latest_news').hover(function() {
			$('.news_wrap').stop().animate({
				'bottom' : 89
			}, 'normal', 'easeOutQuint');
		}, function() {
			$('.news_wrap').stop().animate({
				'bottom' : 0
			});
		});
	}, 1500);
});

//window keypress - for fun little things
$(window).keydown(function(e){
	if (e.keyCode == 73) {
		//$('body').append('<div class="stuff">I don\'t know, and don\'t care how this site looks in IE. But it probably looks like shit.</div>')
	}
});

