/*
 * contactable 1.2.1 - jQuery Ajax contact form
 *
 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Revision: $Id: jquery.contactable.js 2010-01-18 $
 *
 */
 
//extend the plugin
(function($){

	//define the new for the plugin ans how to call it	
	$.fn.contactable = function(options) {
		//set default options  
		var defaults = {
			recievedMsg : '<p class="recieved"><span>Danke für Ihre Anfrage. Wir rufen Sie schnellstmöglich zurück.</span></p><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1043981993/?label=kumBCOfmswIQqc3n8QM&amp;guid=ON&amp;script=0"/>',
			notRecievedMsg : '<p class="notrecieved"><span>Es ist ein Fehler aufgetreten. Bitte versuchen Sie es zu einem späteren Zeitpunkt erneut.</span></p>',
			hideOnSubmit: true
		};

		//call in the default otions
		var options = $.extend(defaults, options);
		//act upon the element that is passed into the design    
		return this.each(function(options) {
			//construct the form
			$(this).html('<div id="callbutton"><span>Rückruf</span></div><h2>Wir rufen Sie zurück</h2><form action="" method="" id="contactForm"><div class="field"><label for="name">Name</label><input class="inputText" name="name" type="text" id="name" size="30" maxlength="50" value=""><div class="clear"></div></div><div class="field"><label for="telephone">Telefonnummer</label><input class="inputText" name="telephone" type="text" id="telephone" size="30" maxlength="50" value=""><div class="clear"></div></div><div class="field"><label for="message">Notiz</label><input class="inputText" name="message" type="text" id="message" size="30" maxlength="50" value=""><div class="clear"></div></div><div class="field submit"><input name="submit" type="submit" class="button" id="submit" value="Senden"><div class="clear"></div></div></form><div class="field"><p>Oder rufen Sie uns direkt an: <br>07123 956177-0</p></div><div id="callback"></div>');
			//show / hide function
			$('#callbutton').toggle(function() {

			$("#call").stop().animate({ right: 0 }, 'fast');
			$("#callbutton").addClass("active");
			},
		function(){
			$("#call").stop().animate({ right: -289 }, 'fast');
			$("#callbutton").removeClass("active");
			}
			);

				
			
			//validate the form 
			$("#contactForm").validate({
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					telephone: {
						required: true,
						minlength: 3
					},
					message: {
						required: true
					}
				},
				//set messages to appear inline
//					messages: {
//						name: "",
//						email: "",
//						comment: ""
//					},			
//
				submitHandler: function() {
					$('.field').hide();
//					$('#loading').show();
					$.post('mail.php',{subject:defaults.subject, name:$('#name').val(), telephone:$('#telephone').val(), message:$('#message').val()},
					function(data){
//						$('#loading').css({display:'none'}); 
						if( data == 'success') {
							$('#callback').show().append(defaults.recievedMsg);
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#call').animate({dummy:1}, 1500).animate({"right": "-=0"}, "slow");
								$('#call').animate({dummy:1}, 1500).animate({"right": "-=289px"}, "slow"); 
								$("#callbutton").removeClass("active");
							}
						} else {
							$('#callback').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
})(jQuery);


