// Initialize the effects
/*
$(document).ready(function(){
    $("#top_navi ul li a").mouseover(function() {
    	$(this).animate({
    		paddingTop: "15px"
    	}, 200);
    });
    $("#top_navi ul li a").mouseout(function() {
    	$(this).animate({
    		paddingTop: "0px"
    	}, 200);
    });			    
})
*/

(function($) {
	$.fn.extend({
		fancyField: function(options) {
			var field = $(this);
			var sampleValue = options["sampleValue"];
			
			// Setup data
			field.data("fancyField_state", {
				sampleValue: sampleValue,
				hasText: false
			});

			// Check if there is already some text in the field.
			// If not set the sampleValue
			if(field.val() == '' || field.val() == sampleValue) {
				field.val(sampleValue).addClass("noFocus");			
			} else {
				field.data("fancyField_state")["hasText"] = true;
			}

			// Scan for the parent form tag and register for the submit 
			// event.
			var form = field.parents().filter("form");
			var formState = form.data("fancyForm_state");
			if (formState == undefined) {
				// Initial setup
				formState = {
					fieldList: [field]
				}
				form.data("fancyForm_state", formState);
				form.submit(function() {
					var fieldList = formState["fieldList"];
					for (x in fieldList) {
						//alert(fieldList[x] + " - hasText:" + fieldList[x].data("fancyField_state")["hasText"]);
						if(!fieldList[x].data("fancyField_state")["hasText"]) {
							fieldList[x].val("");
						} 
					}
				});
			} else {
				formState["fieldList"].push(field);
			}			

			// When the field gets the focus we have to remove
			// the noFocus class and remove the sampleValue in case
			// it is set
			field.focus(function() {
				var field = $(this);
				if (field.val() == sampleValue) { field.val(""); }
				field.removeClass("noFocus");
			});

			// When the field loses the focus we must check if the
			// user typed something into the field. 
			field.blur(function() {
				var field = $(this);
				// Still sampleValue?
				//if(field.val() == '' && !field.data("fancyField_state")["hasText"]) { 
				if(field.val() == '') { 
					field.val(sampleValue).addClass("noFocus"); 
					field.data("fancyField_state")["hasText"] = false;
				} else {
					field.data("fancyField_state")["hasText"] = true;
				}
			});
		}
	})
})(jQuery);
