$(document).ready(function(){

	mapToggle();
//	sliderCost();
//	sliderSqf();
//	sliderBath();
//	sliderBed();
	swapMaps();
});


function swapMaps(){
	$(".toggleacadianamap").click(function(){
		
		$("#AcaMap").css('display','block');
		$("#LafMap").css('display','none');
	});
	
	$(".togglelafayettemap").click(function(){
		$("#AcaMap").css('display','none');
		$("#LafMap").css('display','block');
		
	});
	
}



//check if maplink class link is clicked. if so, then
//toggle the checkbox associated with the id just clicked.
function mapToggle() {
	
	$(".maplink").click(function() {
		var count = 0;
		thisId = $(this).attr("id"); id = "#" + thisId;
		thisId = thisId.replace('laf_', '');
		
		chkId = "#chk" + thisId; chkIdVal = 'chk' + thisId;
		
		addTo = $("label[for='"+ chkIdVal +"']").text();
		
		if ( $(chkId).is(":checked")) {
			
			$(chkId).attr('checked','');
		    $('#d'+thisId).remove();
			
		} else {
			
			$(chkId).attr('checked','checked');
			$('#mapresults').append('<div id="d'+ thisId +'" class="list-item">'+addTo+'</div>');
		
		}
		
		
		$("#mapresults").children().each(function(){
			count = count + 1;
		});
		
		
		if (count > 1){
			$("#mapresults").css('display', 'block');
		} else {
			$("#mapresults").css('display', 'none');
		}
		  
		return false;
	});
	
}


/*function mapCheckBoxes() {
	
	$(".mapchkboxes input:checked").each(function(){
		var id = $(this).attr('id');
		
		
	});
} */


/**
 * This function is used to control the slider features for the cost of the house
 */
function sliderCost(){

  //  $('#slider_callout').hide(); 
  //  var calloutVisible = false; 
	
    $('#slider-cost').slider({ 
       // handle: '.ui-slider_handle', 
        handles: [{start:0, min:0, max:100,id:'slider-cost-low'}, {start:100, min:10, max:100, id:'slider-cost-high'}],
		range: true,
		stepping: 5,
		slide: function(e, ui){
			
			if (ui.handle.attr('id') == 'slider-cost-low') {
				var value = ui.value;
				$("#price1").val(value);
			} else {
				var value = ui.value;
				$("#price2").val(value);
			}
			
			if ($("#price1").val() == 0) {
				var price1 = '$0';
			} else {
				var price1 = '$ ' + $("#price1").val() + '0,000';
			}
			
			if ($("#price2").val() == 100) {
				var price2 = 'no limit';
			} else {
				var price2 = '$ ' + $("#price2").val() + '0,000';
			} 
			
			var text = price1 + ' to ' + price2;
			
			$("#price-range").html(text);	
		} 
    });
} 

function sliderSqf(){

  //  $('#slider_callout').hide(); 
  //  var calloutVisible = false; 
	
    $('#slider-sqf').slider({ 
       // handle: '.ui-slider_handle', 
        handles: [{start:0, min:0, max:100,id:'slider-sqf-low'}, {start:100, min:10, max:100, id:'slider-sqf-high'}],
		range: true,
		stepping: 5,
		slide: function(e, ui){
			
			if (ui.handle.attr('id') == 'slider-sqf-low') {
				var value = ui.value;
				$("#sqft1").val(value);
			} else {
				var value = ui.value;
				$("#sqft2").val(value);
			}
			
			if ($("#sqft1").val() == 0) {
				var sqft1 = '0';
			} else {
				var sqft1 = $("#sqft1").val() + '00';
			}
			
			if ($("#sqft2").val() == 100) {
				var sqft2 = 'no limit';
			} else {
				var sqft2 = $("#sqft2").val() + '00';
			} 
			
			var text = sqft1 + ' to ' + sqft2;
			
			$("#sqft-range").html(text);	
		
		} 
    });
}

function sliderBath(){

  //  $('#slider_callout').hide(); 
  //  var calloutVisible = false; 
	
    $('#slider-bath').slider({ 
       // handle: '.ui-slider_handle', 
        handles: [{start:1, min:1, max:10,id:'slider-bath-low'}, {start:10, min:1, max:10, id:'slider-bath-high'}],
		range: true,
		max: 10,
		min: 1,
		stepping: 1,
		slide: function(e, ui){
			
			if (ui.handle.attr('id') == 'slider-bath-low') {
				var value = ui.value;
				$("#minbath").val(value);
			} else {
				var value = ui.value;
				$("#maxbath").val(value);
			}
			
			if ($("#minbath").val() == 0) {
				var minBath = '1';
			} else {
				var minBath = $("#minbath").val() + '';
			}
			
			if ($("#maxbath").val() == 10) {
				var maxBath = 'no limit';
			} else {
				var maxBath = $("#maxbath").val();
			} 
			
			var text = minBath + ' to ' + maxBath;
			
			$("#bath-range").html(text);	
		
		} 
    });
}

/**
 * Slider
 */
function sliderBed(){

  //  $('#slider_callout').hide(); 
  //  var calloutVisible = false; 
	
    $('#slider-bedrooms').slider({ 
       // handle: '.ui-slider_handle', 
        handles: [{start:1, min:1, max:10,id:'slider-bedrooms-low'}, {start:10, min:1, max:10, id:'slider-bedrooms-high'}],
		range: true,
		max: 10,
		min: 1,
		stepping: 1,
		slide: function(e, ui){
			
			if (ui.handle.attr('id') == 'slider-bedrooms-low') {
				var value = ui.value;
				$("#minbed").val(value);
			} else {
				var value = ui.value;
				$("#maxbed").val(value);
			}
			
			if ($("#minbed").val() == 0) {
				var minBed = '1';
			} else {
				var minBed = $("#minbed").val() + '';
			}
			
			if ($("#maxbed").val() == 10) {
				var maxBed = 'no limit';
			} else {
				var maxBed = $("#maxbed").val();
			} 
			
			var text = minBed + ' to ' + maxBed;
			
			$("#bedrooms-range").html(text);	
		
		} 
    });
}