function handle_client_login() {
	var clientID = jQuery('#clientID').val().replace(/ /g, '-');
	if (clientID.length == 0 || clientID === "Enter-Client-ID") {
		alert("Please enter your client ID and click Submit.");
		return false;
	}
	window.location = "http://clients.pixelmack.com/"+clientID;
}

function adjust_feature_nav() {
	// called after slider init on page view
	// ensures horizontal bar is present when needed
	if ( jQuery("#portfolio-return").length != 0 && jQuery("ol#slider-numeric-controls").length == 0 ) {
		jQuery("#feature").append("<ol id=\"slider-numeric-controls\"></ol>");
	}
}

jQuery(document).ready(function($) {
	
	// store "true" header height and hide subnav
	var h = $('#header').height();
	$('#header-container').height('48px');
	
	// even out nav item heights
	$('#nav > li').each(function() {
		$(this).height( (h-20)+'px' );
		if ($.browser.msie && parseInt($.browser.version) <= 7) {
			$(this).height( h +'px' );
		}
	});
	
	// set up nav behavior
	$('#nav li').hover( function() {
		$('#header-container').animate( { 'height' : h+'px' }, { queue:false, duration:300 } );
		
	}, function() {
		if ( ! $(this).parent().is('.subnav') ) {
			$('#header-container').animate( { 'height' : '48px' }, { queue:false, duration:300 } );
		}
		
	});
	
	// client login form
	$('#client-login-form-submit').click(function() {
		handle_client_login();
	});
	$('#client-login-form').submit(function() {
		handle_client_login();
		return false;
	});
	$('#clientID').val('Enter Client ID');
	$('#clientID').addClass('label');
	$('#clientID').focus(function() {
		if ($(this).val() === 'Enter Client ID') {
			//clear label
			$(this).val('');
			$('#clientID').removeClass('label');
		}
	}).blur(function() {
		if ($(this).val() === '') {
			//add label
			$(this).val('Enter Client ID');
			$('#clientID').addClass('label');
		}
	});
	
	// prevent blank search
	$('#searchform').submit(function() {
		if ($('#s').val().length == 0) {
			alert("Please enter a search term and click Search.");
			return false;
		}
	});
	
	// hover effect on grid view
	$('.thumbnail-container img').each(function() {
		$(this).css("opacity", 0.75);
	});
	$('.thumbnail-container img').hover(function() {
		$(this).animate( { opacity : 1.0 }, { queue:false, duration:200 } );
	}, function() {
		$(this).animate( { opacity : 0.75 }, { queue:false, duration:200 } );
	});
	
	
		
	//////////////////////////////////////
	// contact form
	//////////////////////////////////////
	var themeDirectory = "/wp-content/themes/pixelmack"; // CONFIG
	
	// contact form submit handler
	$("#contactFormSubmitButton").click(function() {
		var name = $("input#contact_name").val();
		var email = $("input#contact_email").val();
		var company = $("input#contact_company").val();
		var url = $("input#contact_url").val();
		var phone = $("input#contact_phone").val();
		var message = $("textarea#contact_message").val();
		
		// validate form
		if ($.trim(name).length == 0) {
			alert("Please enter your name.");
			$("input#contact_name").focus();
			return false;
		}
		if ($.trim(email).length == 0) {
			alert("Please enter your email address.");
			$("input#contact_email").focus();
			return false;
		}
		if ($.trim(message).length == 0) {
			alert("Please enter the message you wish to send.");
			$("input#contact_message").focus();
			return false;
		}
		
		// display loading indicator
		$("#contactFormSubmitButton").hide();
		$("#contactForm").append("<p class='pleaseWait'>Please wait. <img src='" + themeDirectory + "/images/ajax-loader.gif' /></p>");
		
		var dataString = 'name=' + encodeURIComponent(name) + '&email=' + encodeURIComponent(email) + '&company=' + encodeURIComponent(company) + '&url=' + encodeURIComponent(url) + '&phone=' + encodeURIComponent(phone) + "&message=" + encodeURIComponent(message);
				
		$.ajax({
			type: "POST",
			url: themeDirectory + "/mailer/processContactForm.php",
			data: dataString,
			success: function(data) {
				if (data === 'SUCCESS') {
					$('#contactForm').html("<div class='resultMessage'><p><b>Contact Form Submitted!</b></p><p>Thanks. We will be in touch soon.</p></div>");
				} else {
					if ($(".resultMessage").length == 0) {
						$('#contactForm').prepend("<div class='resultMessage'><p><span class='red-text'>Your message could not be sent.</span></p><p>Please email us directly at <a href='mailto:info@pixelmack.com'>info@pixelmack.com</a>.</p></div>");
					}
					$(".pleaseWait").remove();
					$("#contactFormSubmitButton").show();
				}
			}
		});
		return false;
	});
	
	
}); // end document.ready

