//<![CDATA[
if(GBrowserIsCompatible()){
	var gmarkers = [];
	var map;
	// Display the map, with some controls and set the initial location 
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	//map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	//map.enableScrollWheelZoom();
	map.setCenter(new GLatLng(40.580584, -96.855468),3);
	var img_path = document.getElementById('gm_image_path').value;
	function createMarker(point,html,item_id,icon) {
		var marker = new GMarker(point,icon);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html,item_id);
			var sel_item = document.getElementById("sel_item").value;
			if(sel_item>0 && sel_item!=item_id) {
				var selected_listing = document.getElementById("listing_"+sel_item);
				if(selected_listing) {
					selected_listing.style.borderColor = "";
					selected_listing.style.borderStyle = "";
					selected_listing.style.borderWidth = "";
					//selected_listing.getElementsByTagName("table")[0].style.border = "";
					document.getElementById("table_listing_"+sel_item).style.border = "none";
					document.getElementById("listingMapTab_"+sel_item).style.display = "";
					
				}
			}
			document.getElementById("sel_item").value = item_id;
			
			//document.getElementById("listing_"+item_id).getElementsByTagName("table")[0].style.border = "2px solid #6A97C1";
			document.getElementById("table_listing_"+item_id).style.border = "2px solid #6A97C1";
			document.getElementById("table_listing_"+item_id).style.padding = "5px";
			document.getElementById("listingMapTab_"+item_id).style.display = "block";
			
			var isInternetExplorer = (navigator.appName.indexOf("Microsoft") != -1);			
			if(isInternetExplorer) diff = 10; else diff = 320;			
			y = document.getElementById("table_listing_"+item_id).offsetTop;			
			document.getElementById('div_search').scrollTop= y - diff;
			
			//var c = document.getElementById("div_search");
			//var pos = document.getElementById("listing_"+item_id).positionedOffset();
			//num_aux = parseFloat(document.getElementById('map_height').value)-225;
			//alert('Now:'+c.scrollTop+' ----- Total:'+c.scrollHeight+' ---- go to:'+(pos[1]-(400+num_aux))+'  map:'+num_aux);
			//c.scrollTop = (pos[1]-(400+num_aux));
			//document.location.hash = "listing_"+item_id;
		});
		gmarkers[item_id] = marker;
		return marker;
	}
	// This function gets the coord. of the location (state and city)
	function SearchPoint(location,type){
		var pointF,zoomlevel;
		var geoAux = new GClientGeocoder();
		geoAux.getLatLng(location,function(point) {
			if(point) {
				pointF = point.toString().replace(")"," ");
				pointF = pointF.replace("("," ");
				var spStr=pointF.split(",");
				if(type==1) zoomlevel = 12; else zoomlevel = 6;
				map.setCenter(new GLatLng(spStr[0],spStr[1]),zoomlevel);
			}
		})
	}
	// This function picks up the click and opens the corresponding info window
	function myclick(item_id) {
		if(gmarkers[item_id])GEvent.trigger(gmarkers[item_id], "click");
		else alert("Google Map is not available for the current address.")
	}
	function addListing(location, box_html, listing_id, listing_level) {
		var icon = new GIcon();
		if(listing_level == 70) {
			icon.image				= img_path+'/map_icon_premium.png';
			icon.shadow				= img_path+'/map_icon_premium-shadow.png';
			icon.iconSize			= new GSize(37.0, 65.0);
			icon.shadowSize			= new GSize(70.0, 65.0);
			icon.iconAnchor			= new GPoint(18.0, 32.0);
			icon.infoWindowAnchor	= new GPoint(18.0, 32.0);
		} else if(listing_level == 50) {
			icon.image				= img_path+'/map_icon_enhanced.png';
			icon.shadow				= img_path+'/map_icon_enhanced-shadow.png';
			icon.iconSize			= new GSize(31.0, 55.0);
			icon.shadowSize			= new GSize(59.0, 55.0);
			icon.iconAnchor			= new GPoint(15.0, 27.0);
			icon.infoWindowAnchor	= new GPoint(15.0, 27.0);
		} else {
			icon.image				= img_path+'/map_icon_basic.png';
			icon.shadow				= img_path+'/map_icon_basic-shadow.png';
			icon.iconSize			= new GSize(25.0, 45.0);
			icon.shadowSize			= new GSize(48.0, 45.0);
			icon.iconAnchor			= new GPoint(12.0, 22.0);
			icon.infoWindowAnchor	= new GPoint(12.0, 22.0);
		}
		var geo = new GClientGeocoder();
		geo.getLatLng(location,function(point) {
			if(point) {
				var marker = createMarker(point,box_html,listing_id,icon); 
				map.addOverlay(marker); 
				//map.setCenter(point,5);
			}
		});
	}
} else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}//]]>
var isInternetExplorer=(navigator.appName.indexOf("Microsoft") != -1);
function expandMap(){	
	num_aux=parseFloat(document.getElementById('map_height').value)+100;	
	if(num_aux==625)document.getElementById('expandMap').innerHTML='Expand Map';
	document.getElementById('shrinkMap').innerHTML='<a href="javascript:void(0);" onclick="shrinkMap();">Shrink Map</a>';
	if(num_aux<=625){
		document.getElementById('map_height').value=num_aux;
		var mapObj = document.getElementById('map');		
		if(isInternetExplorer) mapObj.style.height=num_aux;		
		else mapObj.style.height=num_aux+"px";
	}	
}
function shrinkMap(){
	num_aux=parseFloat(document.getElementById('map_height').value)-100;
	if(num_aux==225)document.getElementById('shrinkMap').innerHTML='Shrink Map';
	document.getElementById('expandMap').innerHTML='<a href="javascript:void(0);" onclick="expandMap();">Expand Map</a>';
	if(num_aux>=225){
		mapObj = document.getElementById('map');
		document.getElementById('map_height').value=num_aux;
		if(isInternetExplorer) mapObj.style.height=num_aux;
		else mapObj.style.height=num_aux+"px";
	}
}

function expandDiv(){	
	num_aux=parseFloat(document.getElementById('div_height').value)+200;	
	if(num_aux==1520)document.getElementById('expandDiv').innerHTML='Enlarge Results Pane';
	document.getElementById('shrinkDiv').innerHTML='<a href="javascript:void(0);" onclick="shrinkDiv();">Shrink Results Pane</a>';
	if(num_aux<=1520){		
		document.getElementById('div_height').value=num_aux;
		var divObj = document.getElementById('div_search');	
		if(isInternetExplorer) divObj.style.height=num_aux;		
		else divObj.style.height=num_aux+"px";
	} 		
}

function shrinkDiv(){
	num_aux=parseFloat(document.getElementById('div_height').value)-200;
	if(num_aux==320)document.getElementById('shrinkDiv').innerHTML='Shrink Results Pane';
	document.getElementById('expandDiv').innerHTML='<a href="javascript:void(0);" onclick="expandDiv();">Enlarge Results Pane</a>';
	if(num_aux>=320){
		divObj = document.getElementById('div_search');
		document.getElementById('div_height').value=num_aux;
		if(isInternetExplorer) divObj.style.height=num_aux;
		else divObj.style.height=num_aux+"px";
	}	
}