var jx=jQuery.noConflict();
jx(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		if (jx("#contactForm").is(":hidden")){
			jx("#contactForm").slideDown("slow");
			jx("#backgroundPopup").css({"opacity": "0.7"});
			jx("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			jx("#contactForm").slideUp("slow");
			jx("#backgroundPopup").fadeOut("slow");  
		}
	}
	 
	//run contact form when any contact link is clicked
	jx(".contact").click(function(){contact()});
	
	//animation for same page links #
	jx('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var jxtargetId = jx(this.hash), jxtargetAnchor = jx('[name=' + this.hash.slice(1) +']');
		  var jxtarget = jxtargetId.length ? jxtargetId : jxtargetAnchor.length ? jxtargetAnchor : false;
			if (jx(this.hash).length) {
				jx(this).click(function(event) {
					var targetOffset = jx(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					jx('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});



   //submission scripts
  jx('.contactForm').submit( function(){
		//statements to validate the form	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emails = document.getElementById('e-mail');
		if (!filter.test(emails.value)) {
			jx('.email-missing').show();
		} else {jx('.email-missing').hide();}
		if (document.cform.name.value == "") {
			jx('.name-missing').show();
		} else {jx('.name-missing').hide();}	
		if (document.cform.message.value == "") {
			jx('.message-missing').show();
		} else {jx('.message-missing').hide();}		
		if ((document.cform.name.value == "") || (!filter.test(emails.value)) || (document.cform.message.value == "")){
			return false;
		} 
		
		if ((document.cform.name.value != "") && (filter.test(emails.value)) && (document.cform.message.value != "")) {
			//hide the form
			jx('.contactForm').hide();
		
			//show the loading bar
			jx('.loader').append(jx('.bar'));
			jx('.bar').css({display:'block'});
		
			//send the ajax request
			jx.post('mail.php',{name:jx('#name').val(),
							  emails:jx('#e-mail').val(),
							  message:jx('#message').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  jx('.bar').css({display:'none'});
			  jx('.loader').append(data);
			});
			
			//waits 2000, then closes the form and fades out
			setTimeout('jx("#backgroundPopup").fadeOut("slow"); jx("#contactForm").slideUp("slow")', 2000);
			
			//stay on the page
			return false;
		} 
  });
	//only need force for IE6  
	jx("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  
});
