// basic variables
var mpstatus = false;
var map = null;
var maplocs = [];
var maploca = [];
var hooks = [];
var linktext = '';
var mainIcon = null;
var greyIcon = null;
var bounds = null;
var lastmap = -1;
var lastlink = "";
var order =100;

	$(document).ready(function(){
		//$('#map').slideUp();
		getLocations();
	
		if (maplocs.length > 0) {
			makeMap();
		}
		$('#map').hide();

	});

	function locObj(lng,lat,html,en,marker) {
		this.lng = lng;
		this.lat = lat;
		this.html = html;
		this.en = en;
		this.marker = marker;
		return this;
	}

	function getLocations() {
		$("div.hotel").each(function(i){
			var lng = '';
			var lat = '';
			var en = '';
			
			$(this).find("a.location").each(function(){
				// get the info for this marker
				var loc = this.getAttribute("title").split(";");
				en 	= loc[0];
				lng = loc[1];
				lat = loc[2];	
			});
	
			var html = $(this).find("div.infowindow").html();
				
			// add marker and functionality
			if (GBrowserIsCompatible() && html != '' && lat != '' && lng != '' && lat != 0) {
				var point = new GLatLng(lat,lng);
				var marker = new GMarker(point, {title:en, icon: G_DEFAULT_ICON});
				
				//store the marker
				maplocs[maplocs.length] = new locObj(lng,lat,html,en,marker);
				
				$(this).find("a.location").each(function(){
					$(this).click(function(){
						$('#map').slideDown();
						if (lat != '' && lng != '' && lat !=0 && lng != 0) {
							if(map != null) {
								map.panTo(new GLatLng(lat,lng));
								window.setTimeout(function() {
									marker.openInfoWindowHtml(html);
								}, 1000);							
							}
						}
					
					},function(){
					});
				});
				GEvent.addListener(marker, "mouseover", function() {
					if (map!=null) {
						marker.openInfoWindowHtml(html);
					}
				});
				
			}
		});
	}

	function makeMap() {
		if (GBrowserIsCompatible()) {
			var mapDIV = document.getElementById("gmap");
	
			map = new GMap(mapDIV);
			map.addControl(new GSmallMapControl());
			map.setCenter(new GLatLng(0,0),0);
			bounds = new GLatLngBounds();
	
			for(i=0;i<maplocs.length;i++) {
				var temp = maplocs[i];
				drawMarker(temp);
			}
	
			map.setZoom(map.getBoundsZoomLevel(bounds));
			var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
			var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
			map.setCenter(new GLatLng(clat,clng));	
		}
	}

	function drawMarker(temp) {
		if (temp.lat != '' && temp.lng != '' && temp.lat !=0 && temp.lng != 0) {
			var point = new GLatLng(temp.lat,temp.lng);
			var marker = temp.marker;
			map.addOverlay(marker);
			bounds.extend(point);
		}
	}

