(function($) {

	$.fn.transform = function(options) {
	
		//// setup parameters
		var defaults = {
			transform: 'ns',	//// form, links, images etc, if 'ns' that nothing has been configured
			form_send: 'ns'		//// send via ajx or traditional method
		};
			
		var options = $.extend(defaults, options);
		
		//// each instance
		return this.each(function(i) {
		
			//// not set
			if(options.transform == 'ns') {
				alert("Please tell me what it is I am configuring i.e. 'form'");
			};
			
			//// if transform = form then do the following
			if(options.transform == 'form') {
			
				//// not set
				if(options.form_send == 'ns') {
					alert("Please tell me how to send the form. 'ajax, post'");
				};
				
				$(this).submit(function() {
	
					//// get all the hidden fields and serilize them
					var fields = $(this).serialize();
					
					//// get ready for ajax
					var p = $('input[name="p"]').val();
					
					//// send ajax baby!, dont forget its xml all the way
					$.ajax({
						type : "POST",
						url  : "pages/" + p + ".php",
						data : fields,
						dataType : "xml",
						success: function(xml) {
													
							//// result and code				
							$(xml).find('result').each(function() {
								code = $(this).attr('code');
								message = $(this).text();	
								
								//// code 2 or 3
								if(code == 2) { alert(message); }
								if(code == 3) { alert(message); }
										
							});
							
							//// redirect?
							$(xml).find('redirect').each(function() {
								path = $(this).text();
								window.location = path;						
							});
							
										
						},
						error: function(){ alert('Failed for some reason'); }
					});
					
					return false;
					
				});
				
			};
		
		});
		
	};

})(jQuery);