$(function(evt) {

    Cufon.replace('h2,h3,h4,h5,h6');
	
	$("a.new-window").live("click", function(evt) { window.open($(this).attr("href")); return false; });
	
	$("#header .nav li.nav-level-1-item").mouseenter(function(evt) {
		
		var $navItem = $(this);
		$navItem.children(".nav-level-1-link").addClass("nav-level-1-link-hover");
		$navItem.children("ul").show();
				
	}).mouseleave(function(evt) {
		
		var $navItem = $(this);
		$navItem.children(".nav-level-1-link").removeClass("nav-level-1-link-hover");
		$navItem.children("ul").hide();
		
	});
	
	$(".panel-wrap").each(function(evt) {
		
		var $wrapper = $(this);
		var $panels = $wrapper.find(".panels>.panel");
		var $links = $wrapper.find(".panel-links");
		
		$panels.hide().find(".panel-title").hide();
		
		//$links.find("li:eq(0)>a").addClass("active");
		
	});
	
	$(".cross-link").click(function(evt) {
		
		var $link = $(this);
		var $panel = $($link.attr("href"));
		
		if ($panel.size() == 1) {
			
			$panel.siblings(".active").removeClass("active").hide();
			$panel.show().addClass("active");
			
			$link.parent().parent(".panel-links").find("a.active").removeClass("active");
			$link.addClass("active");
			
		}
		
		return false;
		
	});
	
	$(".panel-links .cross-link:eq(0)").click();
	
	$(".watermark").watermark();
	$(".form-grid input[type=text]").textbox();
	$(".form-grid select").select();
	
	$("#candidate-fields, #client-fields").hide();
	
	$(".form-grid #_selType").change(function(evt) {
		
		var $sel = $(this);
		
		switch($sel.val()) {
			
			case "Candidate":
				$("#candidate-fields").show();
				$("#client-fields").hide();
				break;
			case "Client":
				$("#candidate-fields").hide();
				$("#client-fields").show();
				break;
			default:
				$("#candidate-fields, #client-fields").hide();
				break;
			
		}
		
	});
	
	$("form#form-contact-us").submit(function(evt) {
	
	    var emailtest = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	    var phonetest = /^[0-9]{3}.*[0-9]{3}.*[0-9]{4}$/;
	    
	    var $txtName = $("#_txtName");
	    var $txtPhone = $("#_txtPhone");
	    var $txtEmail = $("#_txtEmail");
	    var $selType = $("#_selType");
	    var $txtCompany = $("#_txtCompany");
	    var $txtSkillArea = $("#_txtSkillArea");
	    var $txtSkillLevel = $("#_txtSkillLevel");
	    
	    var type = $selType.val();
	    
	    if ($txtName.val().length < 2) {
	        alert("A name is required");
	        $txtName.focus();
	        return false;
	    } else if ($txtPhone.val().length > 0 && !phonetest.test($txtPhone.val())) {
	        alert("A valid phone number is required.");
	        $txtPhone.focus();
	        return false;
	    } else if (!emailtest.test($txtEmail.val())) {
	        alert("A valid email address is required.");
	        $txtEmail.focus();
	        return false;
	    } else if ($selType.val() == "") {
	        alert("Please selected whether you are a client or candidate.");
	        $selType.focus();
	        return false;
	    } else if (type == "Client" && $txtCompany.val().length < 2) {
	        alert("A company name is required.");
	        $txtCompany.focus();
	        return false;
	    } else if (type == "Candidate" && $txtSkillArea.val().length < 2) {
	        alert("Please specify your area of skill.");
	        $txtSkillArea.focus();
	        return false;
	    } else if (type == "Candidate" && ($txtSkillLevel.val().length < 2 || isNaN($txtSkillLevel.val()))) {
	        alert("Please specify your skill level in years.");
	        $txtSkillLevel.focus();
	        return false;
	    }
	
	});
	
});