/*
 * 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 $
 *
 */
 
$("#contact2").html('<div id="contactable2"></div><form id="contactForm2" method="" action=""><div id="loading2"></div><div id="callback2"></div><div class="holder2"><p class="facebook"><a href="http://facebook.com/pages/The-Lollipop-Bakery/131198486900790?ref=mf" target="_blank">Facebook</a></p><p class="twitter"><a href="http://twitter.com/lollipopbakery" target="_blank">Twitter</a></p><p class="blank"><a href="http://t.sina.com.cn/lollipopbakery" target="_blank">Weibo</a></p></div></form>'); 
 
//extend the plugin
(function($){

	//define the new for the plugin ans how to call it	
	$.fn.contactable2 = function(options) {
		//set default options  
		var defaults = {
			name: 'Name',
			email: 'Email',
			message : 'Message',
			subject : 'A contactable message',
			recievedMsg : 'Thank you for your message',
			notRecievedMsg : 'Sorry but your message could not be sent, try again later',
			disclaimer: 'Thank you for subscribing, we will get back to you soon',
			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="contactable2"></div><form id="contactForm2" method="" action=""><div id="loading2"></div><div id="callback2"></div><div class="holder2"><p class="facebook"><a href="http://facebook.com/pages/The-Lollipop-Bakery/131198486900790?ref=mf" target="_blank">Facebook</a></p><p class="twitter"><a href="http://twitter.com/lollipopbakery" target="_blank">Twitter</a></p><p class="blank"><a href="http://t.sina.com.cn/lollipopbakery" target="_blank">Weibo</a></p></div></form>');
			//show / hide function
				
				
				$('div#contact2').live('mouseenter',function () {
				    //$('#overlay2').css({display: 'block'});
					$('#contactable2').stop().animate({'marginLeft':'230px'},200);
					$('#contactForm2').stop().animate({"marginLeft": "-30px"}, 200); 
				}).live('mouseleave',function () {
				    //$('#overlay2').css({display: 'none'});
					$('#contactForm2').stop().animate({"marginLeft": "-250px"}, 200);
					$('#contactable2').stop().animate({'marginLeft':'0px'},200);
				});
				
				
			
			//validate the form 
			$("#contactForm2").validate({
				//set the rules for the fild names
				rules: {
					name: {
						required: true,
						minlength: 2
					},
					email: {
						required: true,
						email: true
					},
					comment: {
						required: true
					}
				},
				//set messages to appear inline
					messages: {
						name: "",
						email: "",
						comment: ""
					},			

				submitHandler: function() {
					$('.holder2').hide();
					$('#loading2').show();
					$.post('mail.php',{subject:defaults.subject, name:$('#name').val(), email:$('#email').val(), comment:$('#comment').val()},
					function(data){
						$('#loading2').css({display:'none'}); 
						if( data == 'success') {
							$('#callback2').show().append(defaults.recievedMsg);
							$('#callback2').html('<p>Thank you for your subscribing to our mailing list. We will contact you soon.</p><p><h4>Follow us at:</h4></p><p class="facebook"><a href="http://facebook.com/pages/The-Lollipop-Bakery/131198486900790?ref=mf" target="_blank">Facebook</a></p><p class="twitter"><a href="http://twitter.com/lollipopbakery" target="_blank">Twitter</a></p>');
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#contactForm2').animate({dummy:1}, 2000).animate({"marginLeft": "-=450px"}, "slow");
								$('div#contactable2').animate({dummy:1}, 2000).animate({"marginLeft": "-=447px"}, "slow").animate({"marginLeft": "+=5px"}, "fast"); 
								$('#overlay2').css({display: 'none'});	
							}
						} else {
							$('#callback2').show().append(defaults.notRecievedMsg);
							$('#callback2').html('<p>Sorry but your message could not be sent, please try again later.</p><p><h4>Follow us at:</h4></p><p class="facebook"><a href="http://facebook.com/pages/The-Lollipop-Bakery/131198486900790?ref=mf" target="_blank">Facebook</a></p><p class="twitter"><a href="http://twitter.com/lollipopbakery" target="_blank">Twitter</a></p>');
						}
					});		
				}
			});
		});
	};
})(jQuery);


