$(document).ready(function(){
//--------tell a friend form controls and validation 

 $("#shareform").hide();   
 $("#response").hide();
 $("#tellafriend").validate({
	rules: {
		email: {
			required: true,
			email: true
		},
		toemail: {
		    required: true,
			email: true
	    },
		name:{ 
		    required:true,
		    minlength: 2
		},
		toname:{ 
		required:true,
		minlength: 2
		}
	},
messages: {
	email: "Please enter a valid email address",
	toemail: "Please enter a valid email address",
	name: "Please enter your name",
	toname: "Please enter the recievers name"
					},
submitHandler: function(form) {
   				var inputs = [];
                   $("#response").html("<p>Sending Form…</p>").show();
                   $('#tellafriend input').each(function(){
                      inputs.push(this.name + '=' + escape(this.value));
                   });

 					 $('#tellafriend textarea').each(function(){

                        inputs.push(this.name + '=' + escape(this.value));
                    });
                   $.ajax({
                       data: inputs.join('&'),
				       dataType:"html", 
                       url: "/_inc/tellform.php",
                       timeout: 3000,

                       error: function(){
                         $('#response').html("<strong>Err: Email Not Sent Try Again Later</strong>");   
                       },
                       success: function(){
                         $("#response").html();
                       }
                   });
          //return false;
		}
  });

$("#share .invite").tooltip({ 
	    // change trigger opacity slowly to 0.8
	 	tip: '#shareform',
		delay: .05,
		offset:[0,-122],
        relative:true,
		position: ['top','right'],
		effect: 'fade',
		opacity: 1,

		onHide: function(){
		   $("#share #response").html("").hide();
		} 

	});

});
