/* jquery hide, show, refine search form - used on search results pages */
$(document).ready(function() {
	var currentAmenityGroup;
	var currentCityState;
	// var currentCityState = $(':input[name="main_field"]').val(); //city we start with
	$('ul.amenitiesGroup').hide();
	$('h6#apartment a').addClass('displayOptions');
	$('ul#apartmentAmenities').show();
	/* show/hide options based on category clicked */
	$('h6.optionsTitle').hover( function() {
		if($(this).attr('id') == currentAmenityGroup){
			return;
		}
		currentAmenityGroup = $(this).attr('id');
		$('h6.optionsTitle a').removeClass('displayOptions');
		$(this).children('a').addClass('displayOptions');
		$('ul.amenitiesGroup').hide();
		$('#'+$(this).attr('id')+'Amenities').toggle();
		/**
		  * Show/hide shadowOverlay
		  **/
		if($(this).attr('id') == 'neighborhoods') {
			if (($('#scity').length == 0 || $('#scity').val() == '')
				&& ($('#scollege').length == 0 || $('#scollege').val() == '')
				&& ($('#smilitary').length == 0 || $('#smilitary').val() == '')
				&& ($('#sname').length == 0 || $('#sname').val() == '')
				&& ($('#szipcode').length == 0 || $('#szipcode').val() == '')
			) {
				addShadowOverlay();
			} else {
				// if (hoods != null && CITY STATE NOT CHANGED) {
				//	hoods.refresh();
				// }
				//console.log($(':input[name="main_field"]').val());
				if (hoods != null && $(':input[name="main_field"]').val() != currentCityState){
					currentCityState = $(':input[name="main_field"]').val(); //set new city
					hoods.refresh();
				}
			}
		}else{ //remove overlay
			$('#shadowOverlay').remove();
		}
		return false;
	},
	//this is the hoverout. We don't need it to do anything, but it needs to exist
	function () { return;} 
	);
	
});


var hoods = null;
// AJAX Neighborhoods
$(document).ready(function() {
hoods = new NeighborhoodOptions();
});

function addShadowOverlay(message) {
	if (message == null) {
		message = 'Please select a ';
		switch ($(':input[name="search_type"]').val()) {
			case 'citystate':
				message += 'City and State';
				break;
			case 'zip':
				message += 'Zip code';
				break;
			case 'college':
			case 'military':
			default:
				message += 'location';
				break;
		}
	}
	if ($('#shadowOverlay').length == 0) { //add overlay if it doesn't exist
		$('<span id="shadowOverlay">' + message + '</span>').insertAfter('ul#photos-videosAmenities');
	} else {
		$('#shadowOverlay').html(message);
	}
}


/**
 * Zip code example
 */
$(document).ready(function() {
	if ($('#szipcode').val() == '') {
		$('#szipcode').val('(ex. 23510)');
		$('#szipcode').focus(function() { this.value = ''; });
	}
	
// });
	// main input field validation 
	$('input#search-submit').click(function(){
		if( $('input#scity').val() == ''){
			if( $('.error')){
				$('.error').remove();
			}
			$('fieldset#searches').append('<label id="errorSearchCity" class="searchError error"><strong class="errorExplanation">You Must Enter a City/State Combination To Search!</strong></label>');
			$('input#scity').toggleClass("attention");
			return false;
		}
	});
	$('input#search-submit').click(function(){
		if( $('input#szipcode').val() == ''){
			if( $('.error')){
				$('.error').remove();
			}
			$('fieldset#searches').append('<label id="errorSearchZip" class="searchError error"><strong class="errorExplanation">You Must Enter a Zip Code To Search!</strong></label>');
			$('input#szipcode').toggleClass("attention");
			return false;
		}
	});
	$('input#search-submit').click(function(){
		if( $('input#sname').val() == ''){
			if( $('.error')){
				$('.error').remove();
			}
			$('fieldset#searches').append('<label id="errorSearchName" class="searchError error"><strong class="errorExplanation">You Must Enter an Apartment/<abbr title="Property Management Company">PMC</abbr> To Search!</strong></label>');
			$('input#sname').toggleClass("attention");
			return false;
		}
	});
	$('input#search-submit').click(function(){
		if( $('input#scollege').val() == ''){
			if( $('.error')){
				$('.error').remove();
			}
			$('fieldset#searches').append('<label id="errorSearchCollege" class="searchError error"><strong class="errorExplanation">You Must Enter a College/University To Search!</strong></label>');
			$('input#scollege').toggleClass("attention");
			return false;
		}
	});
	$('input#search-submit').click(function(){
		if( $('input#smilitary').val() == ''){
			if( $('.error')){
				$('.error').remove();
			}
			$('fieldset#searches').append('<label id="errorSearchMilitary" class="searchError error"><strong class="errorExplanation">You Must Enter a Military Installation To Search!</strong></label>');
			$('input#smilitary').toggleClass("attention");
			return false;
		}
	});
});




