// <![CDATA[

// Base icon for custom markers
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = null; // due to dense markers
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

//
var p = [];
var gm = [];
var i = 0;

function createSimpleNameMarker(point, name) {
	markerOptions = {
		title : name
	};
	var marker = new GMarker(point, markerOptions);
	var html = '<table height="100%" align="center"><tr><td><big><b><span style="color: #000000;">'
			+ name + '</span></b></big></td></tr></table>';
	// maxWidth needed for IE to avoid massively wide info window
	infoWindowOpts = {
		maxWidth : 250
	};
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html, infoWindowOpts);
	});
	return marker;
}

function createSimpleTrackedPropertyMarker(point, name) {
	markerOptions = {
		title : name
	};
	var marker = new GMarker(point, markerOptions);
	var html = '<table height="100%" align="center"><tr><td><big><b><span style="color: #000000;">'
			+ name + '</span></b></big></td></tr></table>';
	// maxWidth needed for IE to avoid massively wide info window
	infoWindowOpts = {
		maxWidth : 250
	};
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html, infoWindowOpts);
	});
	gm[i] = marker;
	p[i] = point;
	i++;
	return marker;
}

/**
 * Creates a marker with numbered icon and with html including an image.
 * 
 * @param point
 * @param index
 * @param markerpath
 * @param name
 * @param image
 * @param type
 * @return
 */
function createPropertyMarker3(point, index, markerpath, name, image, type,
		cost, perPperN) {
	var nicon = new GIcon(baseIcon);
	nicon.image = markerpath + 'marker' + index + '.png';
	markerOptions = {
		icon : nicon,
		title : name
	};
	var marker = new GMarker(point, markerOptions);
	var html = '<table class="centered bold"><tr><td><big><span style="color: #000000;">'
			+ index
			+ '. </span><span style="color: #000000;">'
			+ name
			+ '</span></big></td></tr>';
	if (cost != null && cost != '') {
		html += '<tr><td><span style="color: #333333;font-size: 13px;">' + cost
				+ ' ' + perPperN + '</span></td></tr>';
	}
	html += '<tr><td><img src="'
			+ image
			+ '" width="190" height="120" style="border: 1px solid #666" /></td></tr>'
			+ '<tr><td><span style="color: #333333;font-size: 13px;">' + type
			+ '</span></td></tr>';

	// maxWidth needed for IE to avoid massively wide info window
	infoWindowOpts = {
		maxWidth : 250
	};
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html, infoWindowOpts);
	});
	gm[i] = marker;
	p[i] = point;
	i++;
	return marker;
}
function createRegionMarker(point, image, name, qty) {
	var marker = new GMarker(point);
	var html = '<table width="100%"><tr><td rowspan="2"><img src="'
			+ image
			+ '" width="105" height="125" style="border: 1px solid #666" /></td><td height="60" class="bottom"><big><span style="color: #000000;">'
			+ name + '</span></big></td></tr><tr><td class="top" height="60">'
			+ qty + '</td></tr></table>';
	infoWindowOpts = {
		maxWidth : 250
	};
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html, infoWindowOpts);
	});
	return marker;
}
function createRegionMarker2(point, image, name, qty) {
	var marker = new GMarker(point);
	var html = '<table width="100px"><tr><td><img src="'
			+ image
			+ '" width="105" height="125" style="border: 1px solid #666" /></td></tr><tr><td class="bottom"><big><span style="color: #000000;font-size: 14px;">'
			+ name + '</span></big></td></tr></table>';
	html = '<p align="center"><img src="'
			+ image
			+ '" width="105" height="125" style="border: 1px solid #666" /><br/><br/><big>'
			+ name + '</big></p>';
	infoWindowOpts = {
		maxWidth : 100
	};
	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html, infoWindowOpts);
	});
	return marker;
}
/**
 * Fits the map according to the points within the point array, p.
 * 
 * @return
 */
function fitmap() {
	if (map && p) {
		var bounds = new GLatLngBounds();
		for ( var j = 0; j < p.length; j++) {
			if (p[j] != null) {
				bounds.extend(p[j]);
			}
		}
		var zoom = map.getBoundsZoomLevel(bounds);
		map.setZoom(zoom < 15 ? zoom : 15);
		map.setCenter(bounds.getCenter());
	}
}
/**
 * Centers map on the given point within the point array, p. And zooms in.
 * 
 * @param i
 * @return
 */
function zoomIcn(i) {
	if (p && p[i] && map) {
		map.setCenter(p[i], map.getZoom() < 15 ? 15 : map.getZoom());
		if (gm[i]) {
			gm[i].show();
			gm[i]
					.openInfoWindowHtml('<div style="text-align: center;margin-top: 20px;font-size: 16px;color: #000000;">'
							+ gm[i].getTitle() + '</div>');
		}
	}
}

function showArea(area) {
	if (!map) {
		return;
	}
	map.setMapType(G_NORMAL_MAP);
	if (area == 'NISEKO') {
		map.setCenter(new GLatLng(42.8720738755, 140.679567352), 12);
	} else if (area == 'NISEKO_HIRAFU') {
		map.setCenter(new GLatLng(42.858, 140.706), 14);
	} else if (area == 'NISEKO_ANNUPURI') {
		map.setCenter(new GLatLng(42.848, 140.645), 14)
	} else if (area == 'NISEKO_HANAZONO') {
		map.setCenter(new GLatLng(42.89783, 140.70055), 14)
	} else if (area == 'TOKYO') {
		map.setCenter(new GLatLng(35.6903121018, 139.692322742), 8)
	} else if (area == 'TOKYO_CITY') {
		map.setCenter(new GLatLng(35.6903121018, 139.692322742), 8)
	} else if (area == 'TOKYO_NARITA') {
		map.setCenter(new GLatLng(35.78, 140.34), 12)
	} else if (area == 'SAPPORO') {
		map.setCenter(new GLatLng(43.068626685, 141.350791938), 11)
	} else if (area == 'SAPPORO_CITY') {
		map.setCenter(new GLatLng(43.068626685, 141.350791938), 11)
	} else if (area == 'SAPPORO_CHITOSE') {
		map.setCenter(new GLatLng(42.7785055012, 141.693693051), 11)
	} else if (area == 'FURANO') {
		map.setCenter(new GLatLng(43.344175, 142.367177), 12)
	} else if (area == 'FURANO_MOUNTAIN') {
		map.setCenter(new GLatLng(43.344175, 142.367177), 12)
	} else if (area == 'FURANO_TOWN') {
		map.setCenter(new GLatLng(43.344175, 142.367177), 12)
	} else if (area == 'ASAHIDAKE') {
		map.setCenter(new GLatLng(43.652601, 142.797586), 12)
	} else if (area == 'HAKUBA') {
		map.setCenter(new GLatLng(36.701296, 137.839143), 12)
	} else if (area == 'QUEENSTOWN') {
		map.setCenter(new GLatLng(-45.030931, 168.662726), 12)
	} else if (area == 'METHVEN') {
		map.setCenter(new GLatLng(-43.632939, 171.647174), 12)
	} else if (area == 'WANAKA') {
		map.setCenter(new GLatLng(-44.698314, 169.132568), 12)
	} else if (area == 'CARDRONA') {
		map.setCenter(new GLatLng(-44.876719, 169.006741), 12)
	} else if (area == 'CANTERBURYHIGHLANDS') {
		map.setCenter(new GLatLng(-43.335598, 171.927857), 10)
	} else if (area == 'CANTERBURYHIGHLANDS_SPRINGFIELD') {
		map.setCenter(new GLatLng(-43.335598, 171.927857), 12)
	} else if (area == 'PORTILLO') {
		map.setCenter(new GLatLng(-32.835751, -70.13144), 12)
	} else if (area == 'TERMASDECHILLAN') {
		map.setCenter(new GLatLng(-36.903235, -71.412163), 12)
	} else if (area == 'TERMASDECHILLAN_LASTRANCAS') {
		map.setCenter(new GLatLng(-36.912294, -71.485248), 12)
	} else if (area == 'TRESVALLE') {
		map.setCenter(new GLatLng(-33.348777, -70.301471), 12)
	} else if (area == 'TRESVALLE_VALLENEVADO') {
		map.setCenter(new GLatLng(-33.354334, -70.251603), 12)
	} else if (area == 'TRESVALLE_ELCOLORADO') {
		map.setCenter(new GLatLng(-33.345479, -70.289412), 12)
	} else if (area == 'TRESVALLE_LAPARVA') {
		map.setCenter(new GLatLng(-33.329955, -70.279112), 12)
	} else if (area == 'TRESVALLE_FARELLONES') {
		map.setCenter(new GLatLng(-33.352362, -70.309882), 12)
	} else if (area == 'SANTIAGO') {
		map.setCenter(new GLatLng(-33.439177, -70.638657), 12)
	} else if (area == 'LOSANDES') {
		map.setCenter(new GLatLng(-32.835462, -70.599174), 12)
	} else {
		// Unknown... show Japan view
		map.setCenter(new GLatLng(42.8725, 140.666), 4);
	}
}
// ]]>

