<!--
var cityAlias = '';
var panel = '';
var loadingPanel = '';
var map = '';
var xmlKey = new Object;
var itemArr = new Object;
var tpe = '';
var selTpe = '';

var iconYellow = new GIcon();
iconYellow.image = "/img/zzmaps/marker_yellow.png";
iconYellow.shadow = "/img/zzmaps/marker_shadow.png";
iconYellow.iconSize = new GSize(12, 20);
iconYellow.shadowSize = new GSize(22, 20);
iconYellow.iconAnchor = new GPoint(6, 20);
iconYellow.infoWindowAnchor = new GPoint(4, 4);

var iconRed = new GIcon();
iconRed.image = "/img/zzmaps/marker_red.png";
iconRed.shadow = "/img/zzmaps/marker_shadow.png";
iconRed.iconSize = new GSize(12, 20);
iconRed.shadowSize = new GSize(22, 20);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(4, 4);

var iconStar = new GIcon();
iconStar.image = "/img/zzmaps/marker_star.png";
iconStar.shadow = "/img/zzmaps/marker_shadow-star.png";
iconStar.iconSize = new GSize(18, 20);
iconStar.shadowSize = new GSize(29, 20);
iconStar.iconAnchor = new GPoint(9, 20);
iconStar.infoWindowAnchor = new GPoint(9, 10);

var iconBuilding = new GIcon();
iconBuilding.image = "/img/zzmaps/marker_building.png";
iconBuilding.shadow = "/img/zzmaps/marker_shadow-building.png";
iconBuilding.iconSize = new GSize(11.0, 20.0);
iconBuilding.shadowSize = new GSize(22.0, 20.0);
iconBuilding.iconAnchor = new GPoint(6.0, 20.0);
iconBuilding.infoWindowAnchor = new GPoint(5.0, 10.0)

var iconHotel = new Object;
for (var i=0; i <=6; i++)
{
	iconHotel[i] = new GIcon();
	iconHotel[i].image = "/img/zzmaps/marker_hotel_" + i.toString() + ".png";
	iconHotel[i].shadow = "/img/zzmaps/marker_shadow-hotel.png";
	iconHotel[i].iconSize = new GSize(15.0, 20.0);
	iconHotel[i].shadowSize = new GSize(12.0, 20.0);
	iconHotel[i].iconAnchor = new GPoint(8.0, 20.0);
	iconHotel[i].infoWindowAnchor = new GPoint(5.0, 6.0)
}

function loadMap(lat, long, zoom)
{
	map = new GMap2(document.getElementById('map'));
	
	//add controls
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(lat, long), zoom);
}

function init(city, mapTpe)
{
	cityAlias = city;
	tpe = mapTpe;
	selTpe = mapTpe;
	
	selItem = this.document.maplink.linkeditem.value;
	panel = document.getElementById('panel');
	loadingPanel = document.getElementById('loadingSection');
	initPanelCheckBoxes();
	ajaxLoadMapData(tpe, selItem);
}

function initPanelCheckBoxes()
{
	var p = document.getElementById('panelselection');
	if (p!= null)
	{
		//go through all checkboxes and disable
		var cb = p.getElementsByTagName('input');
		for(var c in cb)
		{
			cb[c].checked = false;
			toggleIndex(cb[c].value, 'none');
		}
	}
}

function addItems(tpe, isDefault)
{
	//check if array for this already exits, if not, read from xml file
	loadingPanel.style.display  = 'block';
	if (xmlKey[tpe] != null && xmlKey[tpe] != '')
	{
		ajaxLoadXMLData(tpe, isDefault);
	}
}

function loadXMLData(tpe, isDefault)
{
	itemArr[tpe] = readXMLFile(tpe);
	addPanelHeader(tpe);
	var cnt = 0;
	for(var alias in itemArr[tpe])
	{
		cnt++;
		var value = itemArr[tpe][alias];
		addMarker(value['lat'], value['long'], tpe, alias);
		addToPanel(tpe, alias, value['title'], cnt);
	}
	addPanelFooter(tpe);
	if (selTpe != tpe)
	{
		toggleIndexBody(selTpe, 'none');
		selTpe = tpe;
		toggleIndex(selTpe, 'block');
	}
	else
	{
		toggleIndex(selTpe, 'block');
	}
	//show selected item
	if (selItem != '' && selItem != -1)
	{
		activateIcon(tpe, selItem);
	}
	loadingPanel.style.display  = 'none';
}

function toggleItems(tpe, cb)
{
	if (itemArr[tpe] == null)
	{
			addItems(tpe);
			return;
	}
	if (cb.checked == false)
	{
		//Remove all items for selected type from map
		for(var alias in itemArr[tpe])
		{
				itemArr[tpe][alias]['marker'].hide();
		}
		toggleIndex(tpe, 'none');
		
		//Find another selected type and display that instead
		var tpes = document.getElementById('panelselection').getElementsByTagName('input');
		var found = false;
		for (var i = 0; i < tpes.length; i++)
		{
			if (found == false && tpes[i].checked == true)
			{
				selTpe = tpes[i].getAttribute('id').substr(2).toLowerCase();
				toggleIndex(selTpe, 'block');
				found = true;
			}
		}
		if (found != true)
		{
			selTpe = '';
		}
	}
	else
	{
		//Show all items for selected type from map
		for(var alias in itemArr[tpe])
		{
				itemArr[tpe][alias]['marker'].show();
		}
		
		if (selTpe != tpe && selTpe != '')
		{
			toggleIndexBody(selTpe, 'none');
		}
		toggleIndex(tpe, 'block');
		
		selTpe = tpe;
	}
}

function getResponseXml(xmlUrl) 
{
	var xmlHttp = new XMLHttpRequest();
	xmlHttp.open("GET", xmlUrl, false);
	xmlHttp.send(null);
	return xmlHttp;
}

function readXMLFile(tpe)
{
	var xmlDoc;
	var items = new Object;
	
	path = "/maps/tmpdata/";
	var xmlDoc = getResponseXml(path + xmlKey[tpe] + ".xml").responseXML;
	
	if (xmlDoc.documentElement != null)
	{
		var x = xmlDoc.documentElement.childNodes;
		for (var i = 0; i < x.length; i++)
		{ 
			if (x[i].nodeType==1)
			{ 
				itemAlias = x[i].getAttribute('name'); 
				var itemm = new Object;
				var y = x[i].childNodes;
				for (var j = 0; j < y.length; j++)
				{ 
					if (y[j].nodeType==1)
					{
						if (y[j].childNodes[0] != null)
						{
							itemm[y[j].nodeName] = y[j].childNodes[0].nodeValue;
						}
					}
				}
				items[itemAlias] = itemm;
			} 
		}
	}
	
	return items;
}

function addPanelHeader(tpe)
{
	panel.innerHTML+= "<ul>";
}

function addToPanel(tpe, alias, title, nr)
{
	p = document.getElementById('p' + tpe);	
	if (p != null)
	{
		p.innerHTML+= "<li>" + nr + ". <a href=\"javascript:activateIcon('" + tpe + "', '" + alias + "');\">" + title + "</a></li><br />";
	}
}

function addPanelFooter(tpe)
{
	panel.innerHTML+= "</ul>";
}

function toggleIndexBody(tpe, newstate)
{
	var p = document.getElementById('p' + tpe);	
	var i = document.getElementById('i' + tpe);	
	if (p != null)
	{
		if (newstate == 'toggle')
		{
			newstate = p.style.display == 'block' ? 'none' : 'block';
		}
		if (newstate == 'none')
		{
			p.style.display = 'none';
			p.style.height = '0px';
			i.src = "/img/zzmaps/desel.gif";
		}
		else
		{
			p.style.display = 'block';
			p.style.height = '';
			i.src = "/img/zzmaps/sel.gif";
		}
	}
}

function toggleIndex(tpe, newstate)
{
	var pHead = document.getElementById('p' + tpe + 'Header');
	var p = document.getElementById('p' + tpe);	
	if (p!= null && pHead != null)
	{
		if (newstate == 'block')
		{
			pHead.style.display = 'block';
			pHead.style.height = '';
		}
		else
		{
			pHead.style.display = 'none';
			pHead.style.height = '0px';
		}
		toggleIndexBody(tpe, newstate);
	}
}

function addMarker(lat, long, tpe, alias)
{
	var point = new GLatLng(lat, long)
  marker = createMarker(point, tpe, alias);
  map.addOverlay(marker);	
	itemArr[tpe][alias]['marker'] = marker;
}
	
function createMarker(point, tpe, alias)
{
	switch(tpe)
	{
		case "attractions":
			if (itemArr[tpe][alias]['isTop'] == '1')
				var marker = new GMarker(point, iconStar);
			else
			{
			if (itemArr[tpe][alias]['hasArticle'] == '1')
				var marker = new GMarker(point, iconRed);
			else
				var marker = new GMarker(point, iconYellow);
			}
			break;
		case "buildings":
			var marker = new GMarker(point, iconBuilding);
			break;
		case "hotels":
			var rating = itemArr[tpe][alias]['rating'];
			if (rating == null) rating = "6";
			switch (rating.toString())
			{
				case "0_0":
				case "0_5":
					var marker = new GMarker(point, iconHotel[0]);
					break;
				case "1_0":
				case "1_5":
					var marker = new GMarker(point, iconHotel[1]);
					break;
				case "2_0":
				case "2_5":
					var marker = new GMarker(point, iconHotel[2]);
					break;
				case "3_0":
				case "3_5":
					var marker = new GMarker(point, iconHotel[3]);
					break;
				case "4_0":
				case "4_5":
					var marker = new GMarker(point, iconHotel[4]);
					break;
				case "5_0":
				case "5_5":
					var marker = new GMarker(point, iconHotel[5]);
					break;
				default:
					var marker = new GMarker(point, iconHotel[6]);
					break;
			}
			break;
	}
		
  GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(getHTML(tpe, alias));});
    	
  return marker;
}
  	
function activateIcon(tpe, alias)
{
	itemArr[tpe][alias]['marker'].openInfoWindowHtml(getHTML(tpe, alias));
}

function getHTML(tpe, alias)
{
	title = getTitle(tpe, alias);
	img = itemArr[tpe][alias]['img'];
	loc = itemArr[tpe][alias]['loc'] == null ? "" : "<div class=\"loc\">" + itemArr[tpe][alias]['loc'] + "</div>";
	imgurl = "";
	if (img != null)
	{
		var imgClass = 'ver';
		if (img.indexOf('H') == 0)
		{
			imgClass = 'hor';
			img = img.substring(1, img.length);
		}
		if (tpe == 'buildings')
		{
			imgClass = 'verBuilding';
		}
		if (tpe == "hotels")
		{
			imgurl = "<img src='http://images.travelnow.com/" + img + ".jpg' class='pic' />";
		}
		else
		{
			imgurl = "<img src='../img/" + cityAlias + "/" + img + ".jpg'/ class='pic " + imgClass + "' />";
		}
	}
	lnk = getLinks(tpe, alias);
	
	var html = "<div style=\"color:black\"><table border=\"0\"><tr>";
	html = html + "<td valign='top'>" + imgurl + "</td>";
	html = html + "<td valign='top' width='140'><b>" + title + "</b>" + loc + lnk + "</td></tr></table>";
	
	return html;
}


function getTitle(tpe, alias)
{
	var title = itemArr[tpe][alias]['title'];
	
	if (tpe == "hotels")
	{
			var stars = "";
			if (itemArr[tpe][alias]['rating'] != null && itemArr[tpe][alias]['rating'] != "")
			{
				stars = "<br /><img src=\"/img/zzhotels/stars" + itemArr[tpe][alias]['rating'] + ".gif\" />";
			}
		title = "<a href=\"javascript:jump_hotel('" + alias + "')\">" + title + "</a>" + stars;
	}
	else
	{
		if (itemArr[tpe][alias]['hasArticle'] == null)
		{
			if (itemArr[tpe][alias]['building'] != null)
			{
				var building = itemArr[tpe][alias]['building'];
				title = "<a href=\"../buildings/" + cityAlias + "/" + building + ".htm\" onclick=\"jump_link(this.href);return false;\">" + title + "</a>";
			}
		}
		else
		{
			title = "<a href=\"../" + cityAlias + "/" + alias + ".htm\" onclick=\"jump_link(this.href);return false;\">" + title + "</a>";
		}
	}

	return title;
}

function getLinks(tpe, alias)
{
	var lnk = "";
	var cntLnks = 0;
	if (tpe == "hotels")
	{
		lnk += "<br />> <a href=\"javascript:jump_hotel('" + alias + "')\">Hotel Info</a>";
		cntLnks++;
	}
	if (itemArr[tpe][alias]['hasArticle'] != null)
	{
		lnk += "<br />> <a href=\"../" + cityAlias + "/" + alias + ".htm\" onclick=\"jump_link(this.href);return false;\">More info</a>";
		cntLnks++;
	}
	if (itemArr[tpe][alias]['building'] != null)
	{
		var building = itemArr[tpe][alias]['building'];
		lnk += "<br />> <a href=\"../buildings/" + cityAlias + "/" + building + ".htm\" onclick=\"jump_link(this.href);return false;\">Building facts</a>";
		cntLnks++;
	}
	if (itemArr[tpe][alias]['hasPicture'] != null)
	{
		lnk += "<br />> <a href=\"../gallery/" + cityAlias + "/" + alias + ".htm\" onclick=\"jump_link(this.href);return false;\">Pictures</a>";
		cntLnks++;
	}
	if (itemArr[tpe][alias]['hasPoster'] != null)
	{
		lnk += "<br />> <a href=\"../" + cityAlias + "/posters/" + alias + ".htm\" onclick=\"jump_link(this.href);return false;\">Posters</a>";
		cntLnks++;
	}
	
	for (var indx = 0; indx < 5 - cntLnks; indx++)
	{
		lnk += "<br />";
	}
	return "<div class=\"link\">" + lnk + "</div>";
}


function jump_hotel(hotelid)
{
	if (hotelid != "")
	{
		var url = "http://travel.aviewoncities.com/index.jsp?pageName=hotAvail&hotnetrates=true&mode=1&requestKey=&showInfo=true&cid=71006&locale=en&hotelID=" + hotelid;
		jump_link(url);
	}
}

function jump_link(url)
{
	var isNewWindow = document.getElementById('isnewwindow');
	
	if (isNewWindow.checked == true) 
		win = "_new";
	else
		win = "_self";
	winRef = window.open(url, win);
}

function ajaxLoadXMLData(tpe, isDefault)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				//alert("Error creating Ajax object!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			//alert(ajaxRequest.responseText);
			if (!parseResponseMap2(ajaxRequest.responseText, tpe, isDefault))
				;
		}
	}
	
	var queryString = "/functions/ajax/mapcallback.htm";
	ajaxRequest.open("GET", queryString, true);
	ajaxRequest.send(null);
}

// Process ajax response
function parseResponseMap2(response, tpe, isDefault)
{
	loadXMLData(tpe, isDefault);
}

function ajaxLoadMapData(tpe, selItem)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				//alert("Error creating Ajax object!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			//alert(ajaxRequest.responseText);
			if (!parseResponseMap(ajaxRequest.responseText, tpe, selItem))
				;
		}
	}
	
	var queryString = "/functions/ajax/getmapdata.htm?city=" + cityAlias;
	ajaxRequest.open("GET", queryString, true);
	ajaxRequest.send(null);
}

// Process ajax response
function parseResponseMap(response, tpe, selItem)
{
	if (response.length < 1) { return false; } 

	//Splits the response up in key pairs
  indx = 1;
	keypairs = new Object();
	while (response.indexOf('&') > -1)
	{
		keypairs[indx] = response.substring(0,response.indexOf('&'));
		response = response.substring((response.indexOf('&')) + 1);
		indx++;
	}
	//Go though key pairs
	for (indx in keypairs)
	{
		keyName = keypairs[indx].substring(0,keypairs[indx].indexOf('=')); // Left of '=' is name.
		keyValue = keypairs[indx].substring((keypairs[indx].indexOf('=')) + 1); // Right of '=' is value.
		processKeyPairMap(keyName, keyValue);
	}
	
	
function processKeyPairMap(keyName, keyValue)
{
	var tag = keyName;
	var txt = keyValue;
	if (tag == 'message')
	{
		if (txt == 'err')
		{
			var obj = document.getElementById('msg');
			if (obj != null)
			{	
				obj.innerHTML = 'sorry, an unexpected error occurred';
			}		
				//alert('sorry, an unexpected error occurred');
		}
	}
	else
	{
		xmlKey[tag] = txt;
		if (tag == tpe)
		{
			//load this by default
			addItems(tpe, true);
			//Set checkbox as selected
			var fldName = 'cb' +  tpe;
			var obj = document.getElementById(fldName);	
			if (obj != null)
			{
				obj.checked = true;
			}
		}
	}
}
}

//-->