
$(document).ready(function() {

	$(".twitter-area").tweet({
		username: "team_wendy",
		count : 3
	});
	$(".page_item > a").attr('title','');
	$('ul.children li:last-child').addClass('rm_bg'); // Determines last li class and removes its background
	
	$(".tweet_text a").live('click', function(){
		$(this).attr('target','_blank');
	});
	
	$(".military-products-subnav").find('a').each(function(){
		var link = $(this).attr('href');
		$(this).attr('href',link + '#resources-content');
	});
	
	var activeLi;
	if($("#top-nav-ul").find('li.current-page-ancestor').length) {
		activeLi = $("#top-nav-ul").find('li.current-page-ancestor');
	}
	if($("#top-nav-ul").find('li.current_page_parent').length) {
		activeLi = $("#top-nav-ul").find('li.current_page_parent');
	}
			

	$("#top-nav-ul > li").hover(function() {
		if ($(this).attr('id') == $(activeLi).attr('id')) {
			$(this).css('display', 'block');
		} else {
			$(this).find('.child-holder1').fadeIn('100');
			$(activeLi).find('.child-holder1').fadeOut('50');
		}	
	}, function() {
		if ($(this).attr('id') == $(activeLi).attr('id')) {
			$(this).css('display', 'block');
		} else {
			$(this).find('.child-holder1').fadeOut('50');
		}
	});
	
	// When the mouse is no longer hovering over the navigation tab
	$('.subpage-banner-holder').mouseenter(function() { $(activeLi).find('.child-holder1').css('display', 'block');});
	$('.main-holder').mouseenter(function() { $(activeLi).find('.child-holder1').css('display', 'block');});
	
  var default_values = new Array();
  var sent = false;
  var errors = false;
  $("input.text").focus(function() {
  	$(this).css({'color':'#D5D5D5'});
    if(!default_values[this.id]){
      default_values[this.id] = this.value;
    }
    if(this.value == default_values[this.id]){
      this.value = '';
    }
    $(this).blur(function(){
      if (this.value == ''){
        this.value = default_values[this.id];
      }
    });
  });
  
  
  $(".btn-submit").click(function(){
  	
  	errors = false;
	if(sent == false){
		
		var name = $(".contact-form #name").val();
		var phone = $(".contact-form #phone").val();
		var email = $(".contact-form #email").val();
		var msg = $(".contact-form #message").val();
		var rege = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if(name == ''){
			$(".contact-form #name").css({'color':'red'}).val('*Please enter your name');
			errors = true;
		}
		if(phone == ''){
			$(".contact-form #phone").css({'color':'red'}).val('*Please enter your phone number');
			errors = true;
		}
		if(!rege.test($(".contact-form #email").val()) || $(email) == ''){
			$(".contact-form #email").css({'color':'red'}).val('*Please enter a valid email address');
			errors = true;
		}
		
		if(errors == false){
			$('.row-btn #loader').fadeIn('fast');
			$('.row-btn p').fadeOut('fast').empty();
			$.post('/wp-content/themes/TeamWendy2/mailer.php', 
				{name : name, phone : phone, email : email, message : msg}, function(){
					$('.row-btn #loader').fadeOut('fast');
					$('.contact-form').fadeOut('slow');
					$('.row-btn p').text('Thank you! A Team Wendy representative will contact you shortly').fadeIn('fast');
					sent = true;
			});
		}
	}
	
	else{
		$('.row-btn #response').text('The form has already been submitted.');
	}
  	
  	return false
	
  });
  
});



