var LoadMap;
var Lat,Lon,mImage;
var zLevel=0;
var nodeHType;
var nodeHotel;
var mc_text, me_text;
var topStyle = "<b class='rtop'><b class='r1'></b> <b class='r2'></b> <b class='r3'></b> <b class='r4'></b></b>";
var bottomStyle = "<b class='rbottom'><b class='r4'></b> <b class='r3'></b> <b class='r2'></b> <b class='r1'></b></b>";
ReadMapData();//alert(Lat);alert(Lon);alert(zLevel);alert(mImage);

var mouseX, mouseY;
function initMouseMove_GMap() {
    if (window.Event) {
        document.captureEvents(Event.MOUSEMOVE);
    }
    document.onmousemove = getGMapXY;
}

function getGMapXY(e) {
    mouseX = (window.Event) ? e.pageX : event.clientX;
    mouseY = (window.Event) ? e.pageY : event.clientY;
}
        
function initializeGMap() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(Lat,Lon), parseInt(zLevel));
        map.enableScrollWheelZoom();
        //map.disableGoogleBar();
    }
    
    // Creates a marker at the given point
    // Clicking the marker will hide it
    function createMarker1(latlng, number)
    {
        var icon = new GIcon();
        icon.image = mImage;
        //icon.iconSize = new GSize(20, 34);
        icon.iconAnchor = new GPoint(65, 43);

        opts = { 
          "icon": icon,
          "clickable": false,
          "labelText": "",
          "labelOffset": new GSize(-20, -43)
          };

        var marker = new LabeledMarker(latlng, opts);
        //var marker = new GMarker(latlng);
        return marker;
    }
    function createMarker(latlng, infoHtml)
    {
        var icon = new GIcon();//alert(mImage);
        icon.image = mImage;
        icon.iconSize = new GSize(20, 34);
        icon.iconAnchor = new GPoint(10,34);
        
        opts = { 
          "icon": icon,
          "clickable": true
          };
        var marker = new GMarker(latlng, opts);        
        GEvent.addListener(marker, "click", function() {//alert(infoHtml);
            /*document.getElementById("msg").innerHTML = infoHtml;//alert('X:'+(mouseX-75)+';Y:'+(mouseY-20));
            document.getElementById("msg").style.left = (mouseX-75)+'px';
            document.getElementById("msg").style.top = (mouseY-20)+'px';
            document.getElementById("msg").style.display='block';//alert(document.getElementById("msg").offsetLeft);
            if (document.getElementById("msg").offsetLeft <= document.getElementById("map_canvas").offsetLeft)
                document.getElementById("msg").style.left=document.getElementById("map_canvas").offsetLeft+6+'px';
            if (document.getElementById("msg").offsetTop <= document.getElementById("map_canvas").offsetTop)
                document.getElementById("msg").style.top=document.getElementById("map_canvas").offsetTop+6+'px';
            if (document.getElementById("msg").offsetLeft+150 >= document.getElementById("map_canvas").offsetWidth)
                document.getElementById("msg").style.left=(document.getElementById("map_canvas").offsetWidth-156)+'px';
            marker.openInfoWindow(latlng,document.getElementById("msg"));*/
        });
        map.addOverlay(marker);        
    }
    //createMarker(new GLatLng(Lat,Lon), topStyle + mc_text + bottomStyle);
    createMarker(new GLatLng(Lat,Lon), mc_text);
    if (isAttractions == "true"){//alert(isAttractions);
        var nodeAtrns = nodeHotel.getElementsByTagName("Attractions")[0];
        var nodeAtrn = nodeAtrns.getElementsByTagName("Attraction");//alert(nodeAtrn.length);
        for (var i = 0; i < nodeAtrn.length; i++){
            var mrkLat = nodeAtrn[i].getElementsByTagName("Lat")[0].firstChild.nodeValue;//alert(mrkLat);
            var mrkLon = nodeAtrn[i].getElementsByTagName("Lon")[0].firstChild.nodeValue;
            mImage = nodeAtrn[i].getElementsByTagName("AttractionImage")[0].firstChild.nodeValue;//alert(mImage);
            mc_text = nodeAtrn[i].getElementsByTagName("CollapseText")[0].firstChild.nodeValue;
            //createMarker(new GLatLng(mrkLat,mrkLon), topStyle + mc_text + bottomStyle);
            createMarker(new GLatLng(mrkLat,mrkLon), mc_text);
        }
    }
}

function ReadMapData()
{
    if(navigator.appName=="Microsoft Internet Explorer")
        ReadHotelMapXml1();
    else
        ReadHotelMapXml();
}

function ReadHotelMapXml()
{
    var XmlHTTP = null;
    var Possibles = {0: "XMLHttpRequest()", 1: "ActiveXObject('Microsoft.XMLHttp')", 2:"ActiveXObject('MSXML2.XMLHttp')", 3:"ActiveXObject('MSXML2.XMLHttp.3.0')", 4:"ActiveXObject('MSXML2.XMLHttp.4.0')", 5:"ActiveXObject('MSXML2.XMLHttp.5.0')", 6:"ActiveXObject('MSXML2.XMLHttp.6.0')",7:"ActiveXObject('Msxml.DOMDocument')", 8:""};
    var Option = 0;
    while(XmlHTTP === null){
        XmlHTTP = eval("new " + Possibles[Option]);
    }
    if(XmlHTTP === null)
        return false;
    XmlHTTP.open("get", "common_inc/Hotels_GMap.xml", false);
    XmlHTTP.send("");
    LoadMap = XmlHTTP.responseXML;
    ReadHotelMapData();
}
  
function ReadHotelMapXml1(Id) 
{
    if(window.ActiveXObject && /Win/.test(navigator.userAgent))//IE6
    { 
        LoadMap = new ActiveXObject("Msxml.DOMDocument"); 
        LoadMap.async = false; 
        LoadMap.onreadystatechange = function () 
        { 
            if (LoadMap.readyState == 4) 
                ReadHotelMapData();
        } 
        LoadMap.load("common_inc/Hotels_GMap.xml"); 
    } 
    else if(document.implementation && document.implementation.createDocument)//IE7
    {
        LoadMap = document.implementation.createDocument("","",null); 
        LoadMap.async=false; 
        var loaded = LoadMap.load("common_inc/Hotels_GMap.xml"); 
        moz=1;
        if (loaded) 
            ReadHotelMapData();
    } 
    else 
    { 
        alert("Your browser can\'t handle this script"); 
        return; 
    } 
}

function ReadHotelMapData()
{
    nodeHType = LoadMap.getElementsByTagName(hType)[0];
    nodeHotel = nodeHType.getElementsByTagName(hID)[0];
    Lat = nodeHotel.getElementsByTagName("Lat")[0].firstChild.nodeValue;
    Lon = nodeHotel.getElementsByTagName("Lon")[0].firstChild.nodeValue;
    //zLevel = nodeHotel.getElementsByTagName("ZoomLevel")[0].firstChild.nodeValue;
    if (isAttractions == "true")
        zLevel = nodeHotel.getElementsByTagName("Attractions")[0].getAttribute("ZoomLevel");
    else
        zLevel = nodeHotel.getElementsByTagName("ZoomLevel")[0].firstChild.nodeValue;
    mImage = nodeHotel.getElementsByTagName("MarkerImage")[0].firstChild.nodeValue;
    mc_text = nodeHotel.getElementsByTagName("MarkerCollapseText")[0].firstChild.nodeValue;
    me_text = nodeHotel.getElementsByTagName("MarkerExpandText")[0].firstChild.nodeValue;
}