var locationsVisible = false;

function equalHeight(group) {
	// if there are listings, resize the listings col to be equal to it's contents
	if ($("#marbella-listings-col").length != 0) {
		$("#marbella-listings-col").height($("#listings-header").height() + $("#divSearch").height() + 40);
	}	
	
	tallest = 0;
	group.each(function() {
	thisHeight = $(this).height();
	if(thisHeight > tallest) {
	    tallest = thisHeight;
	}
	});
	// adjust height

	group.height(tallest);
}


function loadtopnav(){
	$("#amenities-dropdown").css({display: "none"}); // Opera Fix
	$("#nav-vill").hover(function() {
		$("#amenities-dropdown").css({visibility: "visible",display: "none"}).slideDown(400);
	},function(){
		var keepVisible = false;
		$("#amenities-dropdown").hover(function() {
			keepVisible = true;
			$("#amenities-dropdown").css({visibility: "visible"});
		},function(){
			$("#amenities-dropdown").css({visibility: "hidden"});
		});
		if (keepVisible != true)
			$("#amenities-dropdown").css({visibility: "hidden"});
	});
} 

function setupselectlocation() {
	$("#form-fields-location").css({display: "none"}); // Opera Fix
	$("#select-location").click(function() {
		if (locationsVisible == false) {
			locationsVisible = true;
			$("#form-fields-location").css({visibility: "visible",display: "block"});
		} else {
			locationsVisible = false;
			$("#form-fields-location").css({visibility: "hidden"});
		}
	});
	$("#close-location").click(function() {
			locationsVisible = false;
			$("#form-fields-location").css({visibility: "hidden"});
	});
} 


$(function() {         
	// initialize "for more information" scrollable  
	$("div.scrollable").scrollable({ 
		vertical:true,  
		size: 5          
	// use mousewheel plugin 
	}).mousewheel();


	// set all hover functionality for top nav images
	$('.topnav').hover(function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	}, function() {
		var currentImg = $(this).attr('src');
		$(this).attr('src', $(this).attr('hover'));
		$(this).attr('hover', currentImg);
	});
	

	loadtopnav();
	setupselectlocation();
	
	
	// make sure users can only check one box at a time
	// similar to radio button functionality, but cohesive with this design
	$('.location-boxes').click(function() {
		// $(':checkbox[name='+ $(this).attr('name') +']').attr('checked',false);
		// $(this).attr('checked',true);

		var selectedCommunity = "";
		var count = 0;
		$('.location-boxes').each(function() {
			if ($(this).attr('checked') == true) {
				selectedVillage = $(this).attr('name');
				selectedVillage = selectedVillage.replace("location-", "");
				count = count + 1;			
			}
		});	
		
		if (count == 1) {
			// each checkbox value is the name of the community, i.e. Las Olas = las-olas, which is page "villages-las-olas.html"			
			$("#listings-form").attr('action','villages-' + selectedVillage + '.html');
		} else {
			// if there is more than one selected, forward them to the 
			$("#listings-form").attr('action','villages.html');
		}
	});
	
	setupsoftjoin();
	
	// set current page in nav to hover state graphic
	$('.currentpage').attr('src', $('.currentpage').attr('hover'));
	
	
	// preload nav hover states
	MM_preloadImages('images/nav_amenities_on.jpg','images/nav_community_on.jpg','images/nav_education_on.jpg','images/nav_joinourlist_on.jpg','images/nav_localinterest_on.jpg','images/nav_villages_on.jpg');

	
	$("a#locmap").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500
	});

	
	// scale height of both right and left
	equalHeight($(".content-cols"));
    
}); 