/*
 * contactable 1.2 - 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 2009-09-24 $
 *
 */
 
//extend the plugin
(function($){

    //define the new for the plugin ans how to call it
    $.fn.contactable = function(options) {
        //set default options
        var defaults = {
            message : 'Message'
        };

        //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="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+'" /><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><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><p>'+defaults.disclaimer+'</p></div></form>');
            //show / hide function
            $('#contactable').toggle(function() {
				
                $(this).animate({
                    "marginRight": "-=5px"
                }, "fast");
                $('#contactForm').animate({
                    "marginRight": "-=0px"
                }, "fast");
                $(this).animate({
                    "marginRight": "+=387px"
                }, "slow");
                $('#contactForm').animate({
                    "marginRight": "+=390px"
                }, "slow");
            },
            function() {
                $('#contactForm').animate({
                    "marginRight": "-=390px"
                }, "slow");
                $(this).animate({
                    "marginRight": "-=387px"
                }, "slow").animate({
                    "marginRight": "+=5px"
                }, "fast");

                        
            });
			
            //validate the form
           var $contactForm = $("#contactForm");
            $contactForm.validate({
                //set the rules for the fild names
                rules: {
					
                    comment: {
                        required: true
                    },
                    subject: {
                        required: true
                    }
                },
			
                messages: {
					
                    subject: "Champ obligatoire",
                    comment: "Champ obligatoire"
                },
                submitHandler: function() {
                    $('.holder').hide();
                    $('#loading').show();
                    $contactForm.ajaxSubmit({
                        target: '#callback',
                        success:function(data){
                            $('#loading').css({
                                display:'none'
                            });
                            $('.holder').show();
                            $('#callback').show().html('<p>'+data+'</p>');
                            
                        }
                    });

            //$.post(feedbackUrl,{ subject:$('#subject').val(), comment:$('#comment').val()},
							
            }
            });
        });
};
//end the plugin call 
})(jQuery);

