/*
 * 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.contactableRight = function(options) {
		//set default options  
		var defaults = {
			name: 'Nom',
			email: 'Email',
			message : 'Message',
			subject : 'A contactable message',
			recievedMsg : 'Merci pour votre message !',
			notRecievedMsg : 'D&eacute;sol&eacute;, votre message n\'a pu &ecirc;tre transmis, r&eacute;essayez dans quelques minutes',
			disclaimer: '',
			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="contactableb"></div><form id="contactFormb" method="" action=""><div id="loadingb"></div><div id="callbackb"></div><div class="holderb"><p class="contactable_title"><img src="/img/fleche_orange.png" alt="-" class="fleche" />Assistance &agrave; distance</p><p class="contactable_min"><em>Cliquez sur la capture ci-dessous pour lancer l\'application d\'assistance &agrave; distance</em></p><p class="contactable"><a href="http://www.humantocomputer.com/Assistance.exe"><img src="/img/help_desk_screen.jpg" alt="Assistance &agrave; distance" title="D&eacute;marrer l\'assistance &agrave; distance" width="250px" style="margin:10px 25px 10px 25px;"></a></p><p class="disclaimer">'+defaults.disclaimer+'</p></div></form>');
			//show / hide function
			$('div#contactableb').toggle(function() {
				$('#overlayb').css({display: 'block'});
				$(this).animate({"marginRight": "-=5px"}, "fast"); 
				$('#contactFormb').animate({"marginRight": "-=0px"}, "fast");
				$(this).animate({"marginRight": "+=387px"}, "slow"); 
				$('#contactFormb').animate({"marginRight": "+=390px"}, "slow"); 
			}, 
			function() {
				$('#contactFormb').animate({"marginRight": "-=390px"}, "slow");
				$(this).animate({"marginRight": "-=387px"}, "slow").animate({"marginRight": "+=5px"}, "fast"); 
				$('#overlayb').css({display: 'none'});
			});
			
			//validate the form 
			$("#contactFormb").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() {
					$('.holder').hide();
					$('#loadingb').show();
					$.post('mail_feedback.php',{subject:defaults.subject, name:$('#name').val(), email:$('#email').val(), comment:$('#comment').val()},
					function(data){
						$('#loadingb').css({display:'none'}); 
						if( data == 'success') {
							$('#callbackb').show().append(defaults.recievedMsg);
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
								$('#contactFormb').animate({dummy:1}, 2000).animate({"marginRight": "-=450px"}, "slow");
								$('div#contactableb').animate({dummy:1}, 2000).animate({"marginRight": "-=447px"}, "slow").animate({"marginRight": "+=5px"}, "fast"); 
								$('#overlayb').css({display: 'none'});	
							}
						} else {
							$('#callbackb').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
})(jQuery);


