// JavaScript Document


$(document).ready(function() {
	$("#nav ul").hide();
	
						
	$("#nav_about").mouseenter(function(){
		$("#nav_about ul").show();
		$("#nav_about .nav_link").addClass('blue');
	});
	
	$("#nav_about").mouseleave(function(){
		$("#nav_about ul").hide();
		$("#nav_about .nav_link").removeClass('blue');
	});
	
	
	$("#nav_consulting").mouseenter(function(){
		$("#nav_consulting ul").show();
		$("#nav_consulting .nav_link").addClass('blue');
	});
	
	$("#nav_consulting").mouseleave(function(){
		$("#nav_consulting ul").hide();
		$("#nav_consulting .nav_link").removeClass('blue');
	});
	
	$("#nav_industries").mouseenter(function(){
		$("#nav_industries ul").show();
		$("#nav_industries .nav_link").addClass('blue');
	});
	
	$("#nav_industries").mouseleave(function(){
		$("#nav_industries ul").hide();
		$("#nav_industries .nav_link").removeClass('blue');
	});
	
	
	
	$("#leadership_nicola_info").hide();
	$("#leadership_ronald_info").hide();
	$("#leadership_thomas_info").hide();
	$("#main_other_wrapper").hide();
	$("div.error").hide();
	
	$("#leadership_thomas").click(function(){
		$("#leadership_thomas_info").toggle("slow");
		return false;
	});
	
	$("#leadership_ronald").click(function(){
		$("#leadership_ronald_info").toggle("slow");
		return false;
	});
	
	$("#leadership_nicola").click(function(){
		$("#leadership_nicola_info").toggle("slow");
		return false;
	});
	
/*	
	$('a[href*=/]').each(function() {
		var the_id = "";
		var the_class = "";						  
			if($(this).attr("id") != "logo"){
				if($(this).attr("id").length > 0){
					the_id = "id= '" + $(this).attr("id") + "' ";
				}
				if($(this).attr("class").length > 0){
					the_class = "class='" + $(this).attr("class") + "' ";
				}
				var a = $(this).attr("href");
				$(this).replaceWith("<a href='/dev" + a + "' " + the_id + the_class + ">" + $(this).text() + "</a>");
			}
	});
	
*/
	
	jQuery.validator.messages.phoneUS = "";
	jQuery.validator.messages.email = "";
	jQuery.validator.messages.required = "";
	
	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}$/);
	}, "");

	
	if($("#main_contact_form").length > 0){
		$("#main_contact_form").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted above'
					: 'You missed ' + errors + ' fields.  They have been highlighted above';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
		});
	}
	
	
	
	$("#mini_name").focus(function(){
		if($("#mini_name").val() == "name"){
			$("#mini_name").val("");	
		}
	});
	
	$("#mini_phone").focus(function(){
		if($("#mini_phone").val() == "phone"){
			$("#mini_phone").val("");	
		}
	});
	
	$("#mini_email").focus(function(){
		if($("#mini_email").val() == "e-mail"){
			$("#mini_email").val("");	
		}
	});
	
	$("#mini_question").focus(function(){
		if($("#mini_question").val() == "How can we help you?"){
			$("#mini_question").val("");	
		}
	});
	
	$("#mini_name").blur(function(){
		if($("#mini_name").val() == ""){
			$("#mini_name").val("name");	
		}
	});
	
	$("#mini_phone").blur(function(){
		if($("#mini_phone").val() == ""){
			$("#mini_phone").val("phone");	
		}
	});
	
	$("#mini_email").blur(function(){
		if($("#mini_email").val() == ""){
			$("#mini_email").val("e-mail");	
		}
	});
	
	$("#mini_question").blur(function(){
		if($("#mini_question").val() == ""){
			$("#mini_question").val("How can we help you?");	
		}
	});
		
	$("#referral").change(function(){
		var the_strng = $('#referral').val();
		
		
		if (the_strng == "other" || the_strng == "colleague,other" || the_strng == "Web search,other" || the_strng == "media,other" || the_strng == "customer,other" || the_strng == "advertising,other" || the_strng == "colleague,Web search,other" || the_strng == "Web search,media,other" || the_strng == "media,customer,other" || the_strng == "customer,advertising,other" || the_strng == "colleague,Web search,media,other" || the_strng == "colleague,Web search,media,customer,other" || the_strng == "colleague,Web search,media,customer,advertising,other" || the_strng == "Web search,media,customer,advertising,other" ||
			the_strng == "media,customer,advertising,other" || the_strng == "colleague,media,customer,advertising,other" || the_strng == "colleague,media,customer,other" || the_strng == "Web search,media,advertising,other") {
			$("#main_other_wrapper").show();
		}
		else
		{
			$("#main_other_wrapper").hide();
		}
		
		
	});
	
	if($("#contact_mini").length >0){
		$("#contact_mini").validate();
	}
	
	
		
	
	
	
	

	
	
	
});

