//ABHILASH R S  (for DWEST)
//extend the plugin
var togvar=0;

(function($){

	//define the new for the plugin ans how to call it	
	$.fn.contactable = function(options) {
		//set default options  
		var defaults = {
			name: 'Name',
			email: 'Email',
			message : 'Message',
			question: 'question',
			recipient : 'feedback@qiqima.com',
			subject : 'A contactable message',
			recievedMsg : 'Thank You for your Feedback!',
			notRecievedMsg : 'Thank You for your Feedback!'
			
		};

		//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="contactable"></div><form id="contactForm" method="" action=""><div id="contactable1" style="cursor:pointer;background:url(images/close.png);width:56px;height:20px;top:60px;float:right;" alt="close"></div><div id="loading"></div><div id="callback"></div><div class="holder"><input type="hidden" id="recipient" name="recipient" value="'+defaults.recipient+'" /><input type="hidden" id="subject" name="subject" value="'+defaults.subject+'" /><h2>Help Us improve</h2><p><label for="name">Name <span class="red"> * </span></label><br /><input id="name" class="contact" name="name" /></p><p><label for="email">E-Mail <span class="red"> * </span></label><br /><input id="email" class="contact" name="email" /></p><p><select name="question" id="question" class="contact"><option value="I have a suggestion">&nbsp;&nbsp;I have a Suggestion</option><option value="I have a Question">&nbsp;&nbsp;I have a Question</option><option value="Report a Technical Issue">&nbsp;&nbsp;Report a Technical Issue</option><option value="I like this">&nbsp;&nbsp;I like this</option></select></p><p><label for="comment">Your Feedback <span class="red"> * </span></label><br /><textarea id="comment" name="comment" class="comment" rows="4" cols="30" ></textarea></p><p><input class="submit" type="submit" value="Send"/></p><h2>Thanks for your feedback!</h2></div></form>');
			//show / hide function
			
			$('div#contactable').click(function(){
				if(togvar == 0){opent();togvar = 1;}
				else{closet();togvar=0;}
			});
			$('div#contactable1').click(function(){
				if(togvar == 0){opent();togvar = 1;}
				else{closet();togvar=0;}
			});
			function opent() {
				$('#overlay').css({display: 'block'});
				$('#contactable').animate({"marginLeft": "-=5px"}, "fast"); 
				$('#contactForm').animate({"marginLeft": "-=0px"}, "fast");
				$('#contactable').animate({"marginLeft": "+=387px"}, "slow"); 
				$('#contactForm').animate({"marginLeft": "+=390px"}, "slow"); 
			}
			
			function closet() {
				$('#overlay').css({display: 'block'});
				$('#contactable').animate({"marginLeft": "-=382px"}, "slow");
				$('#contactForm').animate({"marginLeft": "-=390px"}, "slow");
				 	
			}
			
			
			
			
			
			//validate the form 
			$("#contactForm").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: "",
					question:""
				},
				submitHandler: function() {
					$('.holder').hide();
					$('#loading').show();
					$.get('mail.php',{recipient:$('#recipient').val(), subject:$('#subject').val(), name:$('#name').val(), email:$('#email').val(), comment:$('#comment').val(),question:$('#question').val()},
					function(data){
						$('#loading').css({display:'none'}); 
						if( data == 'success') {
							$('#callback').show().append(defaults.recievedMsg);
						} else {
							$('#callback').show().append(defaults.notRecievedMsg);
						}
					});		
				}
			});
		});
	};
	//end the plugin call 
})(jQuery);


