// JavaScript Document

$(document).ready(function($){
	
/* ========== TWEETS =====  */	
        
	$(".tweet").tweet({
	  username: "morethnmindless",
	  count: 3,
	  loading_text: "loading tweets..."
	});
	
 
/* ========== OFFICAL TWITTER BTN =====  */


/* ========== To TOP =====  */
	$().UItoTop({ easingType: 'easeOutQuart' });



/* ========== FIXED NAVIGATION ===== */

    $(window).scroll(function(){
		
		//if scrolled down more than first amount of pixels.
        if ($(window).scrollTop() > 178){

			// if yes, add "fixed" class to the <nav>
			// add padding top to the #content (value is same as the height of the nav)
            $('#nav').addClass('fixed').addClass('fixed-nav').next().css('padding-top','60px');


        } else {
			
			// when scroll up or less than aboveHeight, remove the "fixed" class, and the padding-top
            $('#nav').removeClass('fixed').removeClass('fixed-nav').next().css('padding-top','0');
        }
    });
	
    $(window).load(function(){
        if ($(window).scrollTop() > 178){
            $('#nav').addClass('fixed').addClass('fixed-nav').next().css('padding-top','60px');
        } else {
            $('#nav').removeClass('fixed').removeClass('fixed-nav').next().css('padding-top','0');
        }
    });
	


/* ========== FORM HINTS  ===== */	
$('input.form-hint').each(function() {
$(this)
  .data('default', $(this).val())
  .addClass('inactive')
  .focus(function() {
	$(this).removeClass('inactive');
	if($(this).val() == $(this).data('default') || '') {
	  $(this).val('');
	}
  })
  .blur(function() {
	var default_val = $(this).data('default');
	if($(this).val() == '') {
	  $(this).addClass('inactive');
	  $(this).val($(this).data('default'));
	}
  });
});

/* ========== VALIDATOR  ===== */	

jQuery.extend(jQuery.validator.messages, {
    required: "This field is required.",
    email: "Not a valid email!",
});


jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Not a valid phone number!");

  $('form#contactMTM').validate({
    rules: {
      name:{
 		required: true
      },
      email: {
        required: true,
        email: true
      },
	  phone: {
 		required: true,
      	phoneUS: true	
      },
	  message: {
 		required: true
      }
    },
    success: function(label) {
      label.text('Perfect!').addClass('valid');
    }
  });

	 var RecaptchaOptions = {
		theme : 'blackglass'
	 };


}); /* ENDS line 12 */

