var communityLoader = new Class({

	initialize: function(container, table){
		this.container = $(container);
		this.table = $(table);
		this.comm = null;

		homeInfo = new Request({
		method:'get',
		autoCancel:true,
		url:'data/community.xml',
		onRequest:function(){
			//placeholder
		}.bindWithEvent(this),
		onSuccess:function(text,responseXML){
		comm = responseXML.documentElement.getElementsByTagName("community");
		this.load();

		}.bindWithEvent(this),
			onFailure:function(transport){ alert('Legacy :: Home information not found.'); }
		});
			
		homeInfo.send();
	},
	load:function() {
		var community = getNodeValue(comm[0],'community_name', '');
		var w_folder = getNodeValue(comm[0], 'web_folder', '');
		//var lat = getNodeValue(comm[0], 'lat', '');
		//var lng = getNodeValue(comm[0], 'lng', '');
		var loc = getNodeValue(comm[0], 'location', '');
		var amen = getNodeValue(comm[0], 'amenities', '');
		var sch = getNodeValue(comm[0], 'schools', '');
		var util = getNodeValue(comm[0], 'utilities', '');
		var dooz = getNodeValue(comm[0], 'dues', '');

		//$("neighborhood_header").set("html","<H2>" + c_name + "</H2>");
//		$$('title').set('html','Legacy Custom Homes :: Available homes in ' + community);

		var bc = new Element('a', {
    		'class': 'divider',
    		'html': community
    	});
		bc.inject($('breadcrumb'));

//		if($("location") != "") {
//			$("location").set('html',loc + " &nbsp;&nbsp;(<a href='/wrweb/directions/index.html?start=" + loc + "'>directions</a>)");
//		}
		$("location").set('html',loc + '&nbsp;&nbsp;<a style="font-size: .8em;" href="/wrweb/directions/index.html?community=' + w_folder + '">(Directions)</a>');
		$("amenities").set('text',amen);
		$("schools").set('text',sch);
		$("utilities").set('text',util);
		$("dues").set('text',dooz);
	}
});

function getNodeValue(node, tagname, default_val) {
	var elems = node.getElementsByTagName(tagname);

	//test to see if tags aren't blank and have some value
	if (elems && elems[0] && elems[0].firstChild &&
		elems[0].firstChild.nodeValue) {
		return elems[0].firstChild.nodeValue;
		}
	return default_val;
}

