$(document).ready(function() {
		
$('.colorbox').colorbox({
	width: 425,
	inititialWidth: 425,
	height: 380,
	initialHeight: 380,
	inline: true,
	href: '#contact-form',
	scrolling: false,
	transition: 'none'
}, function() {
	$('#contact-form').css('display', 'block');
});

$('#contact-form button').click(function() {
	$.fn.colorbox.close();
	$('#contact-form').css('display', 'none');
	return false;
});

$('.updates li').remove();

var twitterUrl = 'http://twitter.com/statuses/user_timeline/contrastfilms.json?count=20&callback=?';

$.getJSON(twitterUrl, function(data) {
	$.each(data, function(i, tweet) {
		if (tweet.text.substring(0, 1) != '@' && $('.updates li').length < 3) {
			var username = tweet.user.screen_name;
			// Replacement method from Twitter Blogger script (http://twitter.com/javascripts/blogger.js)
			var status = tweet.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
		      return '<a href="'+url+'">'+url+'</a>';
		    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
		      return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
		    });
			var html = '<a class="published" href="http://twitter.com/' + username + '/statuses/' + tweet.id +'">' + relative_time(tweet.created_at) + '</a> ' + status;
			$('<li/>').html(html).appendTo('.updates ul');
		}
	})
});
	
// Relative time function from Twitter Blogger script (http://twitter.com/javascripts/blogger.js)
function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);
  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

if (location.href.indexOf('message=sent') != -1) {
	var notification = $('<div/>').addClass('notification').html('<p>Your message has been sent<a href="#">Close</a></p>');
	$('div.main').css('border-top', '1px solid #151515');
	$('body').prepend(notification);
}

$('.notification a').live('click', function() {
	$('.notification').remove();
	$('div.main').css('border-top', 'none');
	return false;
});
	
});

