/*
This little group of scripts just sets a default
value for the quick search and the newsletter sign-ups.
*/
jQuery(document).ready(function($) {
	
	/* ~~~~~~~~~~~~ | search box form default settings | ~~~~~~~~~~~~ */
	$('#bx_search #s').focus(function() {
		if ($(this).val() == 'Search...') {$(this).val('');}
	});
	$('#bx_search #s').blur(function() {
		if ($(this).val() == '') {$(this).val('Search...');}
	});
	
	
	
	/* ~~~~~~~~~~~~ | newsletter signup default settings | ~~~~~~~~~~~~ */
	
	// first name
	$('#upd_first_name').focus(function() {
		if ($(this).val() == 'First Name') {$(this).val('');}
	});
	$('#upd_first_name').blur(function() {
		if ($(this).val() == '') {$(this).val('First Name');}
	});
	
	// last name
	$('#upd_last_name').focus(function() {
		if ($(this).val() == 'Last Name') {$(this).val('');}
	});
	$('#upd_last_name').blur(function() {
		if ($(this).val() == '') {$(this).val('Last Name');}
	});
	
	// email
	$('#upd_email').focus(function() {
		if ($(this).val() == 'Email') {$(this).val('');}
	});
	$('#upd_email').blur(function() {
		if ($(this).val() == '') {$(this).val('Email');}
	});
	
	
	
	/* ~~~~~~~~~~~~ | newsletter signup ajax | ~~~~~~~~~~~~ */
	
	$('#sb_newsletter_signup, #hm_newsletter_signup').submit(function() {
		
		$.ajax({
			url: "/wp-content/themes/twc_custom/signup/index.php",
			data: {
				'FirstName': 	$('#upd_first_name').val(),
				'LastName': 	$('#upd_last_name').val(),
				'EmailAddress': $('#upd_email').val()
			},
			type: "POST",
  			context: $(this),
  			success: function(data){
  				if (data == 'success') {
  					str = '<p class="response">\
  								Thank you for signing up. We have you on\
  								our e-newsletter list and look forward to\
  								staying in touch with you.</p>';
  				} else if (data == 'subscriber') {
  					str = '<p class="response">\
  								You are already subscribed to our newsletter.\
  							</p>';
  				} else {
  					str = '<p style="padding:10px;text-align:center;color:#f00;font-weight:bold;">\
  								Something seems to have gone wrong.\
  								Please try again.\
  							</p>';
  				}
    			$(this).html(str);
  			}
		});
		
		return false;
	});
	
});
