// Reusable 'default text' plugin
jQuery.fn.defaultVal = function(value) {
	return this.each(function(){
		var $field = $(this);
		var $value = $field.val(),
			defaultValue = value;
		$field.addClass('placeholder');
		$field.focus(function(){
			if (($value == '') || ($value == defaultValue)) {
				$field.removeClass('placeholder').addClass('focus').val('');
				$value = $(this).val();
			}
		});
		$field.blur(function(){
			$value = $(this).val();
			if ($value == '') {
				$field.val(defaultValue).removeClass('focus').addClass('placeholder');
			} else { // Finally, a real value.
				$field.removeClass('placeholder').removeClass('focus');
			}
		});
		if ($value == ''){
			$field.val(defaultValue);
		}
	});
};

$("#search input").defaultVal("Search the site");

// == Current State indicator ==
$("#nav a").removeClass("here"); // Remove the 'here' class, just in case
var currentLocation = location.pathname.split("/")[1];
if (currentLocation == "") {
	$("#nav a:first").addClass("here"); // The home button when we're at root
} else {
	$("a[href^=/"+ currentLocation +"]").addClass("here"); // The nav link otherwise
};

// == Ajaxy Comment Forms ==
// Comments form
var $commentform = $('#comments-form'),
	$ajaxmessage = $('#ajax-comment').html('<img src="/_img/ajax-loader.gif" class="loading"/>');
	$loadingImg = $ajaxmessage.find('img.loading').hide();

if ($commentform.length) {
	  $commentform.ajaxForm({
		target: $ajaxmessage,
		beforeSubmit: function(data, $form, opt){
			$ajaxmessage.html($loadingImg);
			$loadingImg.show();
		},
		success: function() {
			$loadingImg.hide();
		}
	});
}; //end of if
