﻿//<![CDATA[
var map;
var bounds;
var lat;
var lng;
var point;
var html;
var label;

var myIcon = new GIcon();
myIcon.image = "http://d3oc9cjcc60qxw.cloudfront.net/images/pages/search-results/google-marker.png";
myIcon.iconSize = new GSize(16, 14);
myIcon.shadowSize = new GSize(20, 17);
myIcon.iconAnchor = new GPoint(5, 14);
myIcon.infoWindowAnchor = new GPoint(7, 4);



	var map = new GMap2(document.getElementById("gmap"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(0, 0), 0);
	var side_bar_html = "";
	var gmarkers = [];
	var htmls = [];
	var i = 0;

	function createMarker(point, name, html) {
		var marker = new GMarker(point, myIcon);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		gmarkers[i] = marker;
		htmls[i] = html;
		i++;
		return marker;
	}

	function showgooglemarker(i) {
		if (map.getInfoWindow().isHidden() || map.getInfoWindow().getPoint() != gmarkers[i].getPoint()) {
			if (gmarkers[i] == null) {
				return;
			}
			gmarkers[i].openInfoWindowHtml(htmls[i]);
			map.getInfoWindow().show();
		}
	}

	// ===== Start with an empty GLatLngBounds object =====     
	var bounds = new GLatLngBounds();

//]]>

function load() {
	//Use this function for map loading functionality
	var d;
	d = null;
	eval("d = document.getElementById('gmap')");
	if (d == null)
		return;
}

function pushPin(latitude, longitude, listingid, city, state, thumbnail, propertytype, price, sqft, beds, baths, isgeocity) {
	lat = parseFloat(latitude); lng = parseFloat(longitude);
	point = new GLatLng(lat, lng);
	htmlSQFT = '';
	htmlBB = '';
	if (sqft != '') {
		htmlSQFT = '<b>' + sqft + '</b> Sq. Ft.<br />';
	}
	if (beds > 0 || baths > 0) {
		htmlBB = '<b>' + beds + '</b> Bed / <b>' + baths + '</b> Bath<br />';
	}
	var url = '/' + state + '/' + city.replace(" ", "-") + '/' + listingid + '/';
	html = '<div style="width:250px;font-size:12px;"><div style="float:left"><div style="border: 1px solid black;width:76px;">' +
				 '<img style="border:0;" width="76" height="56" src="'+thumbnail+'" alt=""/>' +
				 '</div><div style="font-weight:bold;width:76px;color:#04336b;border-bottom:1px solid black;text-align:center;border-left:1px solid black;border-right:1px solid black;background-color:#d9e6f6;">' +
				 price + '</div></div><div style="float:left;font-family:Arial; padding-left:10px;">' +
				 '<div style="color:#04336b;font-weight:bold;padding-bottom:5px;">' + propertytype + '<br />';
	html += city + ', ' + state;
	html += '</div>' +
				 '<div style="font-size:12px;">' + htmlSQFT + htmlBB + '</div></div></div>';
	label = 'Listing ' + listingid + ' on Owners.com';
	var marker = createMarker(point, label, html);

	map.addOverlay(marker);
	bounds.extend(point);
	if (isgeocity) {
		map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds) - 1);
	}
	else {
		map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
	}
}
