/* jQuery extensions */

jQuery.fn.log = function( msg ) {
	if ( console ) {
		console.log("%s: %o", msg, this);
	}

	return this;
}



/* Scripts for all pages */

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

//	fixPageHeight();
	fixForms();
});

var createMenuRollOvers = function( ) {
	$(".menu-image").each(function( ) {
		var src = $(this).attr("src");
		var img = new Image();

		img.src = src.replace(/off/, "on");
		
		$(this).hover(
			function( ) {
				$(this).attr("src", img.src);
			}, 
			function( ) {
				$(this).attr("src", src);
			}
		);
	});
}

var fixPageHeight = function( ) {
	if ( $("#content").height() < 440 ) {
		$("#content").height(440);
	}
}

var fixForms = function( ) {
	$("input[type=text], input[type=password], textarea").each(function( ) {
		var label = $(this).prev("label").eq(0);
		
		var initialValue = label.html();
		
		if ( /^\s*$/.test($(this).val()) || $(this).val() == initialValue ) {
			// only set label value if there is no value in the field
			
			$(this).data("labelText", initialValue);
			$(this).val(initialValue);
			
			$(this).addClass("defaultValue");
		}
		
		label.hide();
		
		$(this).focus(function( ) {
			if ( $(this).val() == $(this).data("labelText") ) {
				$(this).val("");
				$(this).removeClass("defaultValue");
			}
		});
	});
}