        $(function(){
	    $('#mailOverlay').css({opacity: .7});
            $('#openForm').click(function(){
                $('#mailOverlay, #forms').fadeIn();
	 
		$('.submit').click(function(){
		    $('input[type="text"]').css({'background-color': '#fff'});
		    $('#errors').empty();
		   mail($(this));
		   return false;  
		});
		
		$('input').focus(function(){
		    $(this).css({'background-color': '#fff'});    
		});
            });
            $('#close').click(function(){
                $('#mailOverlay, #forms').fadeOut('fast');
            });
            
	    $('#topNav').css({opacity: .6}).hover(function(){
		$(this).stop().animate({opacity: 1},500);
	    },function(){
		$(this).stop().animate({opacity: .6},100);
	    });
   
    });
	
	
	$.getScript('js/tweet.js', function(){
	    $(".tweet").tweet({
	       username: "NetsmartSystems",
	       join_text: "auto",
	       avatar_size: 32,
	       count: 2,
	       auto_join_text_default: "", 
	       auto_join_text_ed: "",
	       auto_join_text_ing: "",
	       auto_join_text_reply: "",
	       auto_join_text_url: "",
	       loading_text: "loading tweets..."
	   });
	 });
	
	function mail(x){
	    var ele = x.parent('li').parent('ul'),
	      fName = ele.find('#fName'),
	      lName = ele.find('#lName'),
	      bName = ele.find('#bName'),
	      ema = ele.find('#email'),
	      pho = ele.find('#phone'),
	      com = $('#comments'),
	      firstName = fName.val(),
	      lastName = lName.val(),
	      businessName = bName.val(),
	      email = ema.val(),
	      phone = pho.val(),
	      comments = com.val(),
	      type =ele.find('#type').val(),
	      data = '&fname='+firstName+'&lname='+lastName+'&bname='+businessName+'&email='+email+'&phone='+phone+'&comments='+comments+'&type='+type,
	      errors = [''];
		    //checking the data
		 if(firstName == ''){
		    fName.css({'background-color': '#cc0000'});
			     errors.push('..');
		 }
		     
		     if(lastName == ''){
		    lName.css({'background-color': '#cc0000'});
			     errors.push('..');
		 }
		     
		      if(businessName == ''){
		    bName.css({'background-color': '#cc0000'});
			     errors.push('..');
		 }
		     
		      if(phone == ''){
		    pho.css({'background-color': '#cc0000'});
			     errors.push('..');
		 }else{
		    numbers = phone.split('');  
		    if(numbers.length < 7){
		       pho.css({'background-color': '#cc0000'});
			errors.push('..');
		    }else if(/[qwertyuiopasdfghjklzxcvbnm]/.test(phone)){
			pho.css({'background-color': '#cc0000'});
			errors.push('..');
			
		    }
		 }
		    
		 if(email == ' '){
		    ema.css({'background-color': '#cc0000'});
			     errors.push('..');
		 }else{
		    at = email.split('@');  
		    if(at.length < 2){
		       ema.css({'background-color': '#cc0000'});
				   errors.push('..');
		    }else{
		       dot = at['1'].split('.');
		       if(dot.length < 2){
			  ema.css({'background-color': '#cc0000'});
					   errors.push('..');
		       }
		    }
		 }
		 
		    
		 
		    
		 if(errors.length>1){
			     $('#errors').html('Please fill out Required Feilds');
		    return false;
		 }
	   
		 $.ajax({
		    type: 'POST',
		    url: 'mail.php',
		    data: data,
		    success: function(data){
		       $('input[type="text"], textarea').val('');
		       $('#results').css({opacity: 0}).html('<center>'+firstName+' '+lastName+', Thanks for Inquiring</center>').animate({opacity: 1},100);
		       $('#errors').empty();
		       setTimeout(function(){
			  $('#forms, #mailOverlay').fadeOut('slow');   
		       },2000)
		    }
		 });
		 return true;
	   }

