﻿
Type.registerNamespace("Weather2.MapSearch");

Weather2.MapSearch.Map = function(service, mapArgs) {
    /// <summary>
    ///   The VE Map.
    ///   Supports load on demand
    /// </summary>
    /// <param name="service">The webservice to call for the map data.</param>
    /// <param name="mapArgs">The map initalisation data.</param>

    this._service = service;
    
    this._mapArgs = mapArgs;
    
    this._map = null;
    
    this._pinID = 0;
    
    this._zoomlevel = 0;
    
    this._layer = null;
    
    this._activity_id = 0;   
    
    this._clicked_token = 0;
    
    this._post_fix = '';
        
    this._server_name="http://www.myweather2.com";
    
    //this._server_name="http://localhost:2622/MyWeather2COM";
    
    //this._server_name="http://62.232.41.224/weather2/w2website";
    
    //popup specific;
    this._PopupPrefix = "POPUP";
    
    this._currentpin = null;
    
    this._currentindex = 0;   
    
    //Birdseye - fix due to not lat/long data available
    this._MapBEyeCentre;  
    
    this._latoffset = 0.005;
    
    this._lonoffset = 0.01;    
    
    this.GetPinDataDelegate = null;
    
    this.PinHoverDelegate = null;
    
    this.OnClickPinDelegate=null;
    
    this.GetMapZoomLevelOnChangeEnd=null;
    
    this.OnMouseMoveOverMap =null;
    
    this._init();
}

Weather2.MapSearch.Map.prototype = {

    _init: function() {
        /// <summary>
        ///   Initialises the Map.
        /// </summary>       
        
        // Firefox support - see VE wiki.
//        var ffv = 0;
//        var ffn = "Firefox/"
//        var ffp = navigator.userAgent.indexOf(ffn);
//        if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
//        // If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
//        if (ffv >= 1.5) {
//          Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
//        }
        
        
        //setup map
        this._map = new VEMap(this._mapArgs.DivID);    
        this._map.LoadMap(this._mapArgs.Center,this._mapArgs.Zoomlevel,this._mapArgs.Style,this._mapArgs.Fixed,this._mapArgs.Mode, false); 
        this._map.SetScaleBarDistanceUnit(this._mapArgs.Scale);
        
        this._layer = new VEShapeLayer();         
        this._map.AddShapeLayer(this._layer);
        
        // Get the correct activity id
        if ($get('ctl00_MiddleContentHolder_activity_id'))               
            this._activity_id=$get('ctl00_MiddleContentHolder_activity_id').value;
           
        if ($get('ctl00_MiddleContentHolder_txtpostfix'))               
            this._post_fix = $get('ctl00_MiddleContentHolder_txtpostfix').value;
            
        var ctlZoom=document.getElementById('SpanZoomLevel'); 
        
        if (ctlZoom!=null)               
            ctlZoom.innerHTML = this._mapArgs.Zoomlevel;                 
    
        this._GetTipsData(this._mapArgs.Zoomlevel);
        
        this._service.GetTopInstructions(this._activity_id, Function.createDelegate(this, this._OnTopInstructionDataSucceeded), Utility.OnFailed);                    
        
        
        if (this._activity_id == "1" || this._activity_id == "17")
        {
            this.OnClickPinDelegate = Function.createDelegate(this, this._showOnClickPin);                
            this._map.AttachEvent("onclick", this.OnClickPinDelegate);            
        }
        else
        {
            
            //setup the function to get new data whenever the map changes
            this.GetPinDataDelegate = Function.createDelegate(this, this._GetPinData);
            this._map.AttachEvent("onchangeview", this.GetPinDataDelegate);
        
            //turn off the standard popup and attach our custom handler        
            this.PinHoverDelegate = Function.createDelegate(this, this._PinActivate);
            this._map.AttachEvent("onmouseover", this.PinHoverDelegate);
            this._map.AttachEvent("onclick", this.PinHoverDelegate);
        }
                                        
        this.GetMapZoomLevelOnChangeEnd = Function.createDelegate(this, this._OnStartZoomHandler);
        this._map.AttachEvent("onendzoom", this.GetMapZoomLevelOnChangeEnd);
                       
        this._map.DeleteAllShapes();
        
        //Setup additional storage for shapes
        VEShape.prototype.Bounds = "";  
	    VEShape.prototype.Drawn = false;    
	    VEShape.prototype.Match = false;
        
        /*
        if ($get('ctl00_MiddleContentHolder_activity_id'))               
            this._activity_id=$get('ctl00_MiddleContentHolder_activity_id').value;
        */
        
        //get the data for the default view
        if (this._activity_id != "1" && this._activity_id != "17")                
            this._GetPinData();
        else
        {
            var loc_provided = "0";                   
            var pl_lat = 0;
            var pl_lon = 0;
            var icon_text = "";
            
            pl_lat = parseFloat($get('ctl00_MiddleContentHolder_mapLatitude').value);
            pl_lon = parseFloat($get('ctl00_MiddleContentHolder_mapLongitude').value);   
                        
            var newShape = new VEShape(VEShapeType.Pushpin, new VELatLong(pl_lat, pl_lon));                 
            //newShape.Match = true;
            
            if ($get('ctl00_MiddleContentHolder_from_map_search'))               
                loc_provided=$get('ctl00_MiddleContentHolder_from_map_search').value;     
               
            if (loc_provided=="1")
            {
                if ($get('ctl00_MiddleContentHolder_activity_id'))
                {                    
                    if ($get('ctl00_MiddleContentHolder_activity_id').value == $get('ctl00_MiddleContentHolder_mapActivity_ID').value)
                    {
                        newShape.SetCustomIcon(icon_text + " <img src=\"" + this._server_name + "/images/pin-orange-2.gif\"/>");
                        this._layer.AddShape(newShape);                                              
                     }
                }
            }                  
            
        }
            
             
       var _screen_width = screen.availWidth;
       var _screen_height = screen.availHeight;
       
//       if (_screen_width <=1100)
//            _screen_width = 600;
//       else
//           _screen_width = 750;
        
       this._map.Resize(565, 500);
    },  
    
    
    _GetActivityID: function()
    {
        if ($get('ctl00_MiddleContentHolder_activity_id'))               
            this._activity_id=$get('ctl00_MiddleContentHolder_activity_id').value;
        else
            this._activity_id="1";
    },

    _GetPinData: function() {  
        /// <summary>
        ///   Get the latest map data from the webservice.
        /// </summary>
            
        //encode the current map bounds
        var points = new Array();
        var zoom;
        
        if (this._map.GetMapStyle() == VEMapStyle.Birdseye) {    
            //set zoomlevel      
            zoom = 19;
            points.push(new VELatLong(this._MapBEyeCentre.Latitude + this._latoffset, this._MapBEyeCentre.Longitude - this._lonoffset));
            points.push(new VELatLong(this._MapBEyeCentre.Latitude - this._latoffset, this._MapBEyeCentre.Longitude + this._lonoffset));
        }else {
            var view = this._map.GetMapView();
            points.push(view.TopLeftLatLong);
            points.push(view.BottomRightLatLong);
            
            
            //get zoomlevel
            zoom = this._map.GetZoomLevel();

            //to try to support Birsdeye we store the centre as currently there is no way to get the lat/long in birdseye :(
            this._MapBEyeCentre = this._map.GetCenter();

        }
        var bounds = Utility.createEncodings(points);
        if (this._zoomlevel != zoom) {
            //clear existing pins
            this._layer.DeleteAllShapes();
            this._zoomlevel = zoom;
        }
        
        //this._GetActivityID();
        
        //call webservice
        this._service.GetClusteredMapData(bounds, zoom, this._activity_id, this._post_fix, Function.createDelegate(this, this._OnMapDataSucceeded), Utility.OnFailed);
    },

    _OnMapDataSucceeded: function(results) {
        /// <summary>
        ///   Receive data for map.
        /// </summary>  
        /// <param name="result">The webservice result object - Optomised CSV string</param>  
            
        //decode pins
        var result=results.split(",")
        var locs = Utility.decodeLine(result[0]);
        
         var loc_provided = "0";                   
        var pl_lat = 0;
        var pl_lon = 0;
        
        
        if ($get('ctl00_MiddleContentHolder_from_map_search'))               
            loc_provided=$get('ctl00_MiddleContentHolder_from_map_search').value;                                       
        
        if (locs.length == 0)
        {            
            if (loc_provided=="1")
            {
                if ($get('ctl00_MiddleContentHolder_activity_id'))
                {                    
                        pl_lat = parseFloat($get('ctl00_MiddleContentHolder_mapLatitude').value);
                        pl_lon = parseFloat($get('ctl00_MiddleContentHolder_mapLongitude').value);                        
                        loc_provided = 1;                                                
                        
                        var newShape = new VEShape(VEShapeType.Pushpin, new VELatLong(pl_lat, pl_lon));                     
                        newShape.Match = true;
                        newShape.SetCustomIcon(icon_text + " <img src=\"" + this._server_name + "/images/pin-orange-2.gif\"/>");                                
                        
                        this._layer.AddShape(newShape);
                }
            }           
            
            
        }
        else
        {        
            //add new pins
            for(x = 0; x < locs.length; x++) {
                var loc = locs[x];
                var bounds = result[x+1];
                var drawn = false;
                
                //see if it is in the current drawn pins
                for(i = 0; i < totalpins; i++) {
                   var currentshape = this._layer.GetShapeByIndex(i);
                    if (currentshape.Bounds == bounds) {
                        drawn = true;
                        currentshape.Match = true;
                        break; //shortcut loop
                    }
                }            
                
                if (!drawn) {
                    var newShape = new VEShape(VEShapeType.Pushpin, loc); 
                    newShape.Bounds = bounds;         
                    newShape.Drawn = drawn;
                    newShape.Match = true;
                    //set custom pin. 
                    //[IDEA FOR YOU TO EXPLORE]
                    //If you where to pass the quantity or the type of pin in the csv string you could have different pins here!         
                    
                    var icon_text = "<img src=\"" + this._server_name + "/images/pin-orange.png\"/>";
                    
                    if (loc_provided=="1")
                    {
                        if ($get('ctl00_MiddleContentHolder_activity_id'))
                        {
                            if ($get('ctl00_MiddleContentHolder_activity_id').value == $get('ctl00_MiddleContentHolder_mapActivity_ID').value)
                            {
                                pl_lat = parseFloat($get('ctl00_MiddleContentHolder_mapLatitude').value);
                                pl_lon = parseFloat($get('ctl00_MiddleContentHolder_mapLongitude').value);                        
                                loc_provided = 1;
                                
                                if (pl_lat.toFixed(2) == loc.Latitude.toFixed(2) && pl_lon.toFixed(2) == loc.Longitude.toFixed(2))
                                    icon_text = "<img src=\"" + this._server_name + "/images/pin-orange-2.gif\"/>";
                            }            
                        }
                    }
        
                   // if (this._activity_id=="8") 
                   //     {               
                        
                   //     newShape.SetCustomIcon(icon_text + " <img align=\"top\" src=\"" + this._server_name + "/images/pin-orange.png\"/>");
                        
                    //    }
                  //  else
                  
                 // icon_text = "<img src=\"" + this._server_name + "/images/pin-orange-2.gif\"/>";
                  
                        newShape.SetCustomIcon(icon_text);
                    //newShape.IconUrl = "dot.gif" 
                    
                    this._layer.AddShape(newShape);  
                }  
            }
            
        }
        
        //remove all existing pins on matches from the screen
        var totalpins = this._layer.GetShapeCount();
        for(x = (totalpins-1); x >=0; x--) {
            var currentshape = this._layer.GetShapeByIndex(x);
            if (!currentshape.Match) {
                this._layer.DeleteShape(currentshape);
            }
            //set match back to false for next time we pan the map.s
            currentshape.Match = false;
        }             
    },
    
    
//    _OnMouseMoveMap: function(el) {
//    
//        var x = el.mapX;
//        
//        var y = el.mapY;
//        
//        var pixel = new VEPixel(x, y);
//        
//        var LL = this._map.PixelToLatLong(pixel);
//        
//        var _latitude=document.getElementById('SpanLatitude');
//        
//        var _longitude = document.getElementById('SpanLongitude');
//        
//        _latitude.innerHTML = LL.Latitude.toFixed(2);         
//        
//        _longitude.innerHTML = LL.Longitude.toFixed(2);
//                
//    },
    
    
    _OnStartZoomHandler: function(zh) {
        /// <summary>
        ///   Receives any mouse of event from VE
        /// </summary>  
        /// <param name="e">The MapEvent object</param>     
            var ctlZoom = null;
            
            var z =0;
            
            var stop_zoom_in = 0;
            
            if (this._activity_id !="0") {
                
                z = zh.zoomLevel;
                
                //this._GetActivityID();
                
                //coastal and sea areas
                if (this._activity_id == "8")
                {
                    if (z >= 13)
                    {
                        this._map.SetZoomLevel(12);
                        
                        z = 12;
                        
                        stop_zoom_in = 1;
                    }
                }                                
                
                
                //Hill and climbing
                if (this._activity_id == "11")
                {
                    if (z >= 11)
                    {
                        this._map.SetZoomLevel(10);
                        
                        z = 10;    
                        
                        stop_zoom_in = 1;
                    }
                }                                
                
                //Snow
                if (this._activity_id == "9")
                {
                    if (z >= 13)
                    {
                        this._map.SetZoomLevel(12);
                        
                        z = 12;   
                        
                        stop_zoom_in = 1;
                    }
                }                                
                
                
                ctlZoom=document.getElementById('SpanZoomLevel');    
                if (ctlZoom!=null)                           
                    ctlZoom.innerHTML = z ;                                        
                       
                this._GetTipsData(z);
                
                this._zoomlevel =z ;
                                
            
            }
            
            /*
            else {
                
                //ctlZoom=document.getElementById('SpanZoomLevel');    
                            
                //z = ctlZoom.innerHTML;
                
                //this._map.SetZoomLevel(z);
                
            }*/
                        
                        
            
//            //callback when data returns from web service
//            function OnTipsDataSucceeded(results, eventArgs)
//            {                
//                var tip=document.getElementById('tips');                               
//                
//                tip.innerHTML = results;
//                
//            }
        
    }, 
    
     _GetTipsData: function(zoomlevel) {
        
         var tip='';
         
         var _ignore = false;
         
         //this._GetActivityID();
         
         switch (this._activity_id)
            {

                    // city/town
                case "1":
//                    if (zoomlevel < 6)
//                        tip = "<b>Tip: </b>"
//                            + "Use the controls on the top left of the map, or your mouse, to zoom in and move around the map.";
//                    else
//                        tip = "<b>Tip: </b>"
//                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the city/town name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Use the controls on the top left of the map, or your mouse, to zoom in and move around the map.";
                    else
                        tip = "<b>Tip: </b>"
                            + "A single tap on the left mouse button anywhere on the map will now bring up a clickable link to take you to the forecast for that location.";
                    break;


                // Golf Courses
                case "7":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Use the controls on the top left of the map, or your mouse, to zoom in and move around the map.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the club/course name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                            //+ ""
                            //+ "<b>Hint:</b>"
                            //+ "Zooming in closer might reveal more golf courses for that area! ";
                    break;


                // Football
                case "10":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. It will give the Football Club or Stadium name and allow you to access the Forecast.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the football/stadium name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    break;


                // Horse racing
                case "13":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. It will give the horse racecourse and allow you to access the Forecast.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the racecourse name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    break;


                // Snow reports
                case "9":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. It will give the snow sport resort name and allow you to access the Forecast.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the snow sport resort name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    break;

                // Walking/Climbing
                case "11":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. It will give the walking/climbing name and allow you to access the Forecast.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over a pin icon. If the pin is for a single location then it will give the walking/climbing name and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    break;

                // Coastal courses
                case "8":
                    if (zoomlevel < 6)
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over an icon. It will give the name or location of the marine area and allow you to access the Forecast.";
                    else
                        tip = "<b>Tip: </b>"
                            + "Move the mouse curser over an icon. If the pin is for a single location then it will give the name or location of the marine area and allow you to access the Forecast. If the pin covers more than one location then you will need to zoom in closer until the pin is only for a single location.";
                    break;

                default:
                    _ignore=true;
                    break;
                    
            }
            
            if (_ignore == false)
            {
                var _span_tips = $get('tips');                               
                
                _span_tips.innerHTML = tip;           
                
              }
           
     },
     
     _OnTopInstructionDataSucceeded: function(results) {
        
         var tip=document.getElementById('SpanInstruct');                               
                
           tip.innerHTML = results;           
           
     },
    
    _PinActivate: function(e) {
        /// <summary>
        ///   Receives any mouse of event from VE
        /// </summary>  
        /// <param name="e">The MapEvent object</param>         
        var z = this._map.GetZoomLevel();
        
        
        if (e.elementID)
        {
            var popupShape = this._map.GetShapeByID(e.elementID)
            if (popupShape)
            {
                //set current pin
                this._currentpin = popupShape;
                this._currentindex = 0;
                
                //get the content for the pin.
                this._getAJAXContent();
                this._currentpin.SetDescription("<div id='" + this._PopupPrefix + this._currentpin.GetID() + "'>Loading...</div>");
                this._currentpin.SetTitle("");
            }
        }        
        
    },   
    
//    _handleDoubleClick : function(e)
//    {
//        var x = e.mapX;
//        var y = e.mapY;
//        
//        var pixel = new VEPixel(x, y);
//        var LL = this._map.PixelToLatLong(pixel);
//        
//        this._map.SetCenterAndZoom(new VELatLong(LL.Latitude, LL.Longitude), this._map.GetZoomLevel());      
//    },
    
    _showOnClickPin : function(el) {
        
        var z = el.zoomLevel;
        
        
        
        //this._GetActivityID();
                
        if (z>=6 && this._activity_id == "1")
        {   
            var x = el.mapX;
            
            var y = el.mapY;             
            
            var pixel = new VEPixel(x, y);
            
            var LL = this._map.PixelToLatLong(pixel);
            
            $get('SpanLatitude').innerHTML = "LatB: " + LL.Latitude.toFixed(2);
            
            this._service.GetNearestLocationBasedOnLatLong(LL.Latitude.toFixed(4), LL.Longitude.toFixed(4), this._activity_id, Function.createDelegate(this, this._OnClickLatitudeLongitudeDataSucceeded), Utility.OnFailed, LL);            
                  
        }
        
    },    
    
    _OnClickLatitudeLongitudeDataSucceeded: function(results,LL)
    {
        if (this._map !=null)
        {
                     
            $get('SpanLatitude').innerHTML = $get('SpanLatitude').innerHTML + "<br>LatA: " + LL.Latitude.toFixed(2) ;
            
            var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(LL.Latitude, LL.Longitude));
          
            shape.SetTitle("<a href='" + this._server_name + "/" + results + "' target=\"_parent\">Click <u>this text link</u> for forecast</a>");
                      
            //shape.SetTitle("<div style='display:none;' id='LLDS_1'><img align=\'absmiddle\' src='" + this._server_name + "/images/ajax-loader-small.gif' /> loading...</div><a onclick=\"showLoaderOnMapShape('LLDS_1');\" href='" + this._server_name + "/" + results + "'>Click <u>this text link</u> for forecast</a>");
            
            //shape.SetTitle("<div style='display:none;' id='LLDS_1'><img src='" + this._server_name + "/images/ajax-loader-small.gif' /></div><a onclick=\"showLoaderOnMapShape('LLDS_1');\" href='#'>Click <u>this text link</u> for forecast</a>");
            
            shape.SetDescription("");
            
            shape.SetCustomIcon("<span></span>");  
            
            this._map.DeleteAllShapes();
            
            this._map.AddShape(shape);
            
            this._map.ShowInfoBox(shape);    
            
            shape=null;     
          }     
        
    },
    
    _getAJAXContent: function() {
        /// <summary>
        ///   Request content for popup.
        /// </summary>  
        
        //call the web service
        this._service.GetPushPin(this._currentpin.Bounds, this._currentindex, this._activity_id, this._post_fix, Function.createDelegate(this, this._OnContentSucceeded), Utility.OnFailed, this._currentpin.GetID());
    }, 
    
    _OnContentSucceeded: function(result, ID) { 
        /// <summary>
        ///   Receive content for popup.
        /// </summary>  
        /// <param name="result">The webservice result object - JSON PinData</param>  
        /// <param name="ID">The popup ID associated with this call</param>  
            
        //verify this is the data for the current popup.
        var z = this._map.GetZoomLevel();
                
        if (ID==this._currentpin.GetID()) {
            if (this._map.GetMapMode() == VEMapMode.Mode3D) {
                //3D mode fails to be able to retrieve the div we placed earlier so resort to setting the title and description only
                this._currentpin.SetTitle(result.Title);
                this._currentpin.SetDescription(result.Details);
            }else {
                //create the content element
                
                //this._GetActivityID();
                
                var el = document.createElement("div");
                
                if (result.TotalRecords > 1) 
                    el.innerHTML = "Zoom in further to make " + result.TotalRecords + " pins visible to you.";
                else
                    el.innerHTML = "<a target=\"_parent\" href='" + this._server_name + "/map.ashx?type=v&aid=" + this._activity_id + "&lat=" + result.Latitude + "&lon=" + result.Longitude + "&url=" + result.Title + "'>Click <u>this text link</u> for " + result.PlaceName + " forecast</a>";
                    
                    //el.innerHTML = "<a href='" + this._server_name + "/forecast.aspx?l=" + result.Title + "&r=" + result.Details + "&c=" + result.Country + "&aid=" + this._activity_id + "'>Click <u>this text link</u> for " + result.Details + " forecast</a>";
                    
                    //el.innerHTML = "<a href='" + this._server_name + "/forecast.aspx?l=" + result.Title + "&r=" + result.Details + "&c=" + result.Country + "&aid=" + this._activity_id + "'>Click <u>this text link</u> for " + result.Details + " forecast</a>";
                    
                    
                        
                        
//                if (z < 6)
//                    el.innerHTML = "Zoom in further to make " + result.TotalRecords + " pin(s) visible to you.";
//                else
//                {                   
//                    
//                    
//                }
                    
                // el.innerHTML = (this._currentindex + 1) + " of " + result.TotalRecords + "Records" + result.Title + " - " + result.Details;
                
                //clear loading and attach the content
                $get(this._PopupPrefix + ID).innerHTML = "";
                $get(this._PopupPrefix + ID).appendChild(el);
                
                
                /*
                    //prev / next functionlaity
                    var prevButton = document.createElement("div");
                    prevButton.innerHTML = "Previous";
                    el.appendChild(prevButton);
                    Sys.UI.DomElement.addCssClass(prevButton, "ActionButton");
                    if (this._currentindex > 0) {  
                        $addHandler(prevButton,"click",Function.createDelegate(this, this._PreviousRecord));      
                    }else {
                        Sys.UI.DomElement.addCssClass(prevButton, "ButtonDisabled");
                    }
                    var nextButton = document.createElement("div");
                    nextButton.innerHTML = "Next";
                    el.appendChild(nextButton);  
                    Sys.UI.DomElement.addCssClass(nextButton, "ActionButton");
                    if (this._currentindex < (result.TotalRecords-1)) {  
                        $addHandler(nextButton,"click",Function.createDelegate(this, this._NextRecord));                         
                    }else {
                        Sys.UI.DomElement.addCssClass(nextButton, "ButtonDisabled");
                    }
                } */             
            }
        }
    },  
    
    _PreviousRecord: function() {
        /// <summary>
        ///   Request the previous record.
        /// </summary>  
        this._currentindex--;
        $get(this._PopupPrefix + this._currentpin.GetID()).innerHTML = "Loading...";
        this._getAJAXContent();
    },
    
    _NextRecord: function() {
        /// <summary>
        ///   Request the next record.
        /// </summary>      
        this._currentindex++;
        $get(this._PopupPrefix + this._currentpin.GetID()).innerHTML = "Loading...";
        this._getAJAXContent();
    },             

    Dispose: function() {
        /// <summary>
        ///   cleans up all objects. Detaches all events.
        /// </summary>
        if (this._map != null) {
//            if (this.GetPinDataDelegate!=null)
//                this._map.DetachEvent("onchangeview", this.GetPinDataDelegate);
//            
//            if (this.PinHoverDelegate!=null)
//                this._map.DetachEvent("onmouseover", this.PinHoverDelegate);
//                
//            if (this.PinHoverDelegate!=null)
//                this._map.DetachEvent("onclick", this.PinHoverDelegate);                
//                
//            if (this.OnClickPinDelegate!=null)
//                this._map.DetachEvent("onclick", this.OnClickPinDelegate);                
//                
//            if (this.GetMapZoomLevelOnChangeEnd!=null)
//                this._map.DetachEvent("onendzoom", this.GetMapZoomLevelOnChangeEnd);                
                
            this._map.Dispose();
        }    
        
        this._service = null;
        this._mapArgs = null;
        
        this._map = null;
        this._pinID = null;
        this._zoomlevel = null;
        this._layer = null;
        this._activity_id=null;
        //popup specific
        this._PopupPrefix = null;
        this._currentpin = null;
        this._currentindex = null;   
        
        //Birdseye
        this._MapBEyeCentre = null;  
        this._latoffset = null;
        this._lonoffset = null;    
        
        this.GetPinDataDelegate = null;
        this.PinHoverDelegate = null;   
        this.OnClickPinDelegate=null;
        this.GetMapZoomLevelOnChangeEnd=null;
        this.OnMouseMoveOverMap =null;
    }    
}

Weather2.MapSearch.Map.registerClass('Weather2.MapSearch.Map', null, Sys.IDisposable);

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


