﻿// scripts/maps.js
// Copyright © AllTravels™ - All Rights Reserved

/*---------------------------------------------------------------------------------------*/
// Custom mouse cursors
// We've introduced new GMapOptions that allow you to set custom mouse cursors for the map.
// For example, if you prefer a pointer cursor (instead of the hand cursor) but want a crosshair cursor for when the map is being dragged, initialize the map using this call: 
// var map = new GMap2(document.getElementById("mapelement"), {draggableCursor: 'crosshair', draggingCursor: 'pointer'});
// We've also added GDraggableObject, which lets you set custom cursors for any draggable object, such as the slider in the zoom control and the overview map.

/*---------------------------------------------------------------------------------------*/
// DragZoomControl()
// DragZoomControl(opts_boxStyle,  opts_other,  opts_callbacks )
//var boxStyleOptions = { opacity: .2, fillColor: '#000', border: '2px solid yellow' };
//var otherOptions = { buttonHTML: 'Drag Zoom', backButtonEnabled: true};
//map.addControl(new DragZoomControl(boxStyleOptions, otherOptions), topLeftSub);

/*---------------------------------------------------------------------------------------*/

// GMap2.prototype.mymap = { movedByOther : false };

// window.setTimeout(function() {map.panTo(new GLatLng(37.4569, -122.1569));}, 1000);

// GLatLng.distanceFrom(latlng)
// Returns the distance expressed in metres from the specified location.
// getLatLng()
// Returns the geographical coordinates at which this marker is anchored

//GEvent.addListener(newMarker, 'dragend', function() {});
// map.closeInfoWindow();
// newMarker.openInfoWindowHtml(map.getCenter().toUrlValue());
// GLog.writeHtml("<b>HTML</b> message<br/>in two lines.");

// <meta name="geo.position" content="45.4339291098716;12.3427641391754" />

/*---------------------------------------------------------------------------------------*/
// GPolygon(latlngs, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?, opts?)
// Creates a polygon from an array of vertices. The colors are given as a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB.
// The weight is the width of the line in pixels. The opacities is given as a number between 0 and 1. The line will be antialiased and semitransparent.

/*---------------------------------------------------------------------------------------*/
// === This function picks up the click and opens the corresponding info window ===
/*
function myclick(i) {
	GEvent.trigger(gmarkers[i], "click");
}
*/
// It's also possible to use the GEvent system to pass messages between different parts of your own code with custom events.
// Simply use GEvent.addListener(marker, "myevent") to listen for the event and GEvent.trigger(marker, "myevent") to trigger it. You can pass up to two parameters.

/*---------------------------------------------------------------------------------------*/
// geocoder = new GClientGeocoder();

/*---------------------------------------------------------------------------------------*/
// GDownloadUrl(url, onload, postBody?, postContentType?)
// Retrieves the resource from the given URL and calls the onload function with the text of the document as first argument, and the HTTP response status code as the second.
// If the request times out, the onload function may be called instead with null as the first argument and -1 as the second.
// This function defaults to sending an HTTP GET request. To send an HTTP POST request instead, pass data within the optional postBody argument.
// If the data being sent is not of type "application/x-www-form-urlencoded," pass the content type as a string in the postContentType argument.
// This method is subject to cross-site scripting restrictions. Note that this method uses the underlying XmlHttpRequest implementation of the browser.

/*---------------------------------------------------------------------------------------*/
// set center and viewport depending on parameters passed to function

// map types below can use either zoomLevel or boundingBox
// var viewportType = typeOf (viewportDetails)

// map.setCenter(boundingBox.getCenter(), map.getBoundsZoomLevel(boundingBox));
// or
// var centerPoint = new GLatLng(detailLat, detailLong);
// map.setCenter(centerPoint, zoomLevel);		


/*---------------------------------------------------------------------------------------*/
// set up icons
// At a minimum, an icon must define the foreground image, the size of type GSize, and an icon offset to position the icon.
var iconBlue = new GIcon();
iconBlue.image = 'http://www.alltravels.com/images/common/icons/maps/mm_20_blue.png';
iconBlue.shadow = 'http://www.alltravels.com/images/common/icons/maps/mm_20_shadow.png';
iconBlue.iconSize = new GSize(12, 20);
iconBlue.shadowSize = new GSize(22, 20);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);

var iconRed = new GIcon();
iconRed.image = 'http://www.alltravels.com/images/common/icons/maps/mm_20_red.png';
iconRed.shadow = 'http://www.alltravels.com/images/common/icons/maps/mm_20_shadow.png';
iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
// iconAnchor is the pixel which will be placed on the specified location. You can think of it as the point that the image points at.
iconRed.infoWindowAnchor = new GPoint(5, 1);
// infoWindowAnchor is the pixel that the tip of the info Window stem will touch

var panoramioIcon = new GIcon();
panoramioIcon.image = "http://www.alltravels.com/images/common/icons/maps/panoramio-marker.png";
panoramioIcon.shadow = "http://www.alltravels.com/images/common/icons/maps/panoramio-shadow.png";
panoramioIcon.iconSize = new GSize(18, 18);
panoramioIcon.shadowSize = new GSize(22, 22);
panoramioIcon.iconAnchor = new GPoint(9, 9);
panoramioIcon.infoWindowAnchor = new GPoint(9, 0);

var hotelIcon = new GIcon();
hotelIcon.image = "http://www.alltravels.com/images/common/icons/maps/hotel.png";
hotelIcon.iconSize = new GSize(16, 16);
hotelIcon.iconAnchor = new GPoint(8, 8);

var airportIcon = new GIcon();
airportIcon.image = "http://www.alltravels.com/images/common/icons/maps/airport.png";
airportIcon.iconSize = new GSize(16, 16);
airportIcon.iconAnchor = new GPoint(8, 8);

var carentalIcon = new GIcon();
carentalIcon.image = "http://www.alltravels.com/images/common/icons/maps/carental.png";
carentalIcon.iconSize = new GSize(16, 16);
carentalIcon.iconAnchor = new GPoint(8, 8);

var webcamIcon = new GIcon();
webcamIcon.image = "http://www.alltravels.com/images/common/icons/maps/webcam.png";
webcamIcon.iconSize = new GSize(16, 16);
webcamIcon.iconAnchor = new GPoint(8, 8);

/*---------------------------------------------------------------------------------------*/
// set up custom icons array
var customIcons = [];
//customIcons['country'] = iconBlue;
//customIcons['admin'] = iconRed;
//customIcons['destination'] = iconRed;

customIcons['hotel'] = hotelIcon;
customIcons['airport'] = airportIcon;
customIcons['carental'] = carentalIcon;
customIcons['webcam'] = webcamIcon;
customIcons['weather'] = panoramioIcon;
//customIcons['tour'] = iconRed;

/*---------------------------------------------------------------------------------------*/
// set up marker options array
// {icon: customIcons[productType], draggable: true, dragCrossMove: true, bounceGravity: 0.4, title: markerTitle};
var markerOptions = [];
//markerOptions['country'] = {};
//markerOptions['admin'] = {};
//markerOptions['destination'] = {};

markerOptions['hotel'] = {};
markerOptions['airport'] = {};
markerOptions['carental'] = {};
markerOptions['webcam'] = {};
markerOptions['weather'] = {};
//markerOptions['tour'] = {};

/*---------------------------------------------------------------------------------------*/
// set up markers array
var gMarkers = [];
//gMarkers['country'] = [];
//gMarkers['admin'] = [];
//gMarkers['destination'] = [];

gMarkers['hotel'] = [];
gMarkers['airport'] = [];
gMarkers['carental'] = [];
gMarkers['webcam'] = [];
gMarkers['weather'] = [];
//gMarkers['tour'] = [];

/*---------------------------------------------------------------------------------------*/
// set up gLayers array
// class GLayer instantiates a predefined "layer" overlay consisting of a collection of related items

var gLayers = [];
//gLayers['wikipedia_en'] = new GLayer('org.wikipedia.en');
//gLayers['panoramio_pop'] = new GLayer('com.panoramio.popular');
//gLayers['panoramio_all'] = new GLayer('com.panoramio.all');
// map.addOverlay(new GLayer('com.google.webcams'));

/*---------------------------------------------------------------------------------------*/
// define standard control positions
var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
var topLeftSub = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,60));
var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,5));
var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10,40));
var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(3,3));
var bottomRightAbove = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(3,27));

/*---------------------------------------------------------------------------------------*/
// initiate global map objects

// main map
var mainMapWrapper = document.getElementById('mainmapcont');

var mainMapContainer = document.getElementById('mainmap'); // TODO: should be 'mainmapcont' ??

var map;
//var mainMap; ??
// markermanager.js seems to rely on 'map'

//var markerManagers = [];

// second map
var map2
// map2 = new GMap2(document.getElementById("map2"));


/*---------------------------------------------------------------------------------------*/
// function init_mainmap()
// set up all generic stuff for different map functions below

// 'mainMapContainer' is already global
// 'map' is already global

// TODO: will be used by all mainMaps
// map controls to be set up by calling map type functions

// TODO: needs to accept more parameters from map type function calls

function init_mainmap(mapWidth, mapHeight) { // viewportDetails
	
	/*---------------------------------------------------------------------------------------*/
	// currently size is set by css in screen.css or in head editable region
	// will be 1x1 px by default ??
	
	//mainMapContainer.style.width = mapWidth + 'px';
	//mainMapContainer.style.height = mapHeight + 'px';
	
	/*---------------------------------------------------------------------------------------*/
	
	map = new google.maps.Map2(mainMapContainer);
	
	/*---------------------------------------------------------------------------------------*/
	// map properties
	
	map.setMapType(G_HYBRID_MAP);
	
	/*---------------------------------------------------------------------------------------*/
	// map methods
	
	// map.enableRotation();
	
	// map.enableContinuousZoom(); ??
	
	// map.enableGoogleBar(); ??		
	
	/*---------------------------------------------------------------------------------------*/
	// set up markerManagers ??
	
	//markerManagers[] = new MarkerManager(map, markerManagerOptions);
	//or
	//var markerManager = new MarkerManager(map, markerManagerOptions);
	
	/*---------------------------------------------------------------------------------------*/
	// listeners for map drag/zoom
	// if admin logged in need to be able to update database(s)
	
	// GEvent.addListener(map, "moveend", mapHandler);
	
	/*GEvent.addListener(map, 'moveend', function() {
												var newCenterPoint = map.getCenter();
												var boundingBox = map.getBounds();
												var southWestPoint = boundingBox.getSouthWest();
												var northEastPoint = boundingBox.getNorthEast();
												var coordsString = southWestPoint.toUrlValue() + ':' + northEastPoint.toUrlValue();
												//document.getElementById('boundingboxdetails').value = coordsString;
												}
												);*/
	
	// 'zoomend' event is fired when the map reaches a new zoom level.
	// the event handler receives the previous and the new zoom level as arguments. (oldLevel, newLevel)
	// map.getZoom() may be more portable
	/*GEvent.addListener(map, 'zoomend', function(oldLevel, newLevel) {
												//document.getElementById('zoomleveldetails').value = newLevel; // map.getZoom()
												}
												);*/
		
	/*---------------------------------------------------------------------------------------*/
	
}


/*---------------------------------------------------------------------------------------*/
// function load_home_map()
// used by site home page
function load_home_map() {
	
	init_mainmap(540, 320);
	
	var centerPoint = new GLatLng(23, 157);
	
	map.setCenter(centerPoint, 1);
	
	map.disableDragging();
	
}

/*---------------------------------------------------------------------------------------*/
// function load_index_map()
// used by product section index pages

// TODO: change to use toggle_markers_mainmap(productType, checkedValue)

function load_index_map(productType) { // mapWidth, mapHeight
	
	load_home_map();
	
	//toggle_markers_mainmap(productType, true);
	
	switch (productType) {
		
		case 'accomodation':
		document.getElementById('hotelmarkers').checked = true;
		show_hotel_markers(1, 'global');
		break;
		
		case 'airports':
		document.getElementById('airportmarkers').checked = true;
		show_airport_markers(1, 'global');
		break;
		
		case 'photos':
		//resize_mainmap(600, 400);
		toggle_gLayer('panoramio_all', true);
		map.enableDragging();
		break;
		
		case 'webcams':
		document.getElementById('webcammarkers').checked = true;
		show_webcam_markers(1, 'global');
		break;		
		
	}
	
}


/*---------------------------------------------------------------------------------------*/
// function load_full_map()
// used by place level pages

function load_full_map(centerLat, centerLong, southWestLat, southWestLong, northEastLat, northEastLong, hasShapedata) {
	
	/*---------------------------------------------------------------------------------------*/
	// resize map container ??
	// default is 1px by 1px with trans.png
	//mainMapContainer.style.width = '640px';
	//mainMapContainer.style.height = '380px';
	
	/*---------------------------------------------------------------------------------------*/
	// append and display xtramapcontrols
	var xtramapcontrols = document.getElementById('xtramapcontrols');
	
	document.getElementById('mainmapcont').appendChild(xtramapcontrols);
	
	xtramapcontrols.style.visibility = 'visible';
	
	/*---------------------------------------------------------------------------------------*/
	
	map = new google.maps.Map2(mainMapContainer);
	
	/*---------------------------------------------------------------------------------------*/
	
	// define the two corners of the bounding box
	// southWestLat, southWestLong
	var southWestCorner = new GLatLng(southWestLat, southWestLong);
	// northEastLat, northEastLong
	var northEastCorner = new GLatLng(northEastLat, northEastLong);
	// create the bounding box
	var boundingBox = new GLatLngBounds(southWestCorner, northEastCorner);
	
	// center map in the center of the bounding box and calculate the appropriate zoom level
	map.setCenter(boundingBox.getCenter(), map.getBoundsZoomLevel(boundingBox));
	
	/*---------------------------------------------------------------------------------------*/
	map.setMapType(G_HYBRID_MAP);
	
	map.enableRotation();
			
	/*---------------------------------------------------------------------------------------*/
	// add zoom control
	map.addControl(new GLargeMapControl3D(), topLeft);
	
	//map.enableDoubleClickZoom();
	// this is default ??
	
	//map.enableScrollWheelZoom();
	// use function toggle_zoom() instead ?
	
	/*---------------------------------------------------------------------------------------*/
	// GMapTypeControl()
	//map.removeMapType(G_NORMAL_MAP);
	map.addControl(new GMapTypeControl(), topRight);
	
	/*---------------------------------------------------------------------------------------*/
	// add scale indicator
	map.addControl(new GScaleControl(), bottomLeft);
	
	/*---------------------------------------------------------------------------------------*/
	// GOverviewMapControl()
	var overviewMap = new GOverviewMapControl(new GSize(200,150));
	overviewMap.setMapType(G_HYBRID_MAP);
	map.addControl(overviewMap); // , topLeft
	
	// You can capture the "maptypechanged" event and set the maptype in your eventhandler
	// overviewMap.setMapType(G_NORMAL_MAP);
	
	/*---------------------------------------------------------------------------------------*/
	
	// geocoder = new GClientGeocoder();
			
	/*---------------------------------------------------------------------------------------*/
	
}


/*---------------------------------------------------------------------------------------*/
// function load_small_map()
// loads a small map
// currently only for secondary map (map2)

// TODO: receives object literal
// parseObj ??

// TODO: with icons for a particular product type

// used by 

// destination product pages
// 'accommodation'
// 'airports'

// create detail hotel
// 'hotel'

// create detail airport
// 'airport'

function load_small_map(productType, centerLat, centerLong, southWestLat, southWestLong, northEastLat, northEastLong, hasShapedata) {
	
	map2 = new GMap2(document.getElementById('smallmap'));
	
	// define the two corners of the bounding box
	var southWestCorner = new GLatLng(southWestLat, southWestLong);
	var northEastCorner = new GLatLng(northEastLat, northEastLong);
	
	// create the bounding box
	var boundingBox = new GLatLngBounds(southWestCorner, northEastCorner);
	
	// center map in the center of the bounding box and calculate the appropriate zoom level
	map2.setCenter(boundingBox.getCenter(), map2.getBoundsZoomLevel(boundingBox));
	
	map2.setMapType(G_HYBRID_MAP);	
	
	map2.enableRotation();
	
	
	// add controls
	
	map2.addControl(new GSmallZoomControl3D(), topLeft);
	//map.addControl(new GLargeMapControl3D(), topLeft);	
	
	map2.addControl(new GScaleControl(), topRight);
	
	map2.addControl(new GMapTypeControl(), bottomRight);
	
	
	
	// if (productType == 'accommodation')
	// get product markers from mainmap 'map'
	
	var requiredMarkers = gMarkers['hotel'];
	
	//console.log(requiredMarkers);
	
	//for (var x=0; x <= requiredMarkers.length; x++) {
	for (var x in requiredMarkers) {
		
		//console.log(requiredMarkers[x]);
		
		// boundingBox.extend(latlng);
		// map.setZoom(map.getBoundsZoomLevel(boundingBox));
		// map.setCenter(boundingBox.getCenter());
		
		//map2.addOverlay(requiredMarkers[x]);
		
	}
	
	
	
}


/*---------------------------------------------------------------------------------------*/
// function load_area_map()
// used by product detail pages
// eg. hotel, airport, webcam, weather

function load_area_map(detailType, detailLat, detailLong, zoomLevel, detailName) {
	
	// TODO: init_mainmap(x, y);
	
	map = new google.maps.Map2(mainMapContainer);
	
	var centerPoint = new GLatLng(detailLat, detailLong);
	
	map.setCenter(centerPoint, zoomLevel);
	
	/*---------------------------------------------------------------------------------------*/
	map.setMapType(G_HYBRID_MAP);
	
	map.enableRotation();
	
	/*---------------------------------------------------------------------------------------*/
	// add zoom control
	map.addControl(new GSmallZoomControl3D(), topLeft);
	//map.addControl(new GLargeMapControl3D(), topLeft);
	
	// add map type control
	map.addControl(new GMapTypeControl(), bottomRight);
	
	// add scale indicator
	map.addControl(new GScaleControl(), topRight);
			
	// set main icon, no action onclick
	var markerOption = {icon: customIcons[detailType], title: detailName};
	
	var newMarker = new GMarker(centerPoint, markerOption);
	// TODO: use big icons, change size of icon to 32x32
	// TODO: cursor not hand onmouseover
	// newMarker.iconSize = new GSize(12, 20);
	map.addOverlay(newMarker);
	
	// TODO: get bounding box
	// search for and display anything else of interest in the area
	// at this level = nearby hotels, cams, restauraunts
	
}

/*---------------------------------------------------------------------------------------*/
// function load_detail_map()
// can be used to add a second map
// used by ajax pages
// airport

function load_detail_map(detailType, detailName, detailLat, detailLong, southWestLat, southWestLong, northEastLat, northEastLong, hasShapedata) {
	
	// move detailmapcontainer to detailmaptarget.innerHTML
	// display.block('detailmapcontainer');
	
	//detailMap = new GMap2(detailmapcontainer);
	detailMap = new google.maps.Map2(detailmapcontainer);
	
	// define the two corners of the bounding box
	// southWestLat, southWestLong
	var southWestCorner = new GLatLng(southWestLat, southWestLong);
	// northEastLat, northEastLong
	var northEastCorner = new GLatLng(northEastLat, northEastLong);
	// create the bounding box
	var boundingBox = new GLatLngBounds(southWestCorner, northEastCorner);
	
	// center map in the center of the bounding box and calculate the appropriate zoom level
	detailMap.setCenter(boundingBox.getCenter(), detailMap.getBoundsZoomLevel(boundingBox));
	
	/*---------------------------------------------------------------------------------------*/
	detailMap.setMapType(G_HYBRID_MAP);
	
	detailMap.enableRotation();		
	
	/*---------------------------------------------------------------------------------------*/
	// add zoom control
	detailMap.addControl(new GSmallZoomControl3D(), topLeft);
	//detailMap.addControl(new GLargeMapControl3D(), topLeft);
	
	// add map type control
	detailMap.addControl(new GMapTypeControl(), bottomRight);
	
	// add scale indicator
	detailMap.addControl(new GScaleControl(), topRight);
			
	// set main icon, no action onclick
	var markerOption = {icon: customIcons[detailType], title: detailName};
	var newMarker = new GMarker(centerPoint, markerOption);
	// TODO: use big icons, change size of icon to 32x32
	// TODO: cursor not hand onmouseover
	// newMarker.iconSize = new GSize(12, 20);
	detailMap.addOverlay(newMarker);
	
	// TODO: get bounding box
	// search for and display anything else of interest in the area
	// at this level = nearby hotels, cams, restauraunts
	
}


/*---------------------------------------------------------------------------------------*/
// function toggle_zoom()
// receives ID of button or link
// toggles ScrollWheelZoom
// changes text displayed in button or link
function toggle_zoom(trigger) {
	
	if (map.scrollWheelZoomEnabled()) {
		map.disableScrollWheelZoom();
		document.getElementById(trigger).value='Enable Scroll Wheel Zoom';
	}
	else {
		map.enableScrollWheelZoom();
		document.getElementById(trigger).value='Disable Scroll Wheel Zoom';
	}
}

// enableContinuousZoom(); ??
// Enables continuous smooth zooming for select browsers (disabled by default).

// enableDoubleClickZoom ??
// Enables double click to zoom in and out (enabled by default). Disabled by marker overlay ??


/*---------------------------------------------------------------------------------------*/
// function build_marker()
/**
 * Builds a new marker
 * @param {GLatLng} markerPoint
 * @param {string} productType
 * @param {string} markerSize
 * @param {string} markerTitle
 * @param {integer} pointId
 */

function build_marker(markerPoint, productType, markerSize, markerTitle, productId) {
	
	var markerOptions = {icon: customIcons[productType], title: markerTitle};
	// TODO: customIcons[markerSize][productType]
	
	var newMarker = new GMarker(markerPoint, markerOptions);
	
	//GEvent.addListener(newMarker, 'click', function() { alert(productId); } );
	
	GEvent.addListener(newMarker, 'click', function() {
													
													// TEMP: 
													if (productType != 'carental') {
														show_product_detail(productType, productId);
													}
													else {
														show_blowup(markerPoint, markerTitle, productId);
													}
													
										   }  //end function()
										   ); //end GEvent.addListener()
	
	return newMarker;
	
}


/*---------------------------------------------------------------------------------------*/
// function toggle_markers_mainmap()

// placeId, placeLevel already set up by site_config.php

function toggle_markers_mainmap(productType, checkedValue) {
	
	if (checkedValue) {
		
		// if required markers already exist just show them and return
		// TEMP: will need to do more when using AJAX/KML network links
		
		if (gMarkers[productType].length > 0) {
			
			//console.log(gMarkers[productType]);
			
			for (var i in gMarkers[productType]) {
				
				gMarkers[productType][i].show();
				
			}
			
			return;
			
		} //end if (gMarkers[productType])
		
		/*---------------------------------------------------------------------------------------*/
		//else create markers and append to gMarkers[productType] array
		
		show_mainmapoverlay();
		
		// TEMP: for testing overlay sizes
		//return;
		
		// TEMP:
		var markerSize = '';
		
		//gMarkers[productType] = [];
		
		var detailGeneratorUrl = set_path() + '/ajax/maps/create_markers_mainmap.php?place=' + placeId + '&level=' + placeLevel + '&type=' + productType;
		// console.log(detailGeneratorUrl);
		
		GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
													
													if (responseCode == 200) {
														
														var xmlResponse = GXml.parse(data);
														//console.log(xmlResponse);
														
														// TODO: if ()
														// parentElements[0] is undefined
														
														var parentElements = xmlResponse.getElementsByTagName('markers');
														
														var resultsCount = parentElements[0].getAttribute('resultsCount');
														//console.log(resultsCount);
														
														/*---------------------------------------------------------------------------------------*/
														
														if (resultsCount > 0) {
															
															var markersArray = xmlResponse.documentElement.getElementsByTagName('marker');
															// <marker resultId="60551" resultName="Macleay Lodge" resultLat="-33.8693911070456" resultLong="151.2253314256670" cityName="Sydney"/>
															
															for (var i = 0; i < markersArray.length; i++) {
															// for (var i in markersArray) {
															// markersArray[i].getAttribute is not a function ??
																
																/*---------------------------------------------------------------------------------------*/	
																
																var resultId = parseInt(markersArray[i].getAttribute('resultId'));
																
																/*---------------------------------------------------------------------------------------*/
																
																var resultLat = parseFloat(markersArray[i].getAttribute('resultLat'));
																
																var resultLong = parseFloat(markersArray[i].getAttribute('resultLong'));
																
																var markerPoint = new GLatLng(resultLat, resultLong);															
																
																/*---------------------------------------------------------------------------------------*/
																
																var resultName = markersArray[i].getAttribute('resultName');
																
																var destName = markersArray[i].getAttribute('destName');
																
																var markerTitle = resultName + ' : ' + destName + ' : Click here for more details about this ' + productType;
																
																/*---------------------------------------------------------------------------------------*/
																
																var newMarker = build_marker(markerPoint, productType, markerSize, markerTitle, resultId);
																
																/*---------------------------------------------------------------------------------------*/
																
																gMarkers[productType].push(newMarker);
																
																// TEMP: 
																map.addOverlay(newMarker);
																
																/*---------------------------------------------------------------------------------------*/
																
																
															} //end for (var i = 0; i < markersArray.length; i++)
															
															//console.log(gMarkers[productType]);
															
															/*---------------------------------------------------------------------------------------*/
															// TODO: 
															
															// MarkerManager
															// mgr.addMarkers(resultMarkers)
															
															// or MarkerClusterer
															// add_marker_clusterer(resultMarkers)
															
															/*---------------------------------------------------------------------------------------*/
															
															// TODO: if all above OK
															// TEMP: 
															//display_none('mainmapoverlay');
															
															setTimeout("display_none('mainmapoverlay')", 300);
															
															/*---------------------------------------------------------------------------------------*/
															
															
														} //end if (resultsCount > 0)
														
														else {
															
															// else what ?
															alert('Sorry, no results found');
															
															display_none('mainmapoverlay');
															
														}
														
														/*---------------------------------------------------------------------------------------*/
														
													} //end if (responseCode == 200)
													
													
													else if (responseCode == -1) {
														
														alert('Sorry, request timed out');
														
														display_none('mainmapoverlay');
														
														//mainmapoverlaycontent.innerHTML = '<div class="bigrednotice">Request Timed Out</div>';
														
													} //end else if (responseCode == -1)
													
													
													/*---------------------------------------------------------------------------------------*/
													
												  }  //end function(data, responseCode)
												  
												  ); //end GDownloadUrl()
		
		return;
		
	} //end if (checkedValue)
	
	/*---------------------------------------------------------------------------------------*/
	// else just hide markers for this productType
	//console.log(gMarkers[productType].length);
	
	if (gMarkers[productType].length > 0) {
		
		for (var i in gMarkers[productType]) {
			
			gMarkers[productType][i].hide();
			
		}
		
		return;
		
	} //end if (gMarkers[productType])
	
	/*---------------------------------------------------------------------------------------*/
	
}


/*---------------------------------------------------------------------------------------*/
// function toggle_GLayer()
// toggles visibility of Wikipedia, Panaramio layers
// called when user selects a checkbox, clicks a link, etc
// receives layerId for use as array key
// receives true or false - (this.checked)

// map.addOverlay(new GLayer('com.google.webcams'));

function toggle_gLayer(layerId, checkedValue) {
	
	if (checkedValue) {
		
		// if layer already exists
		if (gLayers[layerId]) {
			
			gLayers[layerId].show();
			
		}
		
		//else create layer and append to gLayers array
		else {
			
			var layerSource = '';
			
			switch (layerId) {
				
				case 'wikipedia_en':
				layerSource = 'org.wikipedia.en';
				break;
				
				case 'panoramio_all':
				layerSource = 'com.panoramio.all';
				break;
				
			}
			
			gLayers[layerId] = new GLayer(layerSource);
			
			map.addOverlay(gLayers[layerId]);
			
			// is layer shown by default ??
			//gLayers[layerId].show();
			
		}
		
		// lmc:panoramio/1 (Small photos)
		// lmc:youtube (Hopefully coming)		
		
		// var photo_layer = new PhotoLayer(map);
		// photo_layer.enable();
		// http://gmaps-samples.googlecode.com/svn/trunk/panoramio/
		
	}
	
	else{
		
		gLayers[layerId].hide();
		
	}
}

/*---------------------------------------------------------------------------------------*/
//function show_panoramia_layer()
// TEMP: 
function show_panoramia_layer() {
	
	gLayers['panoramio_all'] = new GLayer('com.panoramio.all');
	
	map.addOverlay(gLayers['panoramio_all']);
	
}
// TODO: 
// function show_panaramio_photos()
// http://www.panoramio.com/api/
// http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=20&minx=-180&miny=-90&maxx=180&maxy=90&size=medium
// code already at accomodation/hotel-photos.php



/*---------------------------------------------------------------------------------------*/
// function show_product_detail()
/**
 * shows product detail in overlay layer
 * @param {string} productType
 * @param {integer} productId
 */

function show_product_detail(productType, productId) {
	
	init_overlaycontent(65, 680, 680); // height no longer required
	
	var detailGeneratorUrl = set_path() + '/ajax/';
	
	
	// TODO: javascript switch
	
	if (productType == 'hotel') {
		
		detailGeneratorUrl += 'accom/create_detail_hotel';
		
	}
	else if (productType == 'airport') {
		
		detailGeneratorUrl += 'airports/create_detail_airport';
		
		showSmallMap = true;
		
	}	
	else if (productType == 'webcam') {
		
		detailGeneratorUrl += 'cams/create_detail_webcam';
		
	}	
	else if (productType == 'weather') {
		
		detailGeneratorUrl += 'weather/create_detail_weather';
		
	}
	
	// end javascript switch
	
	detailGeneratorUrl += '.php?code=' + productId;
	
	
	GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
												
												if (responseCode == 200) {
													
													if (showSmallMap) {
														
														// TODO: generate array of object literals for map variables when loading main page
														// load_small_map(productType, centerLat, centerLong, southWestLat, southWestLong, northEastLat, northEastLong, hasShapedata)
														// load_small_map('{$productType}', {$centreLat}, {$centreLong}, {$southWestLat}, {$southWestLong}, {$northEastLat}, {$northEastLong}, {$hasShapedata});
														
														overlayContent.innerHTML = parseScript(data);
														
														//eval(console.log('hello'));
														
														// _trackEvent (productType, productId) , if here need parameter click on map icon or listing link ?
														
													}
													
													else {
														
														overlayContent.innerHTML = data;
														
													}
													
												}
												
												else if (responseCode == -1) {
													
													overlayContent.innerHTML = '<div class="bigrednotice">Sorry, Request Timed Out</div>';
													
												}
												
												else {
												}
												
											  }  //end function(data, responseCode)
											  ); //end GDownloadUrl()
	
	
}


/*---------------------------------------------------------------------------------------*/
/*
// function show_hotel_detail()
function show_hotel_detail(hotelId) {
		
		init_overlaycontent(65, 680, 680);
		// init_overlaycontent(topMargin, reqWidth, reqHeight)
		
		var detailGeneratorUrl = set_path() + '/ajax/accom/create_detail_hotel.php?code=' + hotelId;
		
		GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
												  	
													if (responseCode == 200) {
														
														overlayContent.innerHTML = data;
														
													}
													
													else if (responseCode == -1) {
														
														overlayContent.innerHTML = '<div class="bigrednotice">Request Timed Out</div>';
														
													}
													
													else {
													}
													
												  }  //end function(data, responseCode)
												  ); //end GDownloadUrl()
		
}
*/
// function show_airport_detail()
/*
function show_airport_detail(airportId) {
		
		init_overlaycontent(65, 680, 500);
		// init_overlaycontent(topMargin, reqWidth, reqHeight)
		
		var detailGeneratorUrl = set_path() + '/ajax/airports/create_detail_airport.php?code=' + airportId;
		//alert(detailGeneratorUrl);
		
		GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
												  	
													if (responseCode == 200) {
														
														overlayContent.innerHTML = data;
														
													}
													
													else if (responseCode == -1) {
														
														overlayContent.innerHTML = '<div class="bigrednotice">Request Timed Out</div>';
														
													}
													
													else {
													}
													
												  }  //end function(data, responseCode)
												  ); //end GDownloadUrl()
		
}
*/
/*
// function show_webcam_detail()
function show_webcam_detail(camId) {
		
		init_overlaycontent(65, 680, 500);
		// init_overlaycontent(topMargin, reqWidth, reqHeight)
		
		var detailGeneratorUrl = set_path() + '/ajax/cams/create_detail_webcam.php?code=' + camId;
		//alert(detailGeneratorUrl);
		
		GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
												  	
													if (responseCode == 200) {
														
														overlayContent.innerHTML = data;
														
													}
													
													else if (responseCode == -1) {
														
														overlayContent.innerHTML = '<div class="bigrednotice">Request Timed Out</div>';
														
													}
													
													else {
													}
													
												  }  //end function(data, responseCode)
												  ); //end GDownloadUrl()
		
}

// function show_weather_detail()
function show_weather_detail(weatherId) {
		
		init_overlaycontent(65, 680, 500);
		// init_overlaycontent(topMargin, reqWidth, reqHeight)
		
		var detailGeneratorUrl = set_path() + '/ajax/weather/create_detail_weather.php?code=' + weatherId;	
		//alert(detailGeneratorUrl);
		
		GDownloadUrl(detailGeneratorUrl, function(data, responseCode) {
												  	
													if (responseCode == 200) {
														
														overlayContent.innerHTML = data;
														
													}
													
													else if (responseCode == -1) {
														
														overlayContent.innerHTML = '<div class="bigrednotice">Request Timed Out</div>';
														
													}
													
													else {
													}
													
												  }  //end function(data, responseCode)
												  ); //end GDownloadUrl()
		
}
*/

/*---------------------------------------------------------------------------------------*/
// function toggle_markers()
// toggle_markers('hotel', this.checked)
// gMarkers['hotel']
function toggle_markers(productType, checkedValue) {
	
	var markersArray = gMarkers[productType];
	
	for (var i = 0; i < markersArray.length; i++) {
		
		if (checkedValue) {
			markersArray[i].show();
		}
		
		else {
			markersArray[i].hide();
		}		
		
	}
	
}

/*---------------------------------------------------------------------------------------*/
// function add_marker()
// initState can be 'visible' or 'hidden'

// TODO: use true or false directly from checkbox value
// TODO: create array and pass to marker manager

// _trackEvent (productType, productId)

function add_marker(markerPoint, productType, markerTitle, productId, initState) {
	
	var markerOption = {icon: customIcons[productType], title: markerTitle}; // , draggable: true, dragCrossMove: true, bounceGravity: 0.4
	// TODO: markerOptions[productType]
	
	var newMarker = new GMarker(markerPoint, markerOption);
	
	GEvent.addListener(newMarker, 'click', function() {
	// 'click' event passes an overlay and overlaylatlng if the map click occurs on an overlay; otherwise, it passes a latlng of the map coordinate													
													
													
													// analytics _trackEvent
													
													//var eventLabel = productType + ' ' + productId;
													
													//console.log('hello');
													
													//_gaq.push(['_trackEvent', 'mainmapmarker', 'show_product_detail', eventLabel]);
													
													// _gaq.push(['_trackEvent', '{$eventCategory}', '{$eventAction}', '{$eventLabel}']);
													// ('mainmapmarker', 'ajaxview', "hotel {$hotelID}")
													
													
													
													if (productType == 'hotel') {
														
														show_product_detail(productType, productId)
														
													}
													
													if (productType == 'airport') {
														
														//show_airport_detail(productId);
														show_product_detail(productType, productId);
														
													}													
													
													if (productType == 'webcam') {
														
														show_product_detail(productType, productId);
														
													}
													
													if (productType == 'carental') {
														
														// TODO: 
														//alert(markerTitle);
														show_blowup(markerPoint, markerTitle, productId);
														
													}
																										
													if (productType == 'weather') {
														
														show_product_detail(productType, productId);
														
													}													
													
													
													}  //end function()
													); //end GEvent.addListener()
		
	gMarkers[productType].push(newMarker);
	
	map.addOverlay(newMarker);
	
	if (initState == 'hidden') {
		
		newMarker.hide();
		
	}
	
}

/*---------------------------------------------------------------------------------------*/
// function add_marker_cluster()
// markerclusterer_packed.js required
// http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/src/markerclusterer_packed.js

// http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/docs/examples.html
// http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/docs/reference.html

// The MarkerClusterer will group markers into clusters according to their distance from a cluster's center.
// When a marker is added, the marker cluster will find a position in all the clusters, and if it fails to find one, it will create a new cluster with the marker.
// The number of markers in a cluster will be displayed on the cluster marker.
// When the map viewport changes, MarkerClusterer will destroy the clusters in the viewport and regroup them into new clusters.

function add_marker_clusterer(markersArray) {
	
	var clusterOptions = {gridSize: 50, maxZoom: 15}; // styles : Array of MarkerStyleOptions ordered according to increasing cluster size
	
	//var markersArray = []; // Create the markers you want to add and collect them into a array.
	
	var markerClusterer = new MarkerClusterer(map, markersArray, clusterOptions);
	
	
}

/*---------------------------------------------------------------------------------------*/
// function show_hotel_markers()

function show_hotel_markers(placeId, placeLevel) {
	
	var markerGeneratorUrl = set_path() + '/ajax/maps/create_markers_hotels.php?place=' + placeId + '&level=' + placeLevel;
	// for ajax version need set_path() function from kararu
	
	GDownloadUrl(markerGeneratorUrl, function(data, responseCode) {
												
												if (responseCode == 200) {
													
													var productType = 'hotel';
													
													var xml = GXml.parse(data);
													
													//var parentElements = xml.documentElement.getElementsByTagName('markers');
													//var hotelsCount = parentElements[0].getAttribute('hotelsCount');
													// TEMP: 
													var hotelsCount = 1;
													
													if (hotelsCount > 0) {
														
														var hotelMarkers = [];
														
														// check state of show hotelmarkers checkbox
														// TODO: pass true or false directly from checkbox value
														var showAccom = document.getElementById('hotelmarkers').checked;
														var markerState = (showAccom) ? 'visible' : 'hidden';														
														
														var markers = xml.documentElement.getElementsByTagName('marker');
														// <marker hotelId="1155" hotelName="Mercure Hotel Lelystad" hotelLat="52.51070000" hotelLong="5.47730000" />
														
														for (var i = 0; i < markers.length; i++) {
															
															var hotelLat = parseFloat(markers[i].getAttribute('hotelLat'));
															var hotelLong = parseFloat(markers[i].getAttribute('hotelLong'));
															
															var markerPoint = new GLatLng(hotelLat, hotelLong);
															
															var hotelName = markers[i].getAttribute('hotelName');
															var cityName = markers[i].getAttribute('cityName');
															
															var markerTitle = hotelName + ' : ' + cityName + ' : Click here for more details about this hotel';
															
															var hotelId = markers[i].getAttribute('hotelId');
																														
															add_marker(markerPoint, productType, markerTitle, hotelId, markerState);
															
															/*---------------------------------------------------------------------------------------*/
															
															// MarkerClusterer
															// add_marker_clusterer(hotelMarkers)
															
															// or MarkerManager
															// mgr.addMarkers(hotelMarkers)
															
															
															/*---------------------------------------------------------------------------------------*/
															
														} // end for (var i = 0; i < markers.length; i++)
														
													} //end if (hotelsCount > 0)
													
													// else what ?
													else {
													}													
													
												} //end if (responseCode == 200)
												
												// else if (responseCode == -1)
												// alert("Data request timed out. Please try later.");
																								
											}  //end function(data, responseCode)
											); //end GDownloadUrl()
	
} //end function show_hotel_markers()


/*---------------------------------------------------------------------------------------*/
// function show_hotels_layer()
// ajax call to generate a KML file

// For Apache, add these lines to the httpd.conf file or a .htaccess file in the same folder
// AddType application/vnd.google-earth.kml+xml .kml 
// AddType application/vnd.google-earth.kmz .kmz

// GGeoXml(urlOfXml)
// Creates a GOverlay that represents that XML file.
// add geographic content to the map from an XML file (such as a KML file) that is hosted on a publicly accessible web server.
//function show_hotels_layer(placeId) {
	//var kmlFile = 'http://kml.lover.googlepages.com/my-vacation-photos.kml';
	/*if (var geoXml = new GGeoXML(kmlFile)) {
		
		if (geoXml.loadedCorrectly()) {
			map.addOverlay(geoXml);
		}
	}
	else {
		alert('GGeoXML undefined');
	}*/
//}

/*---------------------------------------------------------------------------------------*/
// function show_airport_markers()
function show_airport_markers(placeId, placeLevel) {
	
	var productType = 'airport';
	
	var markerGeneratorUrl = set_path() + '/ajax/maps/create_markers_airports.php?place=' + placeId + '&level=' + placeLevel;
	//alert(detailGeneratorUrl);
	
	GDownloadUrl(markerGeneratorUrl, function(data, responseCode) {
												  
												  if (responseCode == 200) {
													  
													  var xml = GXml.parse(data);
													  
													  //var parentElements = xml.documentElement.getElementsByTagName('markers');
													  //var locationsCount = parentElements[0].getAttribute('airportsCount');
													  // TEMP: 
													  var airportsCount = 1;
													  
													  if (airportsCount > 0) {
														  
														  // check state of show airportmarkers checkbox
														  // TODO: pass true or false directly from checkbox value
														  var showMarkers = document.getElementById('airportmarkers').checked;
														  var markerState = (showMarkers) ? 'visible' : 'hidden';
														  
														  var markers = xml.documentElement.getElementsByTagName('marker');
														  
														  for (var i = 0; i < markers.length; i++) {
															  
															  var airportId = markers[i].getAttribute('airportId');
															  
															  var airportName = markers[i].getAttribute('airportName');
															  
															  //var airportCity = markers[i].getAttribute('airportCity');
															  
															  var markerTitle = airportName + ' : Click here for more details about this airport';
															  
															  var airportLat = parseFloat(markers[i].getAttribute('airportLat'));
															  
															  var airportLong = parseFloat(markers[i].getAttribute('airportLong'));
															  
															  var markerPoint = new GLatLng(airportLat, airportLong);
															  															  
															  add_marker(markerPoint, productType, markerTitle, airportId, markerState);
															  
														  }
														  
													  } //end if (airportsCount > 0) {
													  
													  // else
													  else {
													  }
													  
												  } //end if (responseCode == 200)
												  
												  else if (responseCode == -1) {
													  alert('Data request timed out. Please try later.');
												  }
											  
											  
											  }  //end function(data, responseCode)
											  );  //end GDownloadUrl()
	
}

/*---------------------------------------------------------------------------------------*/
// function show_webcam_markers()
function show_webcam_markers(placeId, placeLevel) {
	
	var productType = 'webcam';
	
	var markerGeneratorUrl = set_path() + '/ajax/maps/create_markers_webcams.php?place=' + placeId + '&level=' + placeLevel;
	
	GDownloadUrl(markerGeneratorUrl, function(data, responseCode) {
												  
												  // http://googlemapsapi.blogspot.com/2007/02/gdownloadurl-update-better-error.html
												  // always check status code is equal to 200 before processing the data
												  if (responseCode == 200) {
													  
													  var xml = GXml.parse(data);
													  
													  //var parentElements = xml.documentElement.getElementsByTagName('markers');
													  //var camsCount = parentElements[0].getAttribute('camsCount');
													  // TEMP: 
													  var camsCount = 1;
													  
													  if (camsCount > 0) {
														  
														  // check state of show webcammarkers checkbox
														  // TODO: pass true or false directly from checkbox value
														  var showCams = document.getElementById('webcammarkers').checked;
														  var markerState = (showCams) ? 'visible' : 'hidden';
														  
														  var markers = xml.documentElement.getElementsByTagName('marker');
														  
														  for (var i = 0; i < markers.length; i++) {
															  
															  var camLat = parseFloat(markers[i].getAttribute('camLat'));
															  var camLong = parseFloat(markers[i].getAttribute('camLong'));
															  var markerPoint = new GLatLng(camLat, camLong);
															  
															  var camTitle = markers[i].getAttribute('camTitle');
															  var markerTitle = camTitle + ' : Click here to see this webcam';
															  // TODO: throwing error if single quote in camTitle, eg. undersea Egypt
															  // will go away when using $f_camTitle ??
															  
															  var camId = markers[i].getAttribute('camId');
															  //var remoteId = markers[i].getAttribute('remoteId');
															  															  
															  add_marker(markerPoint, productType, markerTitle, camId, markerState);
															  
														  }
														  
													  } //end if (camsCount > 0)
													  
													  // else
													  else {
													  }													  
													  
												  } //end if (responseCode == 200)
												  
												  else if (responseCode == -1) {
													  alert('Data request timed out. Please try later.');
												  }
											  
											  
											  }  //end function(data, responseCode)
											  );  //end GDownloadUrl()
	
}


/*---------------------------------------------------------------------------------------*/
// function show_carental_markers()
function show_carental_markers(placeId, placeLevel) {
	
	var productType = 'carental';
	
	var markerGeneratorUrl = set_path() + '/ajax/maps/create_markers_carentals.php?place=' + placeId + '&level=' + placeLevel;
	
	GDownloadUrl(markerGeneratorUrl, function(data, responseCode) {
												  
												  if (responseCode == 200) {
													  
													  var xml = GXml.parse(data);
													  
													  //var parentElements = xml.documentElement.getElementsByTagName('markers');
													  //var locationsCount = parentElements[0].getAttribute('locationsCount');
													  // TEMP: 
													  var locationsCount = 1;
													  
													  if (locationsCount > 0) {
														  
														  // check state of show carentalmarkers checkbox
														  // TODO: pass true or false directly from checkbox value
														  var showMarkers = document.getElementById('carentalmarkers').checked;
														  var markerState = (showMarkers) ? 'visible' : 'hidden';														  
														  
														  var markers = xml.documentElement.getElementsByTagName('marker');
														  
														  for (var i = 0; i < markers.length; i++) {
															  
															  var locationId = markers[i].getAttribute('locationId');
															  
															  var locationName = markers[i].getAttribute('locationName');
															  var cityName = markers[i].getAttribute('cityName');
															  var markerTitle = locationName + ' : ' + cityName + ' : Click here for more details about this car rental location';
															  
															  var locationLat = parseFloat(markers[i].getAttribute('locationLat'));
															  var locationLong = parseFloat(markers[i].getAttribute('locationLong'));
															  var markerPoint = new GLatLng(locationLat, locationLong);
															  															  
															  add_marker(markerPoint, productType, markerTitle, locationId, markerState);
															  
														  }
														  
													  } //end if (locationsCount > 0) {
													  
													  // else
													  else {
													  }
													  
												  } //end if (responseCode == 200)
												  
												  else if (responseCode == -1) {
													  alert('Data request timed out. Please try later.');
												  }
											  
											  
											  }  //end function(data, responseCode)
											  );  //end GDownloadUrl()	
	
}

/*---------------------------------------------------------------------------------------*/
// function show_weather_markers()
function show_weather_markers(placeId, placeLevel) {
	
	var productType = 'weather';
	
	var markerGeneratorUrl = set_path() + '/ajax/maps/create_markers_weather.php?place=' + placeId + '&level=' + placeLevel;
	
	GDownloadUrl(markerGeneratorUrl, function(data, responseCode) {
												  
												  if (responseCode == 200) {
													  
													  var xml = GXml.parse(data);
													  
													  //var parentElements = xml.documentElement.getElementsByTagName('markers');
													  //var locationsCount = parentElements[0].getAttribute('weatherCount');
													  // TEMP: 
													  var weatherCount = 1;
													  
													  if (weatherCount > 0) {
														  
														  // TODO: pass true or false directly from checkbox value
														  var showMarkers = document.getElementById('weathermarkers').checked;
														  var markerState = (showMarkers) ? 'visible' : 'hidden';														  
														  
														  var markers = xml.documentElement.getElementsByTagName('marker');
														  
														  for (var i = 0; i < markers.length; i++) {
															  
															  var weatherId = markers[i].getAttribute('weatherId');
															  
															  var weatherName = markers[i].getAttribute('weatherName');
															  
															  var markerTitle = weatherName + ' : Click here for current information from this weather station';
															  
															  var weatherLat = parseFloat(markers[i].getAttribute('weatherLat'));
															  var weatherLong = parseFloat(markers[i].getAttribute('weatherLong'));
															  
															  var markerPoint = new GLatLng(weatherLat, weatherLong);
															  
															  add_marker(markerPoint, productType, markerTitle, weatherId, markerState);
															  
														  }
														  
													  } //end if (stationsCount > 0) {
													  
													  // else
													  else {
													  }
													  
												  } //end if (responseCode == 200)
												  
												  else if (responseCode == -1) {
													  alert('Data request timed out. Please try later.');
												  }
											  
											  
											  }  //end function(data, responseCode)
											  );  //end GDownloadUrl()	
	
}


/*---------------------------------------------------------------------------------------*/
// function show_blowup()
// TODO: pass maxZoomLevel from database, according to country
function show_blowup(markerPoint, markerTitle) {
		//alert(markerTitle);
		var blowupOptions = {zoomLevel: 16, mapType: G_SATELLITE_MAP, maxTitle: markerTitle};
		map.showMapBlowup(markerPoint, blowupOptions);
}

/*---------------------------------------------------------------------------------------*/
// initiate markerManager
// requires http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/src/markermanager_packed.js
// http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/docs/reference.html

//var markerManagerOptions = {borderPadding: 50, maxZoom: 15, trackMarkers: false}; // , trackMarkers: true
//var markerManager = new MarkerManager(map, markerManagerOptions);

// addMarkers(markers:Array of Markers, minZoom:Number, opt_maxZoom:Number)
// Add many markers at once. Does not actually update the map, just the internal grid.
// Markers added using the addMarkers() method will not appear on the map until you explicitly call the MarkerManager's refresh() method,
// which adds all markers within the current viewport and border padding region to the map.
// After this initial display, MarkerManager takes care of all visual updates by monitoring the map's "moveend" events.
// http://code.google.com/apis/maps/documentation/overlays.html#Markers

// will have to set up arrays of MarkerManager(s) for each product
// hide() - Hides the manager if it's currently visible
// show() 
// toggle()
//var productsArray = ['hotel', 'airport', 'webcam']; // , '', '', ''
// TODO: set this up with PHP in the main Template from PHP array lookFor in arrays.php ??

// var markerManagers = [];
// for (var i in productsArray)
// markerManagers[i] = new MarkerManager(map, markerManagerOptions);
// add listener to toggle visibility

// example for number of markers specified to show at various minZoom levels
// mgr = new MarkerManager(map);
// function getWeatherMarkers(n) returns array of n marker objects
// second parameter is min zoom level to show each set of markers
// mgr.addMarkers(getWeatherMarkers(20), 3);
// mgr.addMarkers(getWeatherMarkers(200), 6);
// mgr.addMarkers(getWeatherMarkers(1000), 8);
// mgr.refresh();

/*---------------------------------------------------------------------------------------*/

