
var numRand = Math.floor(Math.random()*2)

$(document).ready(function(){
	
	$(".snapshot").click(function(e){
		e.preventDefault();
		$("#expand_snapshot").animate({height: "toggle"});
		
	});
	$(".featured_community2").fadeOut('fast');
	function divHideRandom(){
		
		if(numRand == 1){
			
			$(".featured_community1").fadeOut('fast');
			$(".featured_community2").fadeIn('fast');
			
		}else if(numRand == 2){
			
			$(".featured_community2").fadeOut('fast');
			$(".featured_community1").fadeIn('fast');
		}
		
	}
	divHideRandom();
	
	
	///////navigation effects///////
	//parent element hover function
	function expandCollapse(){
		
		$(".expand_wrapper a[title='']").click(function expandClick(event){
			event.preventDefault();
			var $this = $(this);
			
			if($this.is ('.bluebar')){
				
				$(this).removeClass("bluebar")
				
			}else{
				
				$(this).addClass('bluebar')
				
			}
			
			$(this).next().animate({height: "toggle"});
			
		});
		
		$(".expand").prepend('<div class="spacer"></div>');
		
	}

	expandCollapse();
		
	///////slideshow rotation//////
	$('#home_tabs').tabs({event: 'mouseover' , fx: { opacity: 'toggle' }});
	
	$('#home_tabs ul li a#tab_one').click(function () {window.location = "http://www.mlsfinder.com/fl_mfrmls/vanessabarnes/";});
	$('#home_tabs ul li a#tab_two').click(function () {window.location = "http://www.mlsfinder.com/fl_mfrmls/vanessabarnes/index.cfm?action=newsearch&primarySearchtype=foreclosure&searchtype=map";});
	$('#home_tabs ul li a#tab_three').click(function () {window.location = "http://colon/Clients/vanessa%20barnes/website/international_sub/international_buyers.php";});
	$('#home_tabs ul li a#tab_four').click(function () {window.location = "http://www.simplyfloridarealestate.com/sellers_sub/help_sellers.php";});
	
	/////////contact form effects and validation////////
	
	//focus blur effect
	$('#contact input.input, textarea').focus(function() {  
	    $(this).css({'background' : '#D6D6D6' , 'color' : '#000'});  
	     
	    if(this.value != this.defaultValue){  
	        this.select();  
	    }  
	});  
	$('#contact input.input, textarea').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({'background' : '#FFD8D9','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({'background' : '#FFD8D9','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({'background' : '#FFD8D9','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({'background' : '#FFD8D9','color' : '#D62400'});
			return(false);	
					
		}else{
			
			return(true);
			
		}	
				
	}
	
	//on click event 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();
			
		}
	
	});
	
	
});
