


var localAreaMap = {
    map:null,
    pushPinLatLong:null,
    propId:SW.tools.Url.getParameter(document.location.href,"propertyID"),
    localeCode:null,
    propertyName:null,
    latitude:null,
    longitude:null,
    streetAddress1:null,
    city:null,
    stateName:null,
    stateCode:null,
    countryName:null,
    countryCode:null,
    zipCode:null,
    isChineseMap:null,
    thumbnailURL:null,
    propertyZoom:null,
    token:null,
    gridSize:80,
    minIndex:0,
    totalPushPinsLatLong:new Array(),
    customAddLatLongArray:new Array(),
    attractionsLatLongArray:new Array(),
    baseLayer:new VEShapeLayer(),
    clusterLayer:new VEShapeLayer(),
    attractionsLayer:new VEShapeLayer(),
    initialize: function () {
        this.mapHelper = SW.widget.virtualEarth.initializeMap('map');
        this.mapHelper.setLabels({
            road:'Road',
            aerial:'Aerial',
            traffic:'Traffic',
            label:'Labels',
            birdsEye:"Bird's Eye",
            street:'Street',
            showControls:'Show the view control',
            hideControls:'Hide the view control',
            trafficLegend:"Traffic isn't available in bird's eye view",
            zoomInForTraffic:"Zoom in for Traffic",
            zoomOutForTraffic:"Zoom out for Traffic"
        });
        this.loadMap();
    },
    addPushPin: function (htmlBlock,pushPin, layer, className) {
        var that = localAreaMap;
        pushPin.SetCustomIcon("<div class=" + className + "></div>");
        pushPin.SetLineColor(new VEColor(0,150,100,1.0));
        pushPin.SetFillColor(new VEColor(0,100,150,0.5));
//        pushPin.SetDescription(htmlBlock);
        pushPin.SetPoints(that.pushPinLatLong);
        pushPin.Show();
        layer.AddShape(pushPin);
    },
    loadMap: function () {
        var that = localAreaMap;
        that.URLSkinName = null;
        if(SW.tools.getSkinName() != 'corporate') {
            that.URLSkinName =  SW.tools.getSkinName();
        } else {
            that.URLSkinName = that.brandName;
        }
        that.mapHelper.currentMapObj = localAreaMap;
        that.pushPinLatLong = new VELatLong(this.latitude,this.longitude);
        this.mapHelper.setLatLong(that.pushPinLatLong);
        this.mapHelper.map.HideDashboard();
        this.mapHelper.isChineseMap = this.isChineseMap;
        if (this.propertyZoom == null) {
            this.propertyZoom = 14;
        }
        this.mapHelper.countryCode = this.countryCode;
        if(this.localeCode != 'zh_CN') {
            this.mapHelper.map.SetClientToken(that.token);
        }
        this.mapHelper.map.LoadMap(that.pushPinLatLong,this.mapHelper.getMicrosoftZoom(this.propertyZoom) ,VEMapStyle.Road ,false);
        if (this.localeCode != 'en_US') {
            this.mapHelper.map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
        }
        var mapContainer = document.getElementById('mapContainer');
        var dashboard = this.mapHelper.createCustomDashboard('dashboard');
        mapContainer.appendChild(dashboard);
        this.mapHelper.initializeRotate();
        this.mapHelper.labelsChecked = 'true';
        that.pushPin = new VEShape(VEShapeType.Pushpin, that.pushPinLatLong);
        that.pushPin.SetTitle("<a href=\"/" + that.URLSkinName +  "/property/overview/index.html?propertyID=" + this.propId + "\">" + this.propertyName + "</a>");
        var str = that.generatePushPinContent(that.mapHelper.map.GetMapStyle());
        that.pushPin.SetDescription(str);
        this.addPushPin(str,that.pushPin,this.baseLayer,"pushPin");
        this.attractionsLayer.Hide();
        this.mapHelper.map.AddShapeLayer(this.baseLayer);
        this.mapHelper.map.AddShapeLayer(this.clusterLayer);
        that.totalPushPinsLatLong.concat(that.pushPinLatLong);
        this.mapHelper.map.AttachEvent("onclick",this.breakCluster);
        this.mapHelper.map.AttachEvent("onchangeview", this.cluster);
        this.mapHelper.map.AttachEvent("onchangemapstyle", this.generatePushPinContent);
        yuiEvent.addListener( this.mapHelper.roadTab, "click", function() {
            localAreaMap.generatePushPinContent('road');
            yuiDom.removeClass(yuiDom.get('birdsEyeNote'),'show');
        });
        yuiEvent.addListener( this.mapHelper.aerialTab, "click", function() {
           localAreaMap.generatePushPinContent('aerial');
           yuiDom.removeClass(yuiDom.get('birdsEyeNote'),'show');
        });
        yuiEvent.addListener( this.mapHelper.birdsEyeTabObj, "click", function() {
            localAreaMap.generatePushPinContent('birdseye');
            yuiDom.addClass(yuiDom.get('birdsEyeNote'),'show');
        });
    },
    generatePushPinContent:function() {
        var that = localAreaMap;
         var str = "<div class=\"thumbnailImg\"><img src=\"" + that.thumbnailURL +  "\"/></div><div class=\"address\">" + that.streetAddress1 + ', ' + that.city + ', ' + that.stateCode + ' ' + that.zipCode + ' ' + that.countryName;
        <!--Add Book Now Link only for Active Properties-->
        if (this.propertyStatus == 'Active') {
            str += "<div class=\"bookNow\"><a href=\"/" + that.URLSkinName + "/search/preDecider.html?propertyID=" + that.propId + "\">Book Now &gt;</a></div>";
        }
        str += "</div>";
        str += "<div class=\"clearDiv\"></div></div>";
        str += "<div class=\"bottomArea\">";
        str += "<a href=\"/" + that.URLSkinName + "/property/area/directions.html?propertyID=" + that.propId + "\">Directions </a><br/>";
        if(that.mapHelper.map.GetMapStyle() != null && that.mapHelper.map.GetMapStyle() != 'b') {
            str += "Zoom to: <a class=\"zoomInType\" href=\"javascript:SW.widget.virtualEarth.getMap('map').setZoomtoLinks('" + that.latitude + "','" + that.longitude + "','16')\";>Street</a> | <a class=\"zoomInType\" href=\"javascript:SW.widget.virtualEarth.getMap('map').setZoomtoLinks('" + that.latitude + "','" + that.longitude + "','11');\">City</a> | <a class=\"zoomInType\" href=\"javascript:SW.widget.virtualEarth.getMap('map').setZoomtoLinks('" + that.latitude + "','" + that.longitude + "','6');\">Region</a></div>";
        }
       that.pushPin.SetDescription(str);
    },
    findALocation:function() {
        var that = localAreaMap;
        SW.domWidget.inputLabels.removeLabel(yuiDom.get("customAddress"));
        if(yuiDom.get('addLocationForm').customAddress.value  != '') {
            localAreaMap.mapHelper.map.Find(null,yuiDom.get('addLocationForm').customAddress.value, null, null, null, null, null, null, false, false, localAreaMap.addCustomAddress);
        } else {
         yuiDom.get('addLocationError').innerHTML  ="Please submit an airport code, address or zip code.";
         yuiDom.get('addLocationError').style.display="block";
        }
        return false;
    },
    addCustomAddress:function (veShapeLayer, veFindResult, vePlace, moreResults, errorMsg) {
        var that = localAreaMap;
        that.totalPushPinsLatLong = new Array();
        document.getElementById('addLocationError').style.display = "none";
        if (vePlace != null) {
            var customPlace = null;
            if (vePlace.length > 1) {
                var results = "More than one location was found. Please select the location you were looking for" + ":<br/>";
                var highConfidenceMatches = new Array();
                for (x = 0; x < vePlace.length; x++) {
                    if (vePlace[x].MatchConfidence == VEMatchConfidence.High) highConfidenceMatches.push(vePlace[x]);
                    else results += "<a href=\"javascript:localAreaMap.mapHelper.map.Find(null,'" + vePlace[x].Name + "', null, null, null, null, null, null, false, false, localAreaMap.addCustomAddress)\">" + vePlace[x].Name + "</a><br/>";
                }
                if (highConfidenceMatches.length == 0) {
                    document.getElementById('addLocationError').innerHTML = results;
                    document.getElementById('addLocationError').style.display = "block";
                } else if (highConfidenceMatches.length == 1) {
                    customPlace = highConfidenceMatches[0];
                }
            } else if (vePlace.length == 1) {
                customPlace = vePlace[0];
            }
            if (customPlace != null) {
                var shape = new VEShape(VEShapeType.Pushpin, customPlace.LatLong);
                shape.SetTitle(customPlace.Name);
                shape.SetCustomIcon("<div class='pushPinCustom'></div>");
                // Check if the property has disabled driving directions
                if(!that.disableDrivingDirections) {
                    shape.SetDescription('<a href="/' + SW.tools.getSkinName() + '/property/area/directions_results.html?propertyID=' + localAreaMap.propId + '&lat=' + customPlace.LatLong.Latitude + '&long=' + customPlace.LatLong.Longitude + '&toHotel=true' + '&name=' + customPlace.Name + '">Directions</a>');
                }
                that.baseLayer.AddShape(shape);
                that.customAddLatLongArray.push(customPlace.LatLong);
                that.totalPushPinsLatLong = that.customAddLatLongArray.concat(that.pushPinLatLong,that.attractionsLatLongArray);
                if(that.mapHelper.map.GetMapStyle() != 'b') {
                    that.mapHelper.map.SetMapView(that.totalPushPinsLatLong);
                }
            }
        } else {
            yuiDom.get('addLocationError').innerHTML = "We’re sorry. We are unable to find the address you entered. Please revise the address and search again.";
            yuiDom.get('addLocationError').style.display='block';
            yuiDom.get('addLocationError').style.color='red';
            alert(errorMsg);
        }
    },
    addAttractions:function(htmlBlock, latitude, longitude, count) {
        var that = localAreaMap;
        var latLong = new VELatLong(latitude,longitude);
        that.attractionsLatLongArray.push(latLong);
        pushPin = new VEShape(VEShapeType.Pushpin, latLong);
        pushPin.SetCustomIcon("<div class='attractionsPushPin1'>" + count + "</div>")
        pushPin.SetTitle(htmlBlock);
        pushPin.Show();
        that.attractionsLayer.AddShape(pushPin);
//        that.mapHelper.map.AddShape(pushPin);

    },
       cluster:function()  {
         var that = localAreaMap;

        // Change gridSize based on the zoom level
//        if(that.mapHelper.map.GetZoomLevel() > 12) {
//            that.gridSize = that.gridSizeLimit - (4*(that.mapHelper.map.GetZoomLevel()/2));
//        } else {
            that.gridSize = "80";
//        }

    // Check to see whether event is due to map style change
//            if(mapStyle != that.mapHelper.map.GetMapStyle())
//            {
//               // Store the current map style
//               mapStyle = that.mapHelper.map.GetMapStyle();
//               return true;
//            }

            // Remove all pins from the cluster layer
            that.clusterLayer.DeleteAllShapes();

            // Calculate the size, in pixels, of the map
            var mapView = that.mapHelper.map.GetMapView();
            var bottomRight = that.mapHelper.map.LatLongToPixel(mapView.BottomRightLatLong);
            that.mapWidth = parseInt(Math.ceil(bottomRight.x));
            that.mapHeight = parseInt(Math.ceil(bottomRight.y));

            // Break the map up into a grid
            that.numXCells = parseInt(Math.ceil(that.mapWidth / that.gridSize));
            that.numYCells = parseInt(Math.ceil(that.mapHeight / that.gridSize));

            // Create an array to store all the grid data
            that.gridCells = new Array(that.numXCells*that.numYCells);

            // Initialize the grid array with a structure to store all the data
            for(var i = 0; i < that.numXCells; i++)
            {
               for(var j = 0; j < that.numYCells;j++)
               {
                  that.gridCells[i+j*that.numXCells]={pushPinsArray:new Array(), title:"", description:"", length:0};
               }
            }

            // Iterate through the shapes in the base layer
            for(var cnt = 0; cnt < that.attractionsLayer.GetShapeCount(); cnt++)
            {
               // Convert the shapes latlong to a pixel location
               var shape = that.attractionsLayer.GetShapeByIndex(cnt);

               var latLong = (shape.GetPoints())[0];
               var pixel = that.mapHelper.map.LatLongToPixel(latLong);
               var xPixel = pixel.x;
               var yPixel = pixel.y;

               // Check to see whether the shape is within the bounds of the viewable map                                 i
               if(that.mapWidth >= xPixel && that.mapHeight >= yPixel && xPixel >= 0 && yPixel >= 0)
               {
                  // Calculate the grid position on the map of where the shape is located
                  var i = Math.floor(xPixel/that.gridSize);
                  var j = Math.floor(yPixel/that.gridSize);

                  // Calculate the grid location in the array
                  var key = i+j*that.numXCells;

//                  if(getParameter(document.location.href,"page") != null) {
//                         that.shapeIndex = parseInt(getParameter(document.location.href,"page")) * 10 -9 + cnt ;
//                    } else {
                        that.shapeIndex = cnt +1;
//                    }


                  var shapesObj = {shapeID:shape.GetID(),shapeTitle:shape.GetTitle(),latitude:shape.GetPoints()[0].Latitude,longitude:shape.GetPoints()[0].Longitude,shapeIndex:that.shapeIndex };
                  // Define a standard way to display an individual shape
                  if(that.gridCells[key].length == 0)
                  {
                     that.gridCells[key].latlong = latLong;
                     that.gridCells[key].title = shape.GetTitle();
                     that.gridCells[key].description = shape.GetDescription();

                  }
                  that.gridCells[key].pushPinsArray.push(shapesObj);
                  that.gridCells[key].length++;

                  // Allow the contents of all the points in a grid to be
                  // displayed in the infobox of the shape if the user is zoomed
                  // into a predefined limt. This is done to prevent massive
                  // amounts of data from being displayed inside of the infobox.
                  if(that.gridCells[key].length > 1)
                  {
                     if(that.gridCells[key].length == 2)
                     {
                        that.gridCells[key].description = "<br /><b>" + that.gridCells[key].title +
                           "</b><br />" + that.gridCells[key].description + "<br /><hr />";
                     }

                     that.gridCells[key].title = that.gridCells[key].length + " " + 'results were found. Click to zoom.';
                     that.gridCells[key].description = that.gridCells[key].description +
                        "<b>" + shape.GetTitle() + "</b><br />" + shape.GetDescription() + "<br /><hr />";
                    }


                 }
                }
 // Iterate through the clustered data in the grid array
            for(var key = 0; key < that.gridCells.length; key++)
            {
               that.gridCells[key] = that.gridCells[key];

               // Set the default infobox message for clustered points that are zoomed out
               if(that.gridCells[key].length > 1)

               {
                  that.gridCells[key].title = that.gridCells[key].length + " " + 'results were found. Click to zoom.';
                  that.gridCells[key].description = "";
               }

               // Add a shape to the cluster layer
               if(that.gridCells[key].length > 0)
               {
                  var clusterShape = new VEShape(VEShapeType.Pushpin, that.gridCells[key].latlong);
                  clusterShape.SetTitle(that.gridCells[key].title);
                  clusterShape.SetDescription(that.gridCells[key].description);

                  if(that.gridCells[key].length > 5) {
                     clusterShape.SetCustomIcon("<span class='attractionsPushPin5'>" + ( that.gridCells[key].pushPinsArray[0].shapeIndex + that.minIndex) + "</span>");

                 } else {
                         clusterShape.SetCustomIcon("<span class='attractionsPushPin" +that.gridCells[key].length + "'>" + (that.gridCells[key].pushPinsArray[0].shapeIndex + that.minIndex) + "</span>");
                 }
                  that.clusterLayer.AddShape(clusterShape);
               }
            }
            },
            breakCluster:function(e) {
                var that = localAreaMap;
                var clickedShape = that.mapHelper.map.GetShapeByID(e.elementID);
                if(clickedShape != null) {
                    var clickedLatLong = (clickedShape.GetPoints())[0];
                    var clickedPixel = that.mapHelper.map.LatLongToPixel(clickedLatLong);
                    clickedxPixel = clickedPixel.x;
                    clickedyPixel = clickedPixel.y;
                    if(that.mapWidth >= clickedxPixel && that.mapHeight >= clickedyPixel && clickedxPixel >= 0 && clickedyPixel >= 0) {
                            var i = Math.floor(clickedxPixel/that.gridSize);
                            var j = Math.floor(clickedyPixel/that.gridSize);

                            // Calculate the grid location in the array
                            var key = i+j*that.numXCells;
                            var GridPushPins = that.gridCells[key].pushPinsArray;

                            var clusteredPushPins = new Array();
                            if(GridPushPins.length > 1 ) {
                                for(i =0; i< GridPushPins.length;i++) {
                                    clusteredPushPins.push(new VELatLong(GridPushPins[i].latitude,GridPushPins[i].longitude));
                                }
                                that.mapHelper.map.SetMapView(clusteredPushPins);
                            } else {

                                that.mapHelper.map.ShowInfoBox(clickedShape, new VEPixel(clickedxPixel+13,clickedyPixel));
                            }
                    }
                }
            }
};

(function(){
    var attractionsHandler = {

        minIndex:0,
        maxPerPage:20,
        originalMinIndex:null,
        originalMaxIndex:null,
        totalResults:null,
        parsedResponse:null,
        disableDrivingDirections:false,

        category_onChange:function() {
            var that = attractionsHandler;
            that.minIndex = 0;
            that.maxIndex = that.minIndex + that.maxPerPage - 1;
            that.originalMinIndex = that.minIndex;
            that.originalMaxIndex = that.minIndex + that.maxPerPage -1;
            localAreaMap.attractionsLatLongArray = new Array();
            responseHandler = that.attractionHandler;
            that.minIndex = that.originalMinIndex;
            that.maxIndex = that.originalMaxIndex;
            localAreaMap.minIndex = that.originalMinIndex;
            localAreaMap.maxIndex = that.originalMaxIndex;

            var cat = '';
//            that.toggleLoadingMessage();
            category = document.getElementById("attractionCategory");
            if (category) {
                var cat = category.options[category.selectedIndex].value;
            }

            if (cat != null && cat != "") {
                url = "/ajax/searchAttractions.html?latitude=" + localAreaMap.latitude + "&longitude=" + localAreaMap.longitude + "&country=" + localAreaMap.countryCode + "&attractionType=" + cat;
                that.loadXMLDoc(url);
            }
            return false;
        },
        initialize:function() {
            var that = attractionsHandler;
            that.originalMinIndex = that.minIndex;
            that.originalMaxIndex = that.minIndex + that.maxPerPage -1;
        },
        previous_onClick:function() {
            var that = attractionsHandler;
            var temp = that.minIndex;
              that.originalMinIndex = that.minIndex;
            that.originalMaxIndex = that.minIndex + that.maxPerPage -1;
            if (that.minIndex - that.maxPerPage >= 0) {
                localAreaMap.attractionsLayer.DeleteAllShapes();
                localAreaMap.attractionsLatLongArray = new Array();
                that.minIndex = that.minIndex - that.maxPerPage;
                that.maxIndex = temp;
                localAreaMap.minIndex = that.minIndex;
                localAreaMap.maxIndex = that.maxIndex;
                that.setAttractions();
                that.previousNextHandler(that.parsedResponse);
            }
            return false;
        },
        next_onClick:function() {
            var that = attractionsHandler;
              that.originalMinIndex = that.minIndex;
            that.originalMaxIndex = that.minIndex + that.maxPerPage -1;
            if ((that.minIndex + that.maxPerPage) < totalResults) {
                localAreaMap.attractionsLayer.DeleteAllShapes();
                localAreaMap.attractionsLatLongArray = new Array();

                that.minIndex = that.minIndex + that.maxPerPage;
                that.maxIndex = that.minIndex + that.maxPerPage - 1;
                if (that.maxIndex > totalResults) {
                    that.maxIndex = totalResults;
                }
                localAreaMap.minIndex = that.minIndex;
                localAreaMap.maxIndex = that.maxIndex;
                that.setAttractions();
                that.previousNextHandler(that.parsedResponse);

            }
            return false;
        },
        loadXMLDoc:function(url) {
            var that = attractionsHandler;
            var callback = {
            success: function(o) {
                that.attractionHandler(o);
                },
            failure: function(o) {
//                yuiDom.removeClass('loadingMessage', 'show');
                alert("AJAX doesn’t work"); //FAILURE
                }
            }
             var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);

        },
        getClientToken:function(req,localAreaMap) {
            var that = localAreaMap;
             if (req.responseText.indexOf("(") >= 0 && req.responseText.indexOf("(") < 5)
                responseText = req.responseText.substring(2, req.responseText.length - 1); else responseText = req.responseText;
            try {
                that.parsedResponse = YAHOO.lang.JSON.parse(responseText);
            } catch(x) {

            }
            that.mapHelper.map.SetClientToken(that.parsedResponse.data);
        },
         attractionHandler:function(req) {
         var that = attractionsHandler;
            if (req.responseText.indexOf("(") >= 0 && req.responseText.indexOf("(") < 5)
                responseText = req.responseText.substring(2, req.responseText.length - 1); else responseText = req.responseText;
            try {
                that.parsedResponse = YAHOO.lang.JSON.parse(responseText);
            } catch (x) {
                that.clearResults();
                document.getElementById("resultnav1").style.display = "none";
                document.getElementById("resultnav2").style.display = "none";
                document.getElementById("resultsSection").style.display = "block";
                that.results = yuiDom.get("results");
                p1 = document.createElement("p");
                p1InnerText = document.createTextNode("We're sorry, an error occurred.");
                p1.appendChild(p1InnerText);
                that.results.appendChild(p1);
                return;
            }
            if (category) {
                if (category.value != null && category.value != '') {
                    that.setAttractions(that.parsedResponse);
                    if(that.parsedResponse.status != 'error') {
                        that.previousNextHandler(that.parsedResponse)
                    } else {
                        localAreaMap.clusterLayer.DeleteAllShapes();
                    }
                }
            }
        },
        previousNextHandler:function(parsedResponse) {
            var that = attractionsHandler;
            totalResults = that.parsedResponse.data.localAttractions.length;

            var totalCount = document.getElementById("totalCount");
            var totalCount2 = document.getElementById("totalCount2");
            totalCount.innerHTML = totalResults;
            totalCount2.innerHTML = totalResults;

            var fromCount = document.getElementById("fromCount");
            var fromCount2 = document.getElementById("fromCount2");
            var toCount = document.getElementById("toCount");
            var toCount2 = document.getElementById("toCount2");

            fromCount.innerHTML = that.minIndex + 1;
            fromCount2.innerHTML = that.minIndex + 1;

            if (totalResults < (that.minIndex + that.maxPerPage) - 1) {
                toCount.innerHTML = totalResults;
                toCount2.innerHTML = totalResults;

                if (totalResults <= that.maxPerPage) {
                    document.getElementById("prevNextLink1").style.display = "none";
                    document.getElementById("prevNextLink2").style.display = "none";
                }
            } else {
                toCount.innerHTML = (that.minIndex + that.maxPerPage);
                toCount2.innerHTML = (that.minIndex + that.maxPerPage);
                document.getElementById("prevNextLink1").style.display = "block";
                document.getElementById("prevNextLink2").style.display = "block";
            }

            if (that.minIndex == '0') {
                document.getElementById("previousLink").className = 'previousLinkMin';
                document.getElementById("previousLink2").className = 'previousLinkMin';
            } else {
                document.getElementById("previousLink").className = 'previousLinkCount';
                document.getElementById("previousLink2").className = 'previousLinkCount';
            }
            if (((that.minIndex + that.maxPerPage)) >= totalResults) {
                document.getElementById("nextLink").className = 'nextLinkMax';
                document.getElementById("nextLink2").className = 'nextLinkMax';
            } else {
                document.getElementById("nextLink").className = 'nextLink';
                document.getElementById("nextLink2").className = 'nextLink';
            }
            //here you have to set total results
            //and change class of prev if there are no more.
        },
         formatPhone:function(num) {
            num = num.replace("-", "");
            _return = "(";
            var ini = num.substring(0, 3);
            _return += ini + ") ";
            var st = num.substring(3, 6);
            _return += st + "-";
            var end = num.substring(6, 10);
            _return += end;
            return _return;
        },
        toggleLoadingMessage: function() {
            if(yuiDom.hasClass('loadingMessage','show')) {
                yuiDom.removeClass('loadingMessage', 'show');
            } else {
             yuiDom.addClass('loadingMessage', 'show');
              var loadingMessage = yuiDom.get("loadingMessage");
              loadingMessage.style.left = yuiDom.getViewportWidth()/2 - yuiDom.getStyle(loadingMessage,"width").substring(0,yuiDom.getStyle(loadingMessage,"width").length-2)/2 + "px";
              loadingMessage.style.top = yuiDom.getViewportHeight()/2  + yuiDom.getDocumentScrollTop() - yuiDom.getStyle(loadingMessage,"height").substring(0,yuiDom.getStyle(loadingMessage,"width").length-2)/2 + "px";
            }
        },
        setAttractions:function(parsedResponse) {
            var that = attractionsHandler;
//            that.toggleLoadingMessage();
            that.results = yuiDom.get("results");
            document.getElementById("resultsSection").style.display = "block";
            localAreaMap.attractionsLayer.DeleteAllShapes();
            localAreaMap.totalPushPinsLatLong = new Array();
            that.clearResults();
            var items = that.parsedResponse.data.localAttractions;
            if (!items || items.length == 0) {
                document.getElementById("resultnav1").style.display = "none";
                document.getElementById("resultnav2").style.display = "none";
                p1 = document.createElement("p");
                p1InnerText = document.createTextNode("We're sorry, the attraction you selected is unavailable in this area.");
                p1.appendChild(p1InnerText);
                that.results.appendChild(p1);
            } else {
                document.getElementById("resultnav1").style.display = "block";
                document.getElementById("resultnav2").style.display = "block";
                table = document.createElement("table");
                tbody = document.createElement("tbody");

                table.appendChild(tbody);
                that.results.appendChild(table);

                for (var i = that.minIndex; i < that.minIndex + Math.round((that.maxIndex - that.minIndex) / 2); i++) {
                    if (i >= items.length) break;

                    tr = document.createElement("tr");
                    var item = items[i];
                    var item2 = items[Math.round((that.maxIndex - that.minIndex) / 2) + i];
                    var name = item.name;
                    ;
                    var distance = item.distance;
                    var phone = item.phoneNumber;

                    var address = "";
                    if (item.address != null) {
                        street = item.address.streetAddress;
                        city = item.address.city;
                        state = item.address.state;
                        postal = item.address.postalCode;
                        country = item.address.country;
                        latitude = item.address.latitude;
                        longitude = item.address.longitude;

                        if (street != '' && city != '') address = street + ", " + city + ", " + state + " " + postal + " " + country;

                        this.td1 = that.addResult(i, name, latitude, longitude, distance, address, phone, "/" + SW.tools.getSkinName() + "/property/area/directions_results.html?propertyID=" + localAreaMap.propId + "&lat=" + item.address.latitude + "&long=" + item.address.longitude + "&toHotel=false" + "&name=" + item.name);
                    }
                    if (item2 != null) {
                        var name2 = item2.name;
                        ;
                        var distance2 = item2.distance;
                        var phone2 = item2.phoneNumber;

                        var address2 = "";
                        if (item2.address != null) {
                            street2 = item2.address.streetAddress;
                            city2 = item2.address.city;
                            state2 = item2.address.state;
                            postal2 = item2.address.postalCode;
                            country2 = item2.address.country;
                            latitude2 = item2.address.latitude;
                            longitude2 = item2.address.longitude;

                            if (street2 != '' && city2 != '') address2 = street2 + ", " + city2 + ", " + state2 + " " + postal2 + " " + country2;
                            this.td2 = that.addResult(Math.round((that.maxIndex - that.minIndex) / 2) + i, name2, latitude2, longitude2, distance2, address2, phone2, "/" + SW.tools.getSkinName() + "/property/area/directions_results.html?propertyID=" + localAreaMap.propId + "&lat=" + item2.address.latitude + "&long=" + item2.address.longitude + "&toHotel=false" + "&name=" + item2.name);
                        }
                    }
                    tr.appendChild(this.td1);
                    if (item2 != null) {
                        tr.appendChild(this.td2);
                    }
                    tbody.appendChild(tr);

                }
                // Plotting attractions to map seperately so that the sequence is maintained for numbering of pushPins
                for (var i = that.minIndex; i <= that.maxIndex; i++) {
                    if (i >= items.length) break;
                    var item = items[i];

                    htmlBlock = item.name;
                    htmlBlock = htmlBlock + '<br/>' + item.address.streetAddress + ' ' + item.address.city + ' ' + item.address.state + ' ' + item.address.postalCode + '<br/>';
                     if(!that.disableDrivingDirections) {
                        htmlBlock = htmlBlock + '<a href=/' + SW.tools.getSkinName() + '/property/area/directions_results.html?propertyID=' + localAreaMap.propId + '&lat=' + item.address.latitude + '&long=' + item.address.longitude + '&toHotel=false' + '&name=' + item.name + '>Directions</a>';
                    }
                    localAreaMap.addAttractions(htmlBlock, item.address.latitude, item.address.longitude, (i + 1));
                }
                 localAreaMap.totalPushPinsLatLong = localAreaMap.customAddLatLongArray.concat(localAreaMap.pushPinLatLong,localAreaMap.attractionsLatLongArray);
                localAreaMap.mapHelper.map.SetMapView(localAreaMap.totalPushPinsLatLong);
                localAreaMap.minIndex = that.minIndex;
                localAreaMap.cluster();

            }
            document.getElementById("resultsHeader").innerHTML = document.categoryForm.attractionCategory[document.categoryForm.attractionCategory.selectedIndex].text;
        },
         addResult:function(count, name, latitude, longitude, distance, address, phone, link) {
            var that = attractionsHandler;

            td = document.createElement("td");
            h4 = document.createElement("h4");
            h4InnerText = document.createTextNode((count + 1) + ") " + name + " (" + Math.round((distance * 1.6) * 100) / 100 + ' km' + "/" + Math.round(distance * 100) / 100 + ' miles' + ")");
            p1 = document.createElement("p");
            p1InnerText = document.createTextNode(address);
            p2 = document.createElement("p");
            p2InnerText = document.createTextNode("Phone: " + that.formatPhone(phone));
            p3 = document.createElement("p");
            aLink = document.createElement("a");
            aLink.setAttribute("href", link);
            aLinkInnerText = document.createTextNode("Directions >");

            td2 = document.createElement("td");
            h42 = document.createElement("h4");
            h4InnerText2 = document.createTextNode(count + ") " + name + " (" + Math.round((distance * 1.6) * 100) / 100 + ' km' + "/" + Math.round(distance * 100) / 100 + ' miles' + ")");
            p12 = document.createElement("p");
            p1InnerText2 = document.createTextNode(address);
            p22 = document.createElement("p");
            p2InnerText2 = document.createTextNode(phone);
            p32 = document.createElement("p");
            aLink2 = document.createElement("a");
            aLink2.setAttribute("href", link);
            aLinkInnerText2 = document.createTextNode("Directions >");
            td2.appendChild(h42);

            td.appendChild(h4);
            h4.appendChild(h4InnerText);
            p1.appendChild(p1InnerText);
            p2.appendChild(p2InnerText);

            p3.appendChild(aLink);
            aLink.appendChild(aLinkInnerText);
            if (address != '') td.appendChild(p1);
            if (phone != '') td.appendChild(p2);
             // Check if the property has disabled driving directions
            if(!that.disableDrivingDirections) {
                td.appendChild(p3);
            }


            //        htmlBlock = name;
            //        localAreaMap.addAttractions(htmlBlock, latitude,longitude, count);
            return td;

        },
        clearResults:function() {
           elem = document.getElementById("results");
            while (elem.childNodes.length > 0) {
                elem.removeChild(elem.firstChild);
            }
        }


    };
      SW.widget.AttractionsHandler = attractionsHandler;
})();
