$(document).ready(function(){
	//function for contact form dropdown
	function candidate() {
		if ($("#candidateForm").is(":hidden")){
			$('.loader').hide(); 
			$('.complete').hide();
			$('.contactForm').show();
			$("#candidateForm").slideDown("slow");
			$("#backgroundPopup").css({"opacity": "0.7"});
			$("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			$("#candidateForm").slideUp("slow");
			$("#backgroundPopup").fadeOut("slow");  
		}
	}
	function firm() {
		if ($("#firmForm").is(":hidden")){
			$('.loader').hide(); 
			$('.complete').hide();
			$('.contactForm').show();
			$("#firmForm").slideDown("slow");
			$("#backgroundPopup").css({"opacity": "0.7"});
			$("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			$("#firmForm").slideUp("slow");
			$("#backgroundPopup").fadeOut("slow");  
		}
	}	
	 
	//run contact form when any contact link is clicked
	$(".candidate").click(function(){ candidate(); return false;});
	$(".firm").click(function(){firm(); return false;});

	$("#candidateForm .close").click(function(){
				$("#candidateForm").slideUp("slow");
				$("#backgroundPopup").fadeOut("slow");  
				return false;
	});
	$("#firmForm .close").click(function(){			
				$("#firmForm").slideUp("slow");
				$("#backgroundPopup").fadeOut("slow");  
				return false;
	});
	
	//animation for same page links #
	$('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		  var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($(this.hash).length) {
				$(this).click(function(event) {
					var targetOffset = $(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					$('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});


	//pop up submission	
	var options = { 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:       showResponse  // post-submit callback 
	}; 

	$('.contactForm').submit(function() { 
		$(this).ajaxSubmit(options); 
		return false; 
	}); 

	// pre-submit callback 
	function showRequest(formData, jqForm, options) {
	    $('.contactForm').hide();
	    $('.loader').show();
	    var queryString = $.param(formData); 
	    return true; 
	} 

	// post-submit callback 
	function showResponse(responseText, statusText, xhr, $form)  {
	    $('.loader').hide(); 
	    $('.complete').show();
	    setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#candidateForm").slideUp("slow")', 2000); 
	}  				

	//only need force for IE6  
	$("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  
});
