var quickViewCache = new Object();
var moreMaps = false;

function MapItem() {
	
	var point;
	var id;
	var cid;
	var count;
	var ajaxPreviewUrl;
	var name;
	var infoWindowHtml;
}

function panToCommunity(id) {
	
	cid = "c" + id;
	marker = markers[cid];
	map.panTo(marker.getPoint());
	getQuickViewForGMap(cid,'/content/en/search/ajax.preview.community.php?id=' + id,marker);
	
}

function getDirections(from,to) {
	
	
	if (to == "") {
		alert("Please enter a departure address!");
		return;
	}
	
	
	directionsPanel = document.getElementById("TravelDirections");
	directions = new GDirections(map,directionsPanel);
	directions.load(decodeURI(from) + " to " + to);
	
	
}


function showMoreOnMap(url) {
	
	if (!moreMaps) {
		new Ajax.Request(url,{onComplete:updateMap});
	}
}

function updateMap(res) {
	
	
	eval(res.responseText);
	//moreMaps = true;
	map.setCenter(bounds.getCenter()); 
	
	return;
	
	if (!newListings) {
		return;
	}
	
	debug = new Array();	
	
	for(i=0;i<newListings.length;i++) {
		
		arr = newListings[i].split(",");
		
		id = arr[0];
		lat = arr[1];
		lng = arr[2];
		
		msg = "ID = " + id + " , Lat = " + lat + " , Lng = " + lng;
		debug.push(msg);
		
	}
	
	alert(debug.join("\n"));
	
}

function quickView(id,url,e) {
	
	
	positionQuickView(e);
	qv = $("QuickView");
	
	
	if (quickViewCache[id]) {
		
		qv.innerHTML = quickViewCache[id];
		
	} else {
		
		new Ajax.Request(url,{onComplete:updateQuickView});
	}
		
}

function getQuickViewForGMap(id,url,marker) {

	if (quickViewCache[id]) {
		marker.openInfoWindowHtml(quickViewCache[id]);
	} else {

		new Ajax.Request(url,{onSuccess: function(res) {   
			txt = res.responseText;
			preview = eval(txt);
			quickViewCache[preview.id] = preview.html;
			marker.openInfoWindowHtml(preview.html);
		
		}});
	}

}

function quickViewForGMap(res) {
	
	txt = res.responseText;
	preview = eval(txt);
	quickViewCache[preview.id] = preview.html;
	
	return preview.html;
	
}

function updateQuickView(res) {
	
	txt = res.responseText;
	//$("debug").innerHTML = txt;
	
	preview = eval(txt);
	
	quickViewCache[preview.id] = preview.html;
	
	qv = $("QuickView");
	qv.style.width = "300px";
	qv.innerHTML = preview.html;
}

function positionQuickView(e) {
	
	if (!e) var e = window.event;
	
	qv = $("QuickView");
	
	Element.show(qv);
	m = getMouse(e);
	qv.style.left = (m.x + 10) + 'px';
	qv.style.top = ( m.y + 10) + 'px';				
	
	qv.innerHTML = "<img src=\"/images/indicator.gif\" />";
}

function hideQuickView() {
	Element.hide("QuickView");
}


function highlightRow() {
	
	if (this.hasClassName("RowHighlight")) { return ; }
	this.toggleClassName("RowHighlighted");
	
}

function highlightColumn() {
	
	if (this.parentNode.hasClassName("RowHighlight")) { return ; }
	
	parentNode = this.parentNode;
	
	
	
	this.toggleClassName("CellHighlighted");
	
}

function getMouse(e) {
	
	x = Event.pointerX(e);
	y = Event.pointerY(e);	
	
	m = new Object();
	m.x = x;
	m.y = y;
	
	return m;
	
}

function init() {
	
	tbls = document.getElementsByClassName("Compare");
	
	for(i=0;i<tbls.length;i++) {
		
		tbl = tbls[i];
		
		trs = tbl.getElementsByTagName("tr");
		
		for(n=0;i<trs.length;n++) {
			
			tr = trs[n];
			
			if (!tr) { break; }
			
			tr.onmouseover = highlightRow;
			tr.onmouseout = highlightRow;
			
		}
		
		
		tds = tbl.getElementsByTagName("td");
		
		for(n=0;i<tds.length;n++) {
			
			td = tds[n];
			
			if (!td) { break; }
			
			td.onmouseover = highlightColumn;
			td.onmouseout = highlightColumn;
			td.columnIndex = n;
			
		}		
		
	}
	
}

