
			function processJson(data) { 
			// 'data' is the json object returned from the server 
			//alert(data.message); 
			if (data.status = true)
			{
				$j('.holder').hide();	
				$j('#callback').show().append("Vielen Dank für Ihre Nachricht.");	
				
			}
			else
			{
				$j('#callback').html("Fehler...");	
			}			
			
		}

(function($){


    var formoptions = { 
        target:        '#output2',   // target element(s) to be updated with server response 
        //beforeSubmit:  showRequest,  // pre-submit callback 
        success:       processJson,  // post-submit callback 
 
        // other available options: 
        url:       'includes/json_contact.php',         // override for form's 'action' attribute 
        type:      'post',        // 'get' or 'post', override for form's 'method' attribute 
        dataType:  'json'        // 'xml', 'script', or 'json' (expected server response type) 
        
		//clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit  
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
 
 
	//define the new for the plugin ans how to call it	
	$.fn.floatingcontact = function(options) {
		//set default options  
		var defaults = {
			url: 'http://YourServerHere.com/floatingcontact/mail.php',
			name: 'Name',
			email: 'Email',
			message : 'Message',
			subject : 'A floatingcontact message',
			submit : 'SEND',
			recievedMsg : 'Thank you for your message',
			notRecievedMsg : 'Sorry but your message could not be sent, try again later',
			disclaimer: 'Please feel free to get in touch, we value your feedback',
			hideOnSubmit: false

		};

		//call in the default otions
		var options = $.extend(defaults, options);
		//act upon the element that is passed into the design    
		return this.each(function() {
				//construct the form
				var this_id_prefix = '#'+this.id+' ';
				//$(this).html('<div id="floatingcontact_inner"></div><form id="floatingcontactForm" method="" action=""><div id="loading"></div><div id="callback"></div><div class="holder"><p><label for="name">'+options.name+'<span class="red"> * </span></label><br /><input id="name" class="contact" name="name"/></p><p><label for="email">'+options.email+' <span class="red"> * </span></label><br /><input id="email" class="contact" name="email" /></p><p><label for="message">'+options.message+' <span class="red"> * </span></label><br /><textarea id="message" name="message" class="message" rows="4" cols="30" ></textarea></p><p><input class="submit" type="submit" value="'+options.submit+'"/></p><p class="disclaimer">'+options.disclaimer+'</p></div></form>');
				//show / hide function
				$(this_id_prefix+'div#floatingcontact_inner').toggle(function() {
					$(this_id_prefix+'#overlay').css({display: 'block'});
					$(this).animate({"marginLeft": "-=5px"}, "fast"); 
					$(this_id_prefix+'#floatingcontactForm').animate({"marginLeft": "-=0px"}, "fast");
					$(this).animate({"marginLeft": "+=387px"}, "slow"); 
					$(this_id_prefix+'#floatingcontactForm').animate({"marginLeft": "+=390px"}, "slow"); 
				}, 
				function() {
					$(this_id_prefix+'#floatingcontactForm').animate({"marginLeft": "-=390px"}, "slow");
					$(this).animate({"marginLeft": "-=387px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
					$(this_id_prefix+'#overlay').css({display: 'none'});
				});
												
				$(this_id_prefix+'#floatingsubmitbutton').click(function() {				  				 
				  $j("#floatingcontactForm").validationEngine("updatePromptsPosition")    
					if ($j("#floatingcontactForm").validationEngine('validate'))
					{						
						$j("#floatingcontactForm").submit();
					}
					else
					{						
					}					
				});
	
				$(this_id_prefix+'#floatingcontactForm').submit(function() { 
					// inside event callbacks 'this' is the DOM element so we first 
					// wrap it in a jQuery object and then invoke ajaxSubmit 
					$(this).ajaxSubmit(formoptions); 
			 
					// !!! Important !!! 
					// always return false to prevent standard browser submit and page navigation 
					return false; 
				}); 
			
			/*
			//validate the form  
			$(this_id_prefix+"#floatingcontactForm").validate(
			{
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					email: {
						required: true,
						email: true
					},
					message: {
						required: true
					}
				},
				//set messages to appear inline
					messages: {
						name: "",
						email: "",
						message: ""
					},			

				submitHandler: function() {
					$(this_id_prefix+'.holder').hide();
					$(this_id_prefix+'#loading').show();
					$.ajax({
							  type: 'POST',
							  url: options.url,
							  data: {subject:options.subject, name:$(this_id_prefix+'#name').val(), email:$(this_id_prefix+'#email').val(), message:$(this_id_prefix+'#message').val()},
							  success: function(data){
								$(this_id_prefix+'#loading').css({display:'none'}); 
									$(this_id_prefix+'#callback').show().append(options.recievedMsg);
so								if( data == 'success') {
									if(options.hideOnSubmit == true) {
										//hide the tab after successful submition if requested
										$(this_id_prefix+'#floatingcontactForm').animate({dummy:1}, 2000).animate({"marginLeft": "-=450px"}, "slow");
										$(this_id_prefix+'div#floatingcontact_inner').animate({dummy:1}, 2000).animate({"marginLeft": "-=447px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
										$(this_id_prefix+'#overlay').css({display: 'none'});	
									}
								} else {
									$(this_id_prefix+'#callback').show().append(options.notRecievedMsg);
									setTimeout(function(){
										$(this_id_prefix+'.holder').show();
										$(this_id_prefix+'#callback').hide().html('');
									},2000);
								}
							},
							error:function(){
								$(this_id_prefix+'#loading').css({display:'none'}); 
								$(this_id_prefix+'#callback').show().append(options.notRecievedMsg);
                                        }
							});		
				}
			});
			*/
		});
	};
 
})(jQuery);

