jQuery.fn.blueshade = function (options) {

	var options = jQuery.extend( {
		doblurfocus : 'true',
		dokeyup : 'true',
		doajax : 'false',
		doajaxurl : '',
		defaultFocus : ''
	},options);
	
this.each(function() {	
		
	// define some variables
		
		var spanid = 'inputsection_'+$(this).attr("name");
		
		var stylerspan = '<span id="';
		stylerspan += spanid;
		stylerspan += '" class="inputsection">';
		stylerspan += '</span>';
			
		// surround with styler span
		
		$(this).wrap(stylerspan);
		$(this).after('<div class="clear"></div>');
		
		// add title
		if($(this).attr('alt') != ''){
		$(this).before('<div class="formtxt"><label for="'+$(this).attr("name")+'">'+$(this).attr("alt")+'</label>'+'</div>');
		}
		// add ID value
		
		$(this).attr('id', 'input_'+$(this).attr('name'));
		
		// determine type & do type specific js
		
		var type = $(this).attr("type");
		
		if(type == 'text'){
		$(this).attr('class','txtinput');
		}
		
		// this is included here to make the css more efficient, and allow the exclusion of the applied css to
		// selected elements.
				
		if(this.tagName == 'SELECT'){
		$(this).css('margin-right', '15px');
		$(this).css('margin-top', '7px');
		}
		
		// style textareas
		if(this.tagName == 'TEXTAREA'){
		$(this).css('float', 'left').css('margin-right', '15px');
		$("#"+spanid).append('<div class="clear"></div>');
		}
		
		// add onfocus / blur
			
		if(options.doblurfocus == 'true') {
		
		$(this).blur(function(){
			
			$(this).attr("onblur");
		
			// remove error / noerror boxes
			
			$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();
			
			if($(this).val() != ''){			
						
				// ajax validation code
				
				if(options.doajax != 'false'){
								
				// do an ajax request using the submitted url
				// check for return either 'true' or 'false'
				
				$.get(options.doajaxurl, {name : $(this).attr('name'), str : $(this).val()}, function(data){
					// doajaxurl needs to be in the form of:
					// url.php
					if(data == 'true' || data == ''){
					$("#"+spanid).attr('class','inputsection2');
					$("#"+spanid).append('<p class="inputnoerror"></p>');					
					} else {
					if(data == 'false'){
					$("#"+spanid).attr('class','inputsection3');
					$("#"+spanid).append('<p class="inputerror"></p>');					
					}
					}
				
				});
				
				} else {
				$("#"+spanid).attr('class','inputsection2');
				$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();
				$("#"+spanid).append('<p class="inputnoerror"></p>');	
				}
			
			} else {
			$("#"+spanid).attr('class','inputsection');
			$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();			
			}
		});
		
		$(this).focus(function(){
			$("#"+spanid).attr('class','inputsection1');
			$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();		});
		
		if(options.dokeyup == 'true'){
		
		$(this).keyup(function(){
		
		if($(this).val() != ''){
		
				// remove error / noerror boxes
				
				$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();				
			
				// ajax validation code
				
				if(options.doajax != 'false'){
												
				// do an ajax request using the submitted url
				// check for return either 'true' or 'false'
				
				$.get(options.doajaxurl, {name : $(this).attr('name'), str : $(this).val()}, function(data){
					// doajaxurl needs to be in the form of:
					// url.php
					if(data == 'true' || data == ''){
					$("#"+spanid).attr('class','inputsection2');
					// extra remove in for keyup version
					$("#"+spanid+'> .inputerror, '+"#"+spanid+'> .inputnoerror').remove();			
					$("#"+spanid).append('<p class="inputnoerror"></p>');			
					} else {
					}
				
				});
				
				} else {
				$("#"+spanid).attr('class','inputsection2');
				$("#"+spanid).append('<p class="inputnoerror"></p>');				
				}
			
			} else {
//			$("#"+spanid).attr('class','inputsection');			
//			just leave it alone
			}
		
		
		});
		}
		
		}
		
		
	
});

if(options.defaultFocus != ''){
	setTimeout(function(){$(":input[name='"+options.defaultFocus+"']").focus();}, 300);
}


};