$(function() {
	var username = $('#twitter-username').val();
	$('#smt-follow-btn').attr({ 'href': 'http://twitter.com/' + username });
	$('#smt-twitter-username').html(username);
	
	$('#sidebar div.tweets, #smt-twitter-feed').tweet({
		count: 2,
		loading_text: 'Loading tweets...',
		template: '{text} {time}',
		username: username
	});
	
	$('#mainnav li').hoverIntent({
		over: function() {
			$.data(this, 'current', $(this).children('ul'));
			if (!$.data(this, 'current').is(':animated')) {
				$.data(this, 'current').fadeIn('fast');
			}
		},
		out: function() {
			$.data(this, 'current').fadeOut('fast');
		}
	});
	
	$('#newsletter-focus').click(function(e) {
		e.preventDefault();
		$.scrollTo('#newsletter-form', 400, {
			onAfter: function() {
				$('#newsletter-form input:first').focus();
			}
		});
	});
	
	$('a.colorbox').colorbox();
	$('a.colorbox.inline').colorbox({
		inline: true,
		innerWidth: 800
	});
	$('a.youtube, a.colorbox.iframe').colorbox({
		iframe: true,
		innerHeight: 480,
		innerWidth: 800
	});
	
	$.tools.tooltip.addEffect('customFade',
		function(done) {
			if ($.support.opacity) {
				this.getTip().stop(true, true).fadeIn('fast', done());
			}
			else {
				this.getTip().show();
				done();
			}
		},
		function(done) {
			if ($.support.opacity) {
				this.getTip().stop(true, true).fadeOut('fast', done());
			}
			else {
				this.getTip().hide();
				done();
			}
		}
	);
	$('a.tooltip').click(function(e) {
		e.preventDefault();
	}).tooltip({
		delay: 0,
		effect: 'customFade',
		offset: [-30, 0],
		predelay: 30,
		relative: true,
		onBeforeShow: function() {
			var $tooltip = this.getTip();
			if (!$tooltip.find('div.arrow').length) {
				$tooltip.prepend('<div class="arrow"></div>');
			}
		}
	});
	
	$('a.toggle').click(function(e) {
		e.preventDefault();
		
		var $div = $(this).parent().next('div');
		
		if ($div.length) {
			if ($div.is(':visible')) {
				$div.slideUp();
			}
			else {
				$div.slideDown();
			}
		}
	});
});
