$(document).ready(function(){
	//function for contact form dropdown
	function contact() {
		var arrow_ud1 = document.getElementById('arrow_ud1');
		var arrow_ud2 = document.getElementById('arrow_ud2');
		if ($("#contactForm").is(":hidden"))
		{
			$("#contactForm").slideDown("slow");
			arrow_ud1.innerHTML="<img src='newsletter/images/bullet_arrow_up.png' align='absmiddle' />";
			arrow_ud2.innerHTML="<img src='newsletter/images/bullet_arrow_up.png' align='absmiddle' />";
		}
		else
		{
			$("#contactForm").slideUp("slow");
			arrow_ud1.innerHTML="<img src='newsletter/images/bullet_arrow_down.png' align='absmiddle' />";
			arrow_ud2.innerHTML="<img src='newsletter/images/bullet_arrow_down.png' align='absmiddle' />";
		}
	}
	 
	//run contact form when any contact link is clicked
	$(".contact").click(function(){contact()});
	
	//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;
				});
			}
		}
	});



   //submission scripts
  $('.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 email = document.getElementById('e-mail');
		var arrow_ud1 = document.getElementById('arrow_ud1');
		var arrow_ud2 = document.getElementById('arrow_ud2');
		
		var register_from = document.getElementById('register_from');
		if (!filter.test(email.value)) 
		{
			$('.email-missing').show();
			$('.email').css({border:'1px solid #F00'});
		} 
		else 
		{
			$('.email-missing').hide();
		}
			
		if (!filter.test(email.value)){
			return false;
		} 
		
		if (filter.test(email.value)) {
			//hide the form
			$('.contactForm').hide();
		
			//show the loading bar
			$('.loader').append($('.bar'));
			$('.bar').css({display:'block'});
		
			//send the ajax request
			$.post('newsletter/mail_process.asp',{email:$('#e-mail').val(),register_from:$('#register_from').val()},
		
			//return the data
			function(data){
			  //hide the graphic
			  $('.bar').css({display:'none'});
			  $('.loader').append(data);
			});
			
			//waits 2000, then closes the form and fades out			
			setTimeout('$("#contactForm").slideUp("slow")', 4000);
			arrow_ud1.innerHTML="<img src='newsletter/images/bullet_arrow_down.png' align='absmiddle' />";
			arrow_ud2.innerHTML="<img src='newsletter/images/bullet_arrow_down.png' align='absmiddle' />";
			//stay on the page
			return false;
		} 
  });
	//only need force for IE6  
	$("#wallpaper").css({  
		"height": document.documentElement.clientHeight 
	});  
});