$(document).ready(function(){
	// reveal bottom text
	var pageHeight = $(window).height();
	$(document).mousemove(function(e){
		if( $('#container').hasClass('open') ){  // if the container is opened…
			if( e.pageY <= (pageHeight * 0.5) ) {  // and the cursor is above 1/2 page, close it...
				$('#container').animate({'bottom' : '-60%'}, 'fast').removeClass('open');
			}					
		} else { // the container is opened and the cursor is below 1/2 page, close it...
			if( e.pageY >= (pageHeight * 0.9) ) {
				$('#container').animate({'bottom' : '0'}, 'fast').addClass('open');
			}
		}
	});
	
	$('.title').click(function(){
		if( $('#container').hasClass('open') ){  // if the container is opened…
			$('#container').animate({'bottom' : '-60%'}, 'fast').removeClass('open');				
		} else { // the container is opened and the cursor is below 1/2 page, close it...
			$('#container').animate({'bottom' : '0'}, 'fast').addClass('open');
		}
	});
	
	// Supersized plugin
	$.supersized({			
		autoplay : 0,
		slide_interval : 5000,	
		transition : 1, 			
		transition_speed : 700,								
		slide_links	 : 'blank',					
		slides : [		
			{image : 'slides/slide_1.jpg'},
			{image : 'slides/slide_2.jpg'},
			{image : 'slides/slide_3.jpg'},
			{image : 'slides/slide_4.jpg'}
		]				
	});
	
	// Add functionality to Supersized
	$('#next').click(function(){
		api.nextSlide();
	});
	
	$('#prev').click(function(){
		api.prevSlide();
	});
	
	// Slide in slide advance buttons
	$('#next').delay(800).animate({'right' : '0'}, 'slow', 'swing');
	$('#prev').delay(800).animate({'left' : '0'}, 'slow', 'swing');
	
	// appointment form honeypot
	function honeypot(field,alerttxt){
		with (field){
			if (value==null||value==""){ 
				alert(alerttxt);return true;
			}else{return false;}
		}
	}
			
	function validate_form(thisform){
		with (thisform){
			if (honeypot(honeypot,"Quit that, robot!")==false)
				{honeypot.focus();return false;}
		}
	}
	
	$(function(){
		$('.error').hide();
		
		$(".button").click(function(){
			$('.error').hide();			
			if( $('#email').val() != '' ){
				$('#email').css({'color' : '#CCC'});				
				$('.button').fadeOut('slow');
			};
					
			var email = $("input#email").val();
			if (email == ""){
				$("input#email").focus();
				return false;
			}			
			
			var dataString = 'email=' + email ;
			$.ajax({
				type: "POST",
				url: "contact.php",
				data: dataString,
				success: function() {
					$('#contact_form').html("<div id='message'></div>");
					$('#message').html("<h4>Thanks!  Your email has been submitted.</h4>").append("<em>We will be in touch soon.</em>").hide().fadeIn(1500);
					}
			});
			return false;
		});
	});
});	
