// JavaScript Document
var CommunityData = new Class({
	options:{
		bedroomArray  		: [],	
		bathroomArray 		: [], 
		squareFeetArray		: [],
		priceArray 				: [],
		communitiesArray	: [],
		buildersArray			: [], 
		numberOfElements  : 0
	},
//-------------------------------------------------------->	
	init: function(){
		//Get JSON object, parse into correct arrays
		
		//e = new Event(e).stop();
		var url = '/homefinder.aspx/gethomes.json';
		var request = new Json.Remote(url, {
			method:'get',
			onComplete: function(jsonObj) {
				this.createArrays(jsonObj.estrellaData);
			}.bind(this)
		},this).send();
	},
//-------------------------------------------------------->
	//Function assumes the elemetns of the JSON object
	createArrays: function(element){
		//alert(element.length);
		this.options.numberOfElements = element.length;
		element.each(function(el,i){
			this.options.bedroomArray[i] = el.bedrooms;
			this.options.bathroomArray[i] = el.bathrooms;  
			this.options.priceArray[i] = el.price;  
			this.options.communitiesArray[i] = el.community;  
			this.options.squareFeetArray[i] = el.sqft;  
			this.options.buildersArray[i] = el.builder;  
		}.bind(this))
		//alert(this.options.priceArray);
		//This call initializes all the elements with the correct items from the database
		HomeFinder.initializeHFTool();
	},
//-------------------------------------------------------->
	getNumberOfElements: function(){
		return this.options.numberOfElements;
	},
//-------------------------------------------------------->
	getBedrooms: function(){
		return this.options.bedroomArray;
	},
//-------------------------------------------------------->
	getBathrooms: function(){
		return this.options.bathroomArray;
	},
//-------------------------------------------------------->
	getSquareFeet: function(){
		return this.options.squareFeetArray;
	},
//-------------------------------------------------------->
	getCommunities: function(){
		return this.options.communitiesArray;
	},
//-------------------------------------------------------->
	getPrices: function(){
		return this.options.priceArray;
	},
//-------------------------------------------------------->
	getBuilders: function(){
		return this.options.buildersArray;
	}
});

//window.onDomReady(CommunityData.init.bind(CommunityData));
