/*//-------------------------------------------->
	Home Finder Script				Developed by Agencynet
		
	Script will check to see which type of homefinder is present, Large / Small.
		
		Dependencies:
			hf_checkBox.js
			hf_buttons.js
			hf_priceSlider.js
			
		Assumptions:
			The values present in the page are representative of the min and max values in the database (ie: bedrooms will have 1 - 6) if available
*///----------------------------------------------> 

var HomeFinder = { 
	options: {
		priceSlider				: false,
		bedrooms					: false,
		bathrooms					: false,
		builders					: false, 
		communities				: false,
		squareFeet				: false,
		findMyHouse				: false,
		displayResults		: 'hfResults',
		helpMe						: 'helpMe',
		bedroomArray  		: [0,0,0,0,0],			//Arrays to keep track of whats active / not active
		bathroomArray 		: [0,0,0,0,0,0,0,0], 
		priceSliderArray	: [99999999,0,0,0],		//Price Slider Array 0=absMin 1=absMax 2=currentMin 3=currentMax
		squareFeetArray		: [99999999,0,0,0],		//Square Feet Array 0=absMin 1=absMax 2=currentMin 3=currentMax
		communitiesArray	: [0,0,0],
		buildersArray		: [0,0,0,0,0,0,0]
	},
//-------------------------------------------------------->
	initialize: function(){
		this.homefinderLarge = false;
		if ($('homefinderModuleLg')){
			this.homefinderLarge = true;
		}
		this.mainFilters = [];					//arrays keep track of all filters for each button
		this.bedroomFilter = [];			
		this.bathroomFilter = [];
		this.communityFilter = [];
		this.builderFilter = [];
		this.priceSliderFilter = false;
		this.squareFeetFilter = false;
		this.communityDataVar = new CommunityData();
		this.communityDataVar.init();
			
		//This is now called after the JSON object is loaded
		/*this.createHFTool();
			this.initializeHFTool();
		*/
	},
//-------------------------------------------------------->
	createHFTool: function(){
		this.addBedRooms();
		this.addBathRooms();
		this.addPriceSlider();
		this.addCommunities();
		this.addFindMyHome();
		this.displayResults = $(this.options.displayResults);
		this.helpMeToggle = 0;
		this.addHelpMe();
		this.helpMe = $(this.options.helpMe);
		if(this.homefinderLarge){		// if were using the large home finder tool
			this.addSquareFeet();
			this.addBuilders();
		}	
	},
//-------------------------------------------------------->
	addHelpMe: function(){
		//Create the tooltips....then hide them until user turns them on
		this.myTips = new Tips ($(this.options.helpMe),{
			maxTitleChars: 150,
			offsets: {'x': -60, 'y': -160},
			fixed: false,
			className: 'helpMe'
		});
		this.myTips2 = new Tips ($('priceRange'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -100},
			fixed: false
		});
		this.myTips3 = new Tips ($('bedrooms'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -120},
			fixed: false
		});
		this.myTips4 = new Tips ($('bathrooms'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -110},
			fixed: false
		});
		this.myTips5 = new Tips ($('communities'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -110},
			fixed: false
		});
		this.myTips6 = new Tips ($('hfResults'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -110},
			fixed: false
		});
		this.myTips7 = new Tips ($('findMyHouse'),{
			maxTitleChars: 150,
			offsets: {'x': -30, 'y': -100},
			fixed: false
		});
		
		if(this.homefinderLarge){
			this.myTips8 = new Tips ($('builders'),{
				maxTitleChars: 150,
				offsets: {'x': -30, 'y': -100},
				fixed: false
			});
			this.myTips9 = new Tips ($('squareFeetRange'),{
				maxTitleChars: 150,
				offsets: {'x': -30, 'y': -100},
				fixed: false
			});
		}
		
		this.myTips2.showToggle = false;
		this.myTips3.showToggle = false;
		this.myTips4.showToggle = false;
		this.myTips5.showToggle = false;
		this.myTips6.showToggle = false;
		this.myTips7.showToggle = false;
		if(this.homefinderLarge){	
			this.myTips8.showToggle = false;
			this.myTips9.showToggle = false;
		}
		this.helpMe = $(this.options.helpMe);
		this.helpMe.addEvent('click', function(){
			//alert(this.helpMeToggle);
			if(this.helpMeToggle == 0){
				this.myTips2.showToggle = true;
				this.myTips3.showToggle = true;
				this.myTips4.showToggle = true;
				this.myTips5.showToggle = true;
				this.myTips6.showToggle = true;
				this.myTips7.showToggle = true;
				if(this.homefinderLarge){
					this.myTips8.showToggle = true;
					this.myTips9.showToggle = true;
				}
				this.helpMeToggle = 1;
				this.helpMe.setHTML('Turn Help Off');
				//change text to OFF
			}
			else{
				this.myTips2.showToggle = false;
				this.myTips3.showToggle = false;
				this.myTips4.showToggle = false;
				this.myTips5.showToggle = false;
				this.myTips6.showToggle = false;
				this.myTips7.showToggle = false;
				if(this.homefinderLarge){
					this.myTips8.showToggle = false;
					this.myTips9.showToggle = false;
				}
				this.helpMeToggle = 0;
				this.helpMe.setHTML('Turn Help On');
				//change text to ON
			}
		}.bind(this));
	},
//-------------------------------------------------------->	
	addBuilders: function(){
		this.options.builders = new HF_checkBox({	
			elementRow	: '#builders ul',
			checkBoxes	: '#builders .checkBox',
			label				: '.builderName',
			id					:	'builder'																				
		});	
	},
//-------------------------------------------------------->
	addSquareFeet: function(){
		this.options.squareFeet = new HF_squareFeet('sqarea','sqknob','sqknob2',{
				steps			: 100,		//amount of values between minValue and maxValue
				minValue	: 0,
				maxValue  : 1200000,
				lowTxt		: 'sqleft',
				highTxt		: 'sqright',
				id				: 'squareFeet'
		}).set(0,100);
	},
//-------------------------------------------------------->
	addFindMyHome: function(){
		this.options.findMyHouse = $('findMyHouse');
		this.options.findMyHouse.addEvent('click', function(){ 
			//alert('Number of Houses Returned:  '+this.getNumberOfElementsAvailable()+'  Bathroom: '+this.bathroomFilter);	
	//		alert('SELECTED -- Price: '+this.priceSliderFilter+'  Bedroom: '+this.bedroomFilter+'  Bathroom: '+this.bathroomFilter+'  Community: '+this.communityFilter+'  Squre Feet:  '+this.squareFeetFilter+'  Builders:  '+this.builderFilter);
		//FILTER ALL CLICKED ITEMS INTO A url THEN SET WINDOW.LOCATION
		var searchString = '';
		if(this.priceSliderFilter != false){
			if(this.priceSliderFilter[0] != null){
				searchString = 'prLow='+Math.round(this.priceSliderFilter[0])+'&';
			}
			if(this.priceSliderFilter[1] != null){
				searchString = searchString+'prHigh='+Math.round(this.priceSliderFilter[1])+'&';
			}
		}
		if(this.bedroomFilter.length > 0){
			searchString = searchString+'bed='+this.bedroomFilter+'&';
		}
		if(this.bathroomFilter.length > 0){
			searchString = searchString+'bath='+this.bathroomFilter+'&';
		}
		if(this.squareFeetFilter != false){
			if(this.squareFeetFilter[0] != null){
				searchString = searchString+'sqFtLow='+Math.round(this.squareFeetFilter[0])+'&';
			}
			if(this.squareFeetFilter[1] != null){
				searchString = searchString+'sqFtHigh='+Math.round(this.squareFeetFilter[1])+'&';
			}
		}
		if(this.communityFilter.length > 0){
			searchString = searchString+'comm='+this.communityFilter+'&';
		}
		if(this.builderFilter.length > 0){
			searchString = searchString+'bldr='+this.builderFilter+'&';
		}
		//trim last occurance of the '&' character
		//var tempVar = searchString.lastIndexOf('&');
		//		alert('SearchString: '+searchString);
		//alert(searchString);
		
		if(this.getNumberOfElementsAvailable() == 0)
			alert('Please adjust your search criteria so you will get a result.');
		else
			window.location = '/homefinder.aspx?'+searchString;

		}.bind(this));
		//alert(this.options.priceSliderArray+'  ::  '+this.options.squareFeetArray);
	},
//-------------------------------------------------------->
	addCommunities: function(){
		this.options.communities = new HF_checkBox({	
			elementRow	: '#communities ul',
			checkBoxes	: '#communities .checkBox',
			label				: '.communityName',
			id					:	'community'																				
		});	
	},
//-------------------------------------------------------->
	addBedRooms: function(){
		this.options.bedrooms = new HF_buttons({
			btnOver			: 'C0A16A',
			btnNorm			: 'f2eddb',
			btnClicked	: '785d2c',
			btnCantUse	: 'cec093',
			btnClassId 	: '#bedrooms li',
			id					: 'bedroom'
		});
	}, 
//-------------------------------------------------------->	
	addBathRooms: function(){
		this.options.bathrooms = new HF_buttons({
				btnOver			: 'C0A16A',
				btnNorm			: 'f2eddb',
				btnClicked	: '785d2c',
				btnCantUse	: 'cec093',
			  btnClassId 	: '#bathrooms li',
				id					: 'bathroom'
		});
	},
//-------------------------------------------------------->	
	addPriceSlider: function(){
		this.options.priceSlider = new HF_priceSlider('area','knob','knob2',{
				steps			: 100,		//amount of values between minValue and maxValue
				minValue	: 0,
				maxValue  : 1200000,
				lowTxt		: 'left',
				highTxt		: 'right',
				id				: 'priceSlider'
		}).set(0,100);
	},
//-------------------------------------------------------->
	mergeArrayAdd: function(mainArray, array2){		//mainArray shouold be this.options.xxxx
			//returns the result of two arrays added together, used when something is selected (ie)clicking 4 bedrooms and then 5 bedrooms
		//if(mainArray.length != array2.length)
		//	alert('Error in add merger Array not same size');
		
		array2.each(function(el,i){
			if(el	== 1)
				mainArray[i] = 1;
		}.bind(this));
		return mainArray;
	},
//-------------------------------------------------------->
	mergeArraySub: function(mainArray, array2){		//mainArray shouold be this.options.xxxx
			//returns the result of two arrays subtracted together
		//if(mainArray.length != array2.length)
		//	alert('Error in sub merger Array not same size');
		
		array2.each(function(el,i){
			if(el	== 0)
				mainArray[i] = 0;
		}.bind(this));
		return mainArray;
	},
//-------------------------------------------------------->
	updatePriceSlider:	function(keyArray, howToMerge){
		
		var temp = this.communityDataVar.getPrices();
		var setKnob1 = 0;
		var setKnob2 = 0;
		var lowValue = 99999999;
		var highValue = 0;
	
		//Find min and max value based off of key array
		temp.each(function(el,i){
			if(keyArray[i] == 1){
				if(el < lowValue)
					lowValue = el;
				if(el > highValue)
					highValue = el;
			}
		}.bind(this));
		
		//force values to integers if not already
		lowValue = lowValue.toInt();
		highValue = highValue.toInt();
		
		//set pricesliderArray with the min and max values -- shouldnt be overwritten after the first pass (initialization)
		if(lowValue < this.options.priceSliderArray[0])
			this.options.priceSliderArray[0] = lowValue;
		if(highValue > this.options.priceSliderArray[1])
			this.options.priceSliderArray[1] = highValue;
		
		//use new values as new knob positions
		setKnob1 = lowValue;
		setKnob2 = highValue;
		
		//Process to adjust knob positions based off of what was selected by price slider
		//If howToMerge = add : then its ok to make lower knob lower and higher knob higher but not opposite
		if(howToMerge == 'add'){
			if(this.priceSliderFilter[0] < lowValue){
				setKnob1 = this.priceSliderFilter[0];
			}
			if(this.priceSliderFilter[1] > highValue){
				setKnob2 = this.priceSliderFilter[1];
			}
		}
		//If howToMerge = subtract : then its ok to make lower knob higher and higher knob lower, but not opposite
		if(howToMerge == 'subtract'){
			if(this.priceSliderFilter[0] > lowValue){
				setKnob1 = this.priceSliderFilter[0];
			}
			if(this.priceSliderFilter[1] < highValue){
				setKnob2 = this.priceSliderFilter[1];
			}
		}
		
		//special case...reset the knobs
		if((howToMerge == 'add') && (this.mainFilters.length == 0)){
			//alert('price slider speical case');
			setKnob1 = this.options.priceSliderArray[0];
			setKnob2 = this.options.priceSliderArray[1];
		}
		
		//Force to integer if needed	
		setKnob1 = setKnob1.toInt();
		setKnob2 = setKnob2.toInt();
		
		//Set current Values in pricesliderarray
		this.options.priceSliderArray[2] = setKnob1;
		this.options.priceSliderArray[3] = setKnob2;

		//update the priceSlider with new values - range will always stay the same, but knobs will move
		var rangeLow = this.options.priceSliderArray[0];
		var rangeHigh = this.options.priceSliderArray[1];
		rangeLow = rangeLow.toInt();
		rangeHigh = rangeHigh.toInt();
		
		if((setKnob1 == 99999999) && (setKnob2 == 0)){
			setKnob1 = this.options.priceSliderArray[0];
			setKnob2 = this.options.priceSliderArray[1];
		}
		
		//update the priceslider with new values
		this.options.priceSlider.update(rangeLow, rangeHigh, setKnob1, setKnob2);
	},
//-------------------------------------------------------->
	updateBathRooms: 		function(keyArray, howToMerge){
		var dataArray = this.communityDataVar.getBathrooms();
		var baseArray = [0,0,0,0,0,0,0,0,0];		//amount of items in base Array have to equal amount of buttons in html
		dataArray.each(function(el, i){		//translates all items in dataArray into the keyArray to send to button handlers
			if (keyArray[i] == 1){
				switch(el){
					case 2:
						baseArray[0] = 1;
						break;
					case 2.5:
						baseArray[1] = 1;
						break;
					case 3:
						baseArray[2] = 1;
						break;
					case 3.5:
						baseArray[3] = 1;
						break;
					case 4:
						baseArray[4] = 1;
						break;
					case 4.5:
						baseArray[5] = 1;
						break;
					case 5:
						baseArray[6] = 1;
						break;
					case 5.5:
						baseArray[7] = 1;
						break;
					case 6:
						baseArray[8] = 1;
						break;
					default:
						break;
				}
			}
		}.bind(this));
		
		//have to merge current status with new status, set the new current status and update	
		if(howToMerge == 'add'){
			//alert(this.options.bathroomArray+'   :bath add:   '+baseArray);
			//alert(this.mergeArrayAdd(this.options.bathroomArray,baseArray));
			this.options.bathroomArray = this.mergeArrayAdd(this.options.bathroomArray,baseArray);
			this.options.bathrooms.update(this.options.bathroomArray);
		} else if (howToMerge == 'subtract'){
			//alert(this.options.bathroomArray+'   :bath subtract:   '+baseArray);
			//alert(this.mergeArraySub(this.options.bathroomArray,baseArray));
			//Check here if were subtracting...and if something is selected and to be removed...remove from the filter array
			baseArray.each(function(el, i){
				if (el == 0){
					switch(i){
						case 0:
							if(this.bathroomFilter.contains('2'))
								this.bathroomFilter.remove('2');
							break;
						case 1:
							if(this.bathroomFilter.contains('2.5'))
								this.bathroomFilter.remove('2.5');
							break;
						case 2:
							if(this.bathroomFilter.contains('3'))							
								this.bathroomFilter.remove('3');
							break;
						case 3:
							if(this.bathroomFilter.contains('3.5'))							
								this.bathroomFilter.remove('3.5');
							break;
						case 4:
							if(this.bathroomFilter.contains('4'))							
								this.bathroomFilter.remove('4');
							break;
						case 5:
							if(this.bathroomFilter.contains('4.5'))							
								this.bathroomFilter.remove('4.5');
							break;
						case 6:
							if(this.bathroomFilter.contains('5'))							
								this.bathroomFilter.remove('5');
							break;
						case 7:
							if(this.bathroomFilter.contains('5.5'))							
								this.bathroomFilter.remove('5.5');
							break;	
						case 8:
							if(this.bathroomFilter.contains('6'))
								this.bathroomFilter.remove('6');
							break;		
					}
				}															
			}.bind(this));
			this.options.bathroomArray = this.mergeArraySub(this.options.bathroomArray,baseArray);
			this.options.bathrooms.update(this.options.bathroomArray);
		} else if(howToMerge == 'slider'){
			this.options.bathrooms.update(baseArray);
		}
	},
//-------------------------------------------------------->
	updateBuilders:			function(keyArray, howToMerge){
		var dataArray = this.communityDataVar.getBuilders();
		var baseArray = [0,0,0,0,0,0,0];			//amount of items in base Array have to equal amount of buttons in html
	
		dataArray.each(function(el, i){
			if (keyArray[i] == 1){		
				switch (el){
					case 'Buie Communities':
						baseArray[0] = 1;
						break;
					case 'Manning Homes':
						baseArray[1] = 1;
						break;
					case 'EJL Homes':
						baseArray[2] = 1;
						break;
					case 'California West Communities':
						baseArray[3] = 1;
						break;
					case 'Zacher Homes':
						baseArray[4] = 1;
						break;
				}
			}
		}.bind(this));
		
		//have to merge current status with new status, set the new current status and update	
		if(howToMerge == 'add'){
		//	alert(this.options.buildersArray+'   :build add:   '+baseArray);
		//	alert(this.mergeArrayAdd(this.options.buildersArray,baseArray));
			this.options.buildersArray = this.mergeArrayAdd(this.options.buildersArray, baseArray);
			this.options.builders.update(this.options.buildersArray);
		} else if (howToMerge == 'subtract'){
		//	alert(this.options.buildersArray+'   :build subtract:   '+baseArray);
		//	alert(this.mergeArraySub(this.options.buildersArray,baseArray));
				baseArray.each(function(el, i){
				if (el == 0){
					switch(i){
						case 0:
							if(this.builderFilter.contains('Buie Communities'))
								this.builderFilter.remove('Buie Communities');
							break;
						case 1:
							if(this.builderFilter.contains('Manning Homes '))							
								this.builderFilter.remove('Manning Homes ');
							break;
						case 2:	
							if(this.builderFilter.contains('EJL Homes'))							
								this.builderFilter.remove('EJL Homes');
							break;
						case 3:
							if(this.builderFilter.contains('California West Communities'))							
								this.builderFilter.remove('California West Communities');
							break;
						case 4:
							if(this.builderFilter.contains('Zacher Homes'))							
								this.builderFilter.remove('Zacher Homes');
							break;	
					}
				}															
			}.bind(this));
			this.options.buildersArray = this.mergeArraySub(this.options.buildersArray, baseArray);
			this.options.builders.update(this.options.buildersArray);
		} else if (howToMerge == 'slider'){
			this.options.builders.update(baseArray);
		}			
	},
//-------------------------------------------------------->
	updateCommunities:	function(keyArray, howToMerge){
		var dataArray = this.communityDataVar.getCommunities();
		var baseArray = [0,0,0];			//amount of items in base Array have to equal amount of buttons in html
		
		dataArray.each(function(el, i){
			if (keyArray[i] == 1){		
				switch (el){
					case 'Mountain Ranch':
						baseArray[0] = 1;
						break;
					case 'Montecito':
						baseArray[1] = 1;
						break;
					case 'Province':
						baseArray[2] = 1;
						break;
				}
			}
		}.bind(this));
		
		//have to merge current status with new status, set the new current status and update	
		if(howToMerge == 'add'){
			//alert(this.options.communitiesArray+'   :com add:   '+baseArray);
			//alert(this.mergeArrayAdd(this.options.communitiesArray,baseArray));
			this.options.communitiesArray = this.mergeArrayAdd(this.options.communitiesArray, baseArray);
			this.options.communities.update(this.options.communitiesArray);
		} else if (howToMerge == 'subtract'){
			//alert(this.options.communitiesArray+'   :com subtract:   '+baseArray);
			//alert(this.mergeArraySub(this.options.communitiesArray,baseArray));
			baseArray.each(function(el, i){
				if (el == 0){
					switch(i){
						case 0:
							if(this.communityFilter.contains('Mountain Ranch'))
								this.communityFilter.remove('Mountain Ranch');
							break;
						case 1:
							if(this.communityFilter.contains('Montecito'))
								this.communityFilter.remove('Montecito');
							break;
						case 2:
							if(this.communityFilter.contains('Province'))							
								this.communityFilter.remove('Province');
							break;
					}
				}															
			}.bind(this));
			this.options.communitiesArray = this.mergeArraySub(this.options.communitiesArray, baseArray);
			this.options.communities.update(this.options.communitiesArray);
		} else if (howToMerge == 'slider'){
			this.options.communities.update(baseArray);
		}			
	},
//-------------------------------------------------------->
	updateSquareFeet:		function(keyArray, howToMerge){
		var temp = this.communityDataVar.getSquareFeet();
		var setKnob1 = 0;
		var setKnob2 = 0;
		var lowValue = 99999999;
		var highValue = 0;
		
		//Find min and max value based off of key array
		temp.each(function(el,i){
			if(keyArray[i] == 1){
				if(el < lowValue)
					lowValue = el;
				if(el > highValue)
					highValue = el;
			}
		}.bind(this));
		
		//force values to integers if not already
		lowValue = lowValue.toInt();
		highValue = highValue.toInt();
		
		//set squareFeetArray with the min and max values -- shouldnt be overwritten after the first pass (initialization)
		if(lowValue < this.options.squareFeetArray[0])
			this.options.squareFeetArray[0] = lowValue;
		if(highValue > this.options.squareFeetArray[1])
			this.options.squareFeetArray[1] = highValue;
		
		//use new values as new knob positions
		setKnob1 = lowValue;
		setKnob2 = highValue;
		
		//Process to adjust knob positions based off of what was selected by sqfeet slider
		//If howToMerge = add : then its ok to make lower knob lower and higher knob higher but not opposite
		if(howToMerge == 'add'){
			if(this.squareFeetFilter[0] < lowValue){
				setKnob1 = this.squareFeetFilter[0];
			}
			if(this.squareFeetFilter[1] > highValue){
				setKnob2 = this.squareFeetFilter[1];
			}
		}
		//If howToMerge = subtract : then its ok to make lower knob higher and higher knob lower, but not opposite
		if(howToMerge == 'subtract'){
			if(this.squareFeetFilter[0] > lowValue){
				setKnob1 = this.squareFeetFilter[0];
			}
			if(this.squareFeetFilter[1] < highValue){
				setKnob2 = this.squareFeetFilter[1];
			}
		}
		
		//special case...reset the knobs
		if((howToMerge == 'add') && (this.mainFilters.length == 0)){
			///alert('sqfeet slider speical case');
			setKnob1 = this.options.squareFeetArray[0];
			setKnob2 = this.options.squareFeetArray[1];
		}
		
		//Force to integer if needed	
		setKnob1 = setKnob1.toInt();
		setKnob2 = setKnob2.toInt();
		
		//Set current Values in squareFeetArray
		this.options.squareFeetArray[2] = setKnob1;
		this.options.squareFeetArray[3] = setKnob2;

		//update the squareFeet with new values - range will always stay the same, but knobs will move
		var rangeLow = this.options.squareFeetArray[0];
		var rangeHigh = this.options.squareFeetArray[1];
		rangeLow = rangeLow.toInt();
		rangeHigh = rangeHigh.toInt();
		
		if((setKnob1 == 99999999) && (setKnob2 == 0)){
			setKnob1 = this.options.squareFeetArray[0];
			setKnob2 = this.options.squareFeetArray[1];
		}
		//update the squareFeet with new values
		this.options.squareFeet.update(rangeLow, rangeHigh, setKnob1, setKnob2);
	},
//-------------------------------------------------------->
	updateBedRooms:			function(keyArray, howToMerge){
		var dataArray = this.communityDataVar.getBedrooms();
		var baseArray = [0,0,0,0,0,0];		//amount of items in base Array have to equal amount of buttons in html

		dataArray.each(function(el, i){
			if (keyArray[i] == 1){
				switch (el){
					case 2:
						baseArray[0] = 1;
						break;
					case 3:
						baseArray[1] = 1;
						break;
					case 4:
						baseArray[2] = 1;
						break;
					case 5:
						baseArray[3] = 1;
						break;
					case 6:
						baseArray[4] = 1;
						break;
				}
			}
		}.bind(this));
		
		if(howToMerge == 'add'){
			//alert(this.options.bedroomArray+'   :bed add:   '+baseArray);
			//alert(this.mergeArrayAdd(this.options.bedroomArray,baseArray));
			this.options.bedroomArray = this.mergeArrayAdd(this.options.bedroomArray, baseArray);
			this.options.bedrooms.update(this.options.bedroomArray);
		} else if (howToMerge == 'subtract'){
			//alert(this.options.bedroomArray+'   :bed sub:   '+baseArray);
			//alert(this.mergeArrayAdd(this.options.bedroomArray,baseArray));
			baseArray.each(function(el, i){
				if (el == 0){
					switch(i){
						case 0:
							if(this.bedroomFilter.contains('2'))
								this.bedroomFilter.remove('2');
							break;
						case 1:
							if(this.bedroomFilter.contains('3'))
								this.bedroomFilter.remove('3');
							break;
						case 2:
							if(this.bedroomFilter.contains('4'))							
								this.bedroomFilter.remove('4');
							break;
						case 3:
							if(this.bedroomFilter.contains('5'))							
								this.bedroomFilter.remove('5');
							break;
						case 4:
							if(this.bedroomFilter.contains('6'))							
								this.bedroomFilter.remove('6');
							break;
					}
				}															
			}.bind(this));
			this.options.bedroomArray = this.mergeArraySub(this.options.bedroomArray, baseArray);
			this.options.bedrooms.update(this.options.bedroomArray);
		} else if (howToMerge == 'slider') {
			this.options.bedrooms.update(baseArray);
		}	
	},
//-------------------------------------------------------->
	getArrayAllOnes:	function(amount){
		var temp = [];
		for (var x = 0; x < amount; x++)
			temp[x] = 1;
		return temp;
	},
//-------------------------------------------------------->
	getArrayAllZeros:	function(amount){
		var temp = [];
		for (var x = 0; x < amount; x++)
			temp[x] = 0;
		return temp;
	},
//-------------------------------------------------------->			
	initializeHFTool:		function(){
		this.createHFTool();
		//Variable - tempArray is an array of all 1's....to set up homeFinder, length should be same for all	
		var tempArray = this.getArrayAllOnes(this.communityDataVar.getBedrooms().length);
		this.updateBathRooms(tempArray, 'add');
		this.updateCommunities(tempArray, 'add');
		this.updateBedRooms(tempArray, 'add');
		this.updatePriceSlider(tempArray);
		this.options.priceSliderArray = this.options.priceSlider.getHighLow();		// set new priceSlider
		//force update with new limits
		var tempVarLow = this.options.priceSliderArray[0].toInt();
		var tempVarHigh = this.options.priceSliderArray[1].toInt();
		//this.options.priceSlider.update(tempVarLow, tempVarHigh, tempVarLow, tempVarHigh);
		
		if (this.homefinderLarge == true){
			this.updateBuilders(tempArray, 'add');
			this.updateSquareFeet(tempArray);
			this.options.squareFeetArray = this.options.squareFeet.getHighLow();		// set new squareFeet 
			//force update with new limits
			var tempVarLow2 = this.options.squareFeetArray[0].toInt();
			var tempVarHigh2 = this.options.squareFeetArray[1].toInt();
			this.options.squareFeet.update(tempVarLow2, tempVarHigh2, tempVarLow2, tempVarHigh2);
		}
		this.updateDisplay();
	},
//-------------------------------------------------------->
	applyAllCurrentFilters: function(category){		//category is passed in special case senerio, otherwise send null 
		//have to go thru all moves involved on a click....
		//start with all 1's....and remove what doesnt belong
		var keyArray = this.getArrayAllOnes(this.communityDataVar.getBedrooms().length);
		var tempArray = [];
		
//alert('Filter categories:  '+this.mainFilters+'   Bath Elements: '+this.bathroomFilter+'  Bedroom Elements: '+this.bedroomFilter+'  Community Elements: '+this.communityFilter+'  Price Filter: '+this.priceFilter);
		if(this.mainFilters.length > 0) {			//if there is at least one option selcted somewhere, else return all 1's (special case)
			this.mainFilters.each(function(el,i){		
				switch (el){
					case 'bathroom':		//=================================
						if(category != 'bathroom'){
							tempArray = this.communityDataVar.getBathrooms();
							var tempBathArray = [];
							this.bathroomFilter.each(function(bathEl, j){
								tempArray.each(function(dataEl, i){
									if (dataEl == bathEl){
										tempBathArray[i] = 1;
									}else if(tempBathArray[i] != 1) {
										tempBathArray[i] = 0;
									}
								}.bind(this));
							}.bind(this));
							//we now have tempBathArray ... subtract from keyArray							
							keyArray = this.mergeArraySub(keyArray, tempBathArray);
						}
					break;
					case 'bedroom':			//=================================
						if(category != 'bedroom'){
							tempArray = this.communityDataVar.getBedrooms();
							var tempBedArray = [];
							this.bedroomFilter.each(function(bedEl, j){
								tempArray.each(function(dataEl, i){
									if (dataEl == bedEl){
										tempBedArray[i] = 1;
									}else if(tempBedArray[i] != 1) {
										tempBedArray[i] = 0;
									}
								}.bind(this));																
							}.bind(this));
							//we now have tempBedArray ... subtract from keyArray
							keyArray = this.mergeArraySub(keyArray, tempBedArray);
						}
					break;
					case 'community':		//=================================
						if(category != 'community'){
							tempArray = this.communityDataVar.getCommunities();						
							var tempComArray = [];
							this.communityFilter.each(function(comEl, j){
								tempArray.each(function(dataEl, i){	
									if (dataEl == comEl){		
										tempComArray[i] = 1;
									}else if(tempComArray[i] != 1) {
										tempComArray[i] = 0;
									}
								}.bind(this));																
							}.bind(this));
							//we now have tempBedArray ... subtract from keyArray
							//alert(keyArray+' Community sub '+tempComArray);
							keyArray = this.mergeArraySub(keyArray, tempComArray);
							//alert(keyArray);
						}
					break;
					case 'priceSlider':	//=================================
					//price no matter what tells what can be viewed...therefore if it doesnt fit in the price range, goodbye
						if(this.priceSliderFilter != false){
							tempArray = this.communityDataVar.getPrices();
							var tempPriceArray = [];
							var priceVarLow = this.options.priceSliderArray[0];
							var priceVarHigh = this.options.priceSliderArray[1];
							
							if(this.priceSliderFilter[0] != null)
							priceVarLow = this.priceSliderFilter[0];
							if(this.priceSliderFilter[1] != null)
							priceVarHigh = this.priceSliderFilter[1];
						
							tempArray.each(function(el, i){
								if ((el > priceVarLow) && (el < priceVarHigh)){
									tempPriceArray[i] = 1;
								}else{
									tempPriceArray[i] = 0;
								}
							}.bind(this));
							
							keyArray = this.mergeArraySub(keyArray, tempPriceArray);	
						}
					break;
					case 'builder':			//=================================
						tempArray = this.communityDataVar.getBuilders();
							var tempBuildArray = [];
							this.builderFilter.each(function(buildEl, j){
								tempArray.each(function(dataEl, i){
									//alert('data:'+dataEl+'comEl:'+comEl);
									//alert(dataEl == comEl.toString);
									if (dataEl == buildEl){	
										tempBuildArray[i] = 1;
									}else if(tempBuildArray[i] != 1) {
										tempBuildArray[i] = 0;
									}
								}.bind(this));																
							}.bind(this));
							//we now have tempBedArray ... subtract from keyArray
							keyArray = this.mergeArraySub(keyArray, tempBuildArray);
					break;
					case 'squareFeet':	//=================================
						//square feet no matter what tells what can be viewed...therefore if it doesnt fit in the price range, goodbye
						//alert('calledSF');
						if(this.squareFeetFilter != false){
							tempArray = this.communityDataVar.getSquareFeet();
							var tempSquareFeetArray = [];
							var sfeetVarLow = this.options.squareFeetArray[0];
							var sfeetVarHigh = this.options.squareFeetArray[1];
							
							if(this.squareFeetFilter[0] != null)
							sfeetVarLow = this.squareFeetFilter[0];
							if(this.squareFeetFilter[1] != null)
							sfeetVarHigh = this.squareFeetFilter[1];
							//alert(priceVarLow+'  l:Price Slider:h  '+priceVarHigh);
						
							tempArray.each(function(el, i){
								if ((el > sfeetVarLow) && (el < sfeetVarHigh)){
									tempSquareFeetArray[i] = 1;
								}else{
									tempSquareFeetArray[i] = 0;
								}
							}.bind(this));
							//alert(keyArray+' SqFeet sub '+tempSquareFeetArray);
							keyArray = this.mergeArraySub(keyArray, tempSquareFeetArray);	
							//alert('Price post: '+keyArray);
						}
					break;
				}
			}.bind(this));
		} 
		return keyArray
	},
//-------------------------------------------------------->
	resetForm: function(itemUsed){
		this.updateBathRooms(this.getArrayAllZeros(this.communityDataVar.getBathrooms().length), 'subtract');
		this.updateBedRooms(this.getArrayAllZeros(this.communityDataVar.getBedrooms().length), 'subtract');
		this.updateCommunities(this.getArrayAllZeros(this.communityDataVar.getCommunities().length), 'subtract');
		
		keyArray = this.applyAllCurrentFilters();
		this.updateBathRooms(keyArray, 'add'); 
		this.updateBedRooms(keyArray, 'add');
		this.updateCommunities(keyArray, 'add');
		
		if (this.homefinderLarge == true){
			this.updateBuilders(this.getArrayAllZeros(this.communityDataVar.getCommunities().length), 'subtract');
			this.updateBuilders(keyArray, 'add');
			if (itemUsed == 'priceSlider')				
				this.updateSquareFeet(keyArray);
			else 
				this.updatePriceSlider(keyArray);
		}
	},
//-------------------------------------------------------->
	//Special case when main filter has one option clicked
	mainFilterEqualsOne: function(){
		//alert('mainFilterEqualsOne called'+this.mainFilters);
		switch(this.mainFilters[0]){
			case 'bathroom':
				this.updateBathRooms(this.getArrayAllOnes(this.communityDataVar.getBathrooms().length), 'add'); 
				break;
			case 'bedroom':
				this.updateBedRooms(this.getArrayAllOnes(this.communityDataVar.getBedrooms().length), 'add');
				break;
			case 'community':	
				this.updateCommunities(this.getArrayAllOnes(this.communityDataVar.getCommunities().length), 'add');
				break;
			case 'builder':
				this.updateBuilders(this.getArrayAllOnes(this.communityDataVar.getCommunities().length), 'add');
				break;
		}
	},
//-------------------------------------------------------->
/*
	LOGIC for buttons:
		- if you click a button for the first time .... you subtract results
			each subsequent click will add to results (from same category ie bedrooms)
		- if you deselct a button (with other buttons still selected ... you subtract
			last deselected button ... will add results
		- if a category is already slected ... choose button in another category ... first one subtracts
			each subsequent click will add to results
*/	
	update: function(who, what, value){	
		//alert('WHO CALLED: '+who+'     WHAT HAPPENED: '+what+'     VALUE: '+value);
		var keyArray = [];
		var tempArray = [];
		var howToMergeArrays = 'subtract';
	//Different SCENERIOS
		//BEDROOM================================================
		if((who == 'bedroom') && (what == 'select')){		// create new key	save as this.keyArray				
			this.bedroomFilter.include(value);						//keep track of all values clicked of this category
			this.mainFilters.include(who);								//keep track of categories clicked
		
			if(this.bedroomFilter.length > 1)
				howToMergeArrays = 'add';
					
			//get key Array based off of what we have....what was just selected is already included in applyAllCurrentFilters 
			keyArray = this.applyAllCurrentFilters(null);
			//alert('Bedroom Key Post '+keyArray);
		
					// take key Array and pass to correct other elements elements	
			this.updateBathRooms(keyArray, howToMergeArrays);
			this.updateCommunities(keyArray, howToMergeArrays);
			this.updatePriceSlider(keyArray, howToMergeArrays);
			if (this.homefinderLarge == true){
				this.updateBuilders(keyArray, howToMergeArrays);
				this.updateSquareFeet(keyArray);
			}
		}	
		//--------------------------------------------
		if((who == 'bedroom') && (what == 'deselect')){		
			this.bedroomFilter.remove(value);					//remove filter number from bedroomFilter array
			if(this.bedroomFilter.length == 0){				//if this is the last item of category
				howToMergeArrays = 'add';
				this.mainFilters.remove(who);
			}
				//Apply the other filters, minus the one clicked
			keyArray = this.applyAllCurrentFilters(null);  
			//alert('BEDROOM:  keyArray:  '+keyArray+'  operation: '+howToMergeArrays);
			
			// take key Array and pass to correct other elements
			keyArray = this.applyAllCurrentFilters('bathroom');
			this.updateBathRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('priceSilder');
			this.updatePriceSlider(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('community');
			this.updateCommunities(keyArray, howToMergeArrays);
			if (this.homefinderLarge == true){
				this.updateSquareFeet(keyArray);
				this.updateBuilders(keyArray, howToMergeArrays);
			}
			
			//This call fixes the scenerio where two buttons or more are clicked and one is removed from same category - keeps them active
			keyArray = this.applyAllCurrentFilters('bedroom');
			this.updateBedRooms(keyArray, howToMergeArrays);																								
			//special case: Only one category selected -- Reset active category to all available
			if (this.mainFilters.length == 1){ 
				this.mainFilterEqualsOne();
			}
		
		}
		//BATHROOM===============================================
		if((who == 'bathroom') && (what == 'select')){
			this.bathroomFilter.include(value);		//keep track of all values clicked of this category
			this.mainFilters.include(who);				//keep track of categories clicked
			
			if(this.bathroomFilter.length > 1)
				howToMergeArrays = 'add';
					
			//get what we currently have, and subtract whats not available 
			keyArray = this.applyAllCurrentFilters(null);		
			
			//alert('Bathroom Key Post '+keyArray);
		
					// take key Array and pass to update other elements
			this.updateBedRooms(keyArray, howToMergeArrays);
			this.updateCommunities(keyArray, howToMergeArrays);
			this.updatePriceSlider(keyArray, howToMergeArrays);
			if (this.homefinderLarge == true){
				this.updateBuilders(keyArray, howToMergeArrays);	
				this.updateSquareFeet(keyArray);
			}
		}
		//--------------------------------------------
		if((who == 'bathroom') && (what == 'deselect')){
			this.bathroomFilter.remove(value);	//remove filter number from bedroomFilter array
			if(this.bathroomFilter.length == 0){				
				this.mainFilters.remove(who);
				howToMergeArrays = 'add';	
			}	
	
			keyArray = this.applyAllCurrentFilters();			
				//alert('BATHROOM:  keyArray:  '+keyArray+'  operation: '+howToMergeArrays);

				// take key Array and pass to correct other elements elements
			keyArray = this.applyAllCurrentFilters('bedroom');
			this.updateBedRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('priceSlider');
			this.updatePriceSlider(keyArray, howToMergeArrays);	
			keyArray = this.applyAllCurrentFilters('community');
			this.updateCommunities(keyArray, howToMergeArrays);
			if (this.homefinderLarge == true){
				this.updateSquareFeet(keyArray);
				this.updateBuilders(keyArray, howToMergeArrays);
			}
		
		//This call fixes the scenerio where two buttons or more are clicked and one is removed from same category - keeps them active
			keyArray = this.applyAllCurrentFilters('bathroom');
			this.updateBathRooms(keyArray, howToMergeArrays);
			
			if (this.mainFilters.length == 1){ //special case: Reset active category to all available
					this.mainFilterEqualsOne();
			}
		}
		//COMMUNITY==============================================
		if((who == 'community') && (what == 'select')){
			this.communityFilter.include(value);		//keep track of all values clicked
			this.mainFilters.include(who);					//keep track of all elements clicked
				
			if(this.communityFilter.length > 1)
				howToMergeArrays = 'add';
					
			keyArray = this.applyAllCurrentFilters(null);
		//alert(keyArray);
					// take key Array and pass to correct other elements elements	
			this.updateBathRooms(keyArray, howToMergeArrays);
			this.updateBedRooms(keyArray, howToMergeArrays);
			this.updatePriceSlider(keyArray, howToMergeArrays);
			if (this.homefinderLarge == true){
				this.updateBuilders(keyArray, howToMergeArrays);
				this.updateSquareFeet(keyArray);
			}
		} 
		//--------------------------------------------
		if((who == 'community') && (what == 'deselect')){
			this.communityFilter.remove(value);	//remove filter number from bedroomFilter array
			if(this.communityFilter.length == 0){				
				this.mainFilters.remove(who);
				howToMergeArrays = 'add';	
			}	
	
			//keyArray = this.applyAllCurrentFilters(null);
				// take key Array and pass to correct other elements elements
				//alert('BATHROOM:  keyArray:  '+keyArray+'  operation: '+howToMergeArrays);
				// have to apply all previous filters available to keyGen
			keyArray = this.applyAllCurrentFilters('bedroom');
			this.updateBedRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('bathroom');
			this.updateBathRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('priceSlider');
			this.updatePriceSlider(keyArray, howToMergeArrays);	
			
			if (this.homefinderLarge == true){
				this.updateSquareFeet(keyArray);
				this.updateBuilders(keyArray, howToMergeArrays);
			}

		keyArray = this.applyAllCurrentFilters('community');
		this.updateCommunities(keyArray, howToMergeArrays);
		
		if (this.mainFilters.length == 1){ //special case: Reset active category to all available
				this.mainFilterEqualsOne();
			}
		}
		//PRICESLIDER============================================
		if(who == 'priceSlider'){
			this.mainFilters.include(who);		
			//need to define which knob was moved...then compare that moved knob to the current states
			var tempValue = [];
			//value 0 has changed
			if((value[0] != this.options.priceSliderArray[0]) && (value[1] == this.options.priceSliderArray[1]))
				tempValue = [value[0], null];
			//value 1 has changed
			if((value[0] == this.options.priceSliderArray[0]) && (value[1] != this.options.priceSliderArray[1]))
				tempValue = [null, value[1]];
			//both values have changed
			if((value[0] != this.options.priceSliderArray[0]) && (value[1] != this.options.priceSliderArray[1]))
				tempValue = [value[0], value[1]];
			//the values are back to the original positions, priceSlider is not a factor anymore
			if((value[0] == this.options.priceSliderArray[0]) && (value[1] == this.options.priceSliderArray[1])){
				tempValue = false;
				this.mainFilters.remove(who);
			}
			
			/*	resetFormVar is used to decide if we should reset the form, rather than updating each element
					We are trying to remove all filters when user moves price slider lower or higher than current values with other filters on
			*/
			var resetFormVar = false;
			if ((this.mainFilters.length > 0) && ((tempValue[0] != null) && (tempValue[0] < this.options.priceSliderArray[2])) || ((tempValue[1] != null) && (tempValue[1] > this.options.priceSliderArray[3]))){
				var count = this.mainFilters.length;
				var position = 0;
				for (var i = 0; i < count; i++){					
					switch(this.mainFilters[position]){
						case 'bedroom':
							this.mainFilters.remove('bedroom');
							this.bedroomFilter = [];
							position--;
							break;
						case 'bathroom':
							this.mainFilters.remove('bathroom');
							this.bathroomFilter = [];
							position--;
							break;
						case 'community':
							this.mainFilters.remove('community');
							this.communityFilter = [];
							position--;
							break;
						case 'builder':
							this.mainFilters.remove('builder');
							this.builderFilter = [];
							position--;
							break;
						case 'squareFeet':
							this.mainFilters.remove('squareFeet');
							this.squareFeetFilter = [];
							position--;
							break;
					}	
					position++;
				}
				resetFormVar = true;
			} 
			
			//keep track of min/max Values
			this.priceSliderFilter = tempValue;		
			//keep track of knobValues in priceSliderArrya
			if((tempValue != false) && (tempValue[0] != null))
				this.options.priceSliderArray[2] = tempValue[0];
			if((tempValue != false) && (tempValue[1] != null))
				this.options.priceSliderArray[3] = tempValue[1];
					
		
			//update all elements based off of a reset - this 'special' case
			if (resetFormVar == true){
				this.resetForm('priceSlider');
			} else {
				//update all elements as per new price range
				keyArray = this.applyAllCurrentFilters('bedroom');
				this.updateBedRooms(keyArray, 'slider');
				keyArray = this.applyAllCurrentFilters('bathroom');
				this.updateBathRooms(keyArray, 'slider');
				keyArray = this.applyAllCurrentFilters('community');
				this.updateCommunities(keyArray, 'slider');
			
				if (this.homefinderLarge == true){
					keyArray = this.applyAllCurrentFilters('builders');
					this.updateBuilders(keyArray, 'slider');
					keyArray = this.applyAllCurrentFilters();
					this.updateSquareFeet(keyArray);
				}
			}
		}
		//=======================================================
	
	//FOR FULL HOME FINDER
	
		//BUILDER==============================================
		if((who == 'builder') && (what == 'select')){
			this.builderFilter.include(value);	//keep track of all values clicked
			this.mainFilters.include(who);			//keep track of all elements clicked	
			
			if(this.builderFilter.length > 1)
				howToMergeArrays = 'add';
					
			keyArray = this.applyAllCurrentFilters(null);
			//alert(keyArray);
					
					// take key Array and pass to correct other elements elements	
			this.updateBathRooms(keyArray, howToMergeArrays);
			this.updateBedRooms(keyArray, howToMergeArrays);
			this.updatePriceSlider(keyArray, howToMergeArrays);
			this.updateCommunities(keyArray, howToMergeArrays);
			this.updateSquareFeet(keyArray);
		}
		//--------------------------------------------
		if((who == 'builder') && (what == 'deselect')){
			this.builderFilter.remove(value);	//remove filter number from bedroomFilter array
			if(this.builderFilter.length == 0){				
				this.mainFilters.remove(who);
				howToMergeArrays = 'add';	
			}	
	
			//keyArray = this.applyAllCurrentFilters(null);
				// take key Array and pass to correct other elements elements
				//alert('BATHROOM:  keyArray:  '+keyArray+'  operation: '+howToMergeArrays);
				// have to apply all previous filters available to keyGen
			keyArray = this.applyAllCurrentFilters('bedroom');
			this.updateBedRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('bathroom');
			this.updateBathRooms(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('priceSlider');
			this.updatePriceSlider(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('builder');
			this.updateBuilders(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('squareFeet');
			this.updateSquareFeet(keyArray, howToMergeArrays);
			keyArray = this.applyAllCurrentFilters('community');
			this.updateCommunities(keyArray, howToMergeArrays);
			
			if (this.mainFilters.length == 1){ //special case: Reset active category to all available
				this.mainFilterEqualsOne();
			}
		}
		//SQUAREFEET===========================================
		if(who == 'squareFeet'){
			this.mainFilters.include(who);

			//need to define which knob was moved...
			var tempValue = [];
			//value 0 has changed
			if((value[0] != this.options.squareFeetArray[0]) && (value[1] == this.options.squareFeetArray[1]))
				tempValue = [value[0], null];
			//value 1 has changed
			if((value[0] == this.options.squareFeetArray[0]) && (value[1] != this.options.squareFeetArray[1]))
				tempValue = [null, value[1]];
			//both values have changed
			if((value[0] != this.options.squareFeetArray[0]) && (value[1] != this.options.squareFeetArray[1]))
				tempValue = [value[0], value[1]];
			//the values are back to the original positions
			if((value[0] == this.options.squareFeetArray[0]) && (value[1] == this.options.squareFeetArray[0])){
				tempValue = false;
				this.mainFilters.remove(who);
			}
			
			
			//resetFormVar is used to decide if we should reset the form, rather than updating each element
			//We are trying to remove all filters when user moves price slider lower or higher than current values with other filters on
			

			var resetFormVar = false;
			if ((this.mainFilters.length > 0) && ((tempValue[0] != null) && (tempValue[0] < this.options.squareFeetArray[2])) || ((tempValue[1] != null) && (tempValue[1] > this.options.squareFeetArray[3]))){
				var count = this.mainFilters.length;
				var position = 0;
				for (var i = 0; i < count; i++){					
					switch(this.mainFilters[position]){
						case 'bedroom':
							this.mainFilters.remove('bedroom');
							this.bedroomFilter = [];
							position--;
							break;
						case 'bathroom':
							this.mainFilters.remove('bathroom');
							this.bathroomFilter = [];
							position--;
							break;
						case 'community':
							this.mainFilters.remove('community');
							this.communityFilter = [];
							position--;
							break;
						case 'builder':
							this.mainFilters.remove('builder');
							this.builderFilter = [];
							position--;
							break;
						case 'priceSlider':
							this.mainFilters.remove('priceSlider');
							this.priceSliderFilter = false;
							position--;
							break;
					}	
					position++;
				}
				resetFormVar = true;
			} 
			
			
			//keep track of min/max Values
			this.squareFeetFilter = tempValue;		
			//keep track of knobValues in priceSliderArrya
			if((tempValue != false) && (tempValue[0] != null))
				this.options.squareFeetArray[2] = tempValue[0];
			if((tempValue != false) && (tempValue[1] != null))
				this.options.squareFeetArray[3] = tempValue[1];
		
			
			
			//update all elements based off of a reset - this 'special' case
			if (resetFormVar == true){
				this.resetForm('squareFeet');
			} else {
				//update all elements as per new price range
				keyArray = this.applyAllCurrentFilters('bedroom');
				this.updateBedRooms(keyArray, 'slider');
				keyArray = this.applyAllCurrentFilters('bathroom');
				this.updateBathRooms(keyArray, 'slider');
				keyArray = this.applyAllCurrentFilters('community');
				this.updateCommunities(keyArray, 'slider');
				keyArray = this.applyAllCurrentFilters();
				this.updatePriceSlider(keyArray, 'slider');
				
				if (this.homefinderLarge == true){
					keyArray = this.applyAllCurrentFilters('builders');
					this.updateBuilders(keyArray, 'slider');
				}
			}	
		}
				//=====================================================	
		this.updateDisplay();
	},
//-------------------------------------------------------->
	updateDisplay: function(){
		var countTotal = this.getNumberOfElementsAvailable();
		this.displayResults.setHTML('Number of homes found: '+countTotal+' home(s)');
	},
//-------------------------------------------------------->
	getNumberOfElementsAvailable: function(){
		var tempArray = this.applyAllCurrentFilters(null);
		var count = 0;
		tempArray.each(function(el,i){
			if(el == 1)
				count++;												
		})
		return count;
	}
};

window.onDomReady(HomeFinder.initialize.bind(HomeFinder));




