$(document).ready(function(){
	//parent element hover function 
	$('#navigation ul li').hover(
		
		//roll in
		function() { 
			//display the drop down
			$('ul', this).css({'display': 'block' }); 
			//keep the parent li a style 
			$('a.drop' , this).css({'background': '#fff url("images/menu.png") top center' , 'color' : '#545454'}); 
			$('a.drop_end' , this).css({'background': '#fff url("images/menu.png") top right' , 'color' : '#545454'});
		},
		//role out
		function() { 
			//remove styles
			$('ul', this).css({'display': 'none'}); 
			$('a.drop', this).css({'background': 'none', 'border-top' : 'none' , 'color' : '#fff'}); 
			$('a.drop_end', this).css({'background': 'none', 'border-top' : 'none' , 'color' : '#fff'});
		}
		
	);
	$('#slideshow').tabs({ fx: { opacity: 'toggle' } }).tabs( 'rotate' , 8000 );
	
	/////////contact form effects and validation////////
	
	//focus blur effect
	$('#contact input.input, textarea').focus(function() {  
	    $(this).css({'color' : '#000'});  
	     
	    if(this.value != this.defaultValue){  
	        this.select();  
	    }  
	});  
	$('#contact input.input').blur(function() {  
	    $(this).css({'background' : 'white' , 'color' : '#000'}); 
	 	
	    if ($.trim(this.value == '')){  
	        this.value = (this.defaultValue ? this.defaultValue : '');  
	    }  
	});
	
	
	//validation

	
	//textareaCheck abstraction checks to see if the user has written anything
	function textareaCheck(){
		
		var textareaInput = $('#contact textarea').val();
		var requiredText = "This Field is Required";
		if(textareaInput == '' || textareaInput == requiredText){
			
		
			$('#contact textarea').attr('value', requiredText);
			$('#contact textarea').css({'color' : '#D62400'});
			return(false);
						
		}else{
			
			return(true);
			
		}	
				
	}
	//nameCheck abstraction checks for a name
	function nameCheck(){
		
		var nameInput = $('#contact input#name').attr('value');
		var requiredText = "This Field is Required";
		if(nameInput == '' || nameInput == requiredText){
			
			
			$('#contact input#name').attr('value', requiredText);
			$('#contact input#name').css({'color' : '#D62400'});
			return(false);	
							
		}else{
			
			return(true);
		
		}	
				
	}
	//emailCheck abstraction checks for a proper email address
	function emailCheck(){
		
		//regular expression for email validation returns null if false
		var emailValid = $("input#email").val().match(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/);
		
		var emailInValid = "Enter a Proper Email Address";
		
		if(emailValid == null){
			
			$('#contact input#email').attr('value', emailInValid);
			$('#contact input#email').css({'color' : '#D62400'});
			return(false);		
			
		}else if(emailValid == emailInValid){
			
			return(false);		
			
		}else{
			
			return(true);
			
		}	
				
	}
	
	//phoneCheck abstraction checks for a valid phone number
	function phoneCheck(){
		
		//regular expression for email validation returns null if false
		var phoneValid = $("input#phonenumber").val().match(/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/);
		
		var phoneInValid = "Enter a Proper Phone Number";
		
		if(phoneValid == null){
			
			$('#contact input#phonenumber').attr('value', phoneInValid);
			$('#contact input#phonenumber').css({'color' : '#D62400'});
			return(false);	
					
		}else if(phoneValid == phoneInValid){
			
			return(false);
					
		}else{
			
			return(true);
			
		}	
				
	}
	
	//on click event for the submit button that init all of the error checking

	$('#submit').click(function formcheck(event){
	
		textareaCheck();
		nameCheck();
		emailCheck();
		//phoneCheck();
		
		//if all fields are valid, then adds regular functionality back to the 
		//submit button and submits the form
		if(nameCheck() == true && emailCheck() == true && textarea() == true){	
	
			$('#submit').unbind('click', formcheck);
				
		}else{
			
			//if any of the forms are not valid then dont submit (removes click functionality from button)
			event.preventDefault();
			
		}
	
	});
});
