/*
 * jQuery plugin: formUI - 0.1
 * (c) 2009 NoMoreSleep <thomas@0nomoresleep.net> - http://www.nomoresleep.net
 */

(function($){
	$.fn.formUI = function(options){

		var defaultOptions = {  
            buttonClass: 'button',  
            focusClass: 'focus'
        };  

        var options = $.extend(defaultOptions, options);

		return this.each(function(){
			var form = $(this);
			
			/* Form submit */
			$(form).submit(function(){
				return options.submit($(form));
			});
			
			/* Make Submit Button's nice */
			$(form).find('button, input').each(function(i, button){
				if($(button).attr('type') == 'submit'){
					$(button).replaceWith('<a href="#" class="'+($(button).attr('class'))+' '+options.buttonClass+'"><span>'+($(button).attr('value') ? $(button).val() : $(button).html())+'</span></a>');
				}
			});
            
			
			$(form).find('.'+options.buttonClass).click(function(){
				$(form).submit();
				return false;
			});
			
			/* Focus & Blur Input Suggestions */
			$(form).find('input, textarea').each(function(i, input){
				if(($(input).attr('type') == 'text') | ($(input).attr('type') == 'password')){
					$(input).focus(function(){
						if($(this).val() == $(this).attr('alt')) $(this).val('');
					}).blur(function(){
						if($(this).val() == '') $(this).val($(this).attr('alt'));
					}).val($(input).attr('alt'));
				}
				/* Add & Remove "focus"-class */
				$(input).focus(function(){
					$(this).addClass(options.focusClass);
				}).blur(function(){
					$(this).removeClass(options.focusClass);
				})
			});
		});
	};
	
})(jQuery);
