﻿// JScript File
var map;
var ew;

/*-----------Start eWindow----------------------*/
// Version 0.0  Initial version 
// Version 0.1  10/10/2006 Added E_STYLE_7 
// Version 0.2  17/05/2007 Added .isHidden() and .supportsHide()
// Version 0.3  14/09/2007 added .zindex()

      function EStyle(stemImage, stemSize, boxClass, boxOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
        //this.border = border;
        
        // Known fudge factors are:
        // Firefox (1.0.6 and 1.5)    5, -1
        // IE 6.0                     0, -1
        // Opera 8.54                 3, -1
        // Opera 9 prev               4, -1
        // Netscape (7.2, 8.0)        5, -1
        // Safari                     5, -1        
        
        var agent = navigator.userAgent.toLowerCase();
        
        var fudge = 5;  // assume Netscape if no match found
       
        if (agent.indexOf("opera") > -1) {
          fudge = 3;
        }   
        if (agent.indexOf("firefox") > -1) {
          fudge = 5;
        }   
        if (agent.indexOf("safari") > -1) {
          fudge = 5;
        }   
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
          fudge = 0;
        }
        this.fudge = fudge;
      }
      
      var E_STYLE_1 = new EStyle("stem1.png", new GSize(81,87),  "estyle1", new GPoint(-30,87-3));
      var E_STYLE_2 = new EStyle("stem2.png", new GSize(81,87),  "estyle2", new GPoint(-30,87-1));
      var E_STYLE_3 = new EStyle("stem3.png", new GSize(81,87),  "estyle3", new GPoint(-30,87-10));
      var E_STYLE_4 = new EStyle("stem3.png", new GSize(81,87),  "estyle4", new GPoint(-30,87-10));
      var E_STYLE_5 = new EStyle("stem1.png", new GSize(81,87),  "estyle5", new GPoint(-30,87-3));
      var E_STYLE_6 = new EStyle("stem6.png", new GSize(100,50), "estyle6", new GPoint(100-2,20));
      var E_STYLE_7 = new EStyle("stem7.png", new GSize(24,24),  "estyle2", new GPoint(-10,23));
      var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0,0));

      function EWindow(map,estyle) {
        // parameters
        this.map=map;
        this.estyle=estyle;
        // internal variables
        this.visible = false;
        // browser - specific variables
        this.ie = false;
        var agent = navigator.userAgent.toLowerCase();
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){ this.ie = true} else {this.ie = false}
      } 
      
      EWindow.prototype = new GOverlay();

      EWindow.prototype.initialize = function(map) {              
        var div1 = document.getElementById("infoDiv");
        div1.style.position = "static";
        pos.apply(div1);
        map.getContainer().appendChild(div1);
        this.div1 = div1;   
      }

      EWindow.prototype.openOnMap = function(point, html) {
        //this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = html;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        this.openOnMap(marker.getPoint(), html);
      }      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        pos.apply(this.div1);
      }

      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.visible = false;
      }
      
      EWindow.prototype.isHidden = function() {
        return !this.visible;
      }
      
      EWindow.prototype.supportsHide = function() {
        return true;
      }

      EWindow.prototype.zindex = function(zin) {
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z+zin;
      }

      
/*--------------------End eWindow------------------------*/

function loadMapNoControls(mapDivId) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(mapDivId));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
	}
}

function setCenterToPoint(point, zoom)
{
	map.setCenter(point, zoom);
}

    /*---Single map point on small map---*/
    function createSmallInfoMarker(point, html, onClickDestination) 
    {                     
        ew = new EWindow(map, E_STYLE_7);      
        map.addOverlay(ew);
        
        var Icon = new GIcon(G_DEFAULT_ICON);
        Icon.image = "http://82.138.226.79/Styles/StyleImages/google_maps_marker.png";

        //var marker = createEWindowMarker(point,address, ew);
        var marker = new GMarker(point, Icon);
        map.addOverlay(marker);  
                     
        GEvent.addListener(marker, "click", function() {
          window.location = onClickDestination;
        });
            
        // The new marker "mouseover" listener - open info window
        GEvent.addListener(marker,"mouseover", function() {
          ew.openOnMarker(marker,html);
          marker.setImage("http://82.138.226.79/Styles/StyleImages/google_maps_marker_hover.png");
        }); 
        
        // The new marker "mouseout" listener - close info window
        GEvent.addListener(marker,"mouseout", function() {
          ew.hide();
          marker.setImage("http://82.138.226.79/Styles/StyleImages/google_maps_marker.png");
        }); 
               
        // ========== Close the EWindow if theres a map click ==========
        GEvent.addListener(map, "click", function(overlay,point) {
        if (!overlay) {
          ew.hide();
        }
        });          
    } 
    
    function createSmallInfoMarkerNoMouseOut(point, html, onClickDestination) 
    {                     
        ew = new EWindow(map, E_STYLE_7);      
        map.addOverlay(ew);
        
        var Icon = new GIcon(G_DEFAULT_ICON);
        Icon.image = "http://82.138.226.79/Styles/StyleImages/google_maps_marker.png";

        //var marker = createEWindowMarker(point,address, ew);
        var marker = new GMarker(point, Icon);
        map.addOverlay(marker);  
                     
        GEvent.addListener(marker, "click", function() {
          window.location = onClickDestination;
        });
            
        // The new marker "mouseover" listener - open info window
        GEvent.addListener(marker,"mouseover", function() {
          ew.openOnMarker(marker,html);
          marker.setImage("http://82.138.226.79/Styles/StyleImages/google_maps_marker_hover.png");
        }); 
        
        // The new marker "mouseout" listener - close info window
        GEvent.addListener(marker,"mouseout", function() {
          //ew.hide();
          marker.setImage("http://82.138.226.79/Styles/StyleImages/google_maps_marker.png");
        }); 
               
        // ========== Close the EWindow if theres a map click ==========
        GEvent.addListener(map, "click", function(overlay,point) {
        if (!overlay) {
          ew.hide();
        }
        });          
    } 
