$(document).ready(function($) {

$('#search-query').focus(function() {
	if ($(this).val() == 'Search') {
		this.value = '';
	}
}).blur(function() {
	if ($(this).val() == '') {
		this.value = 'Search';
	}
});

if ($('.syntax').length) {
	$.getScript('/style/syntax/min.js', function () {
		$.syntax({
			root: '/style/syntax/',
			blockLayout: 'fixed'
		});
	});
}
if ($('.showcase').length) {
	$.getScript('/style/jquery-ui-1.8.13.custom.min.js', function () {
		$('.showcase').tabs({ select: function(event, ui) {
			document.location.hash = ui.tab.hash;
		}});
	});
}
if ($('.gallery').length || $('.external').length) {
	$.getScript('/style/colorbox.js', function() {
		$('.gallery a').colorbox({
			maxWidth: '90%',
			maxHeight:'90%'
		});
		$('.external').colorbox({
			iframe: true,
			width: 940,
			height: '80%',
			maxWidth: '90%',
			maxHeight:'90%'
		});
	});
}
if ($('#gravatar').length) {
	function gravatar(email) {
		return 'http://www.gravatar.com/avatar/' + $.md5(email);
	}
	$.getScript('/style/md5.js', function() {
		$('#email').blur(function () {
			var email = $(this).val().toLowerCase();
			if (email.indexOf('@') == -1) return;
			var img = new Image();
			$(img).load(function() {
				$('#gravatar').html('<img src="'+gravatar(email)+'?s=40&d=monsterid&r=R" />');
			}).attr('src', gravatar(email)+'?s=40&d=monsterid&r=R'); 
		});
		$('.comment-reply-link, #cancel-comment-reply-link').click(function() {
			$('.comment-reply-link').show();
			$(this).hide();
		});
	});
}

});
