// Version 0.0  Initial version


      function EStyle(stemImage, stemSize, boxClass, boxOffset, windowOffset, closeButtonOffset) {
        this.stemImage = stemImage;
        this.stemSize = stemSize;
        this.boxClass = boxClass;
        this.boxOffset = boxOffset;
		this.windowOffset = windowOffset;
		this.closeButtonOffset = closeButtonOffset;
        //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), new GPoint(0,0));
	      var E_STYLE_2 = new EStyle("stem2.png", new GSize(81,87), "estyle2", new GPoint(-30,87-1), new GPoint(0,0));
	      var E_STYLE_3 = new EStyle("stem3.png", new GSize(81,87), "estyle3", new GPoint(-30,87-10), new GPoint(0,0));
	      var E_STYLE_4 = new EStyle("stem3.png", new GSize(81,87), "estyle4", new GPoint(-30,87-10), new GPoint(0,0));
	      var E_STYLE_5 = new EStyle("stem1.png", new GSize(81,87), "estyle5", new GPoint(-30,87-3), new GPoint(0,0));
	      var E_STYLE_6 = new EStyle("stem6.png", new GSize(100,50), "estyle6", new GPoint(100-2,20), new GPoint(0,0));
	     
	     // custom styles
	     // image, size, html box offset, image offset, close (x) button offset
	     // big infowindow
	     var E_STYLE_7 = new EStyle("http://www.worldcasinodirectory.com/layout/maps/ewindow/overlay_window.png", new GSize(302,240), "estyle7", new GPoint(10,48), new GPoint(-141,9), new GPoint(277, 217));
	     // small infowindow
	     var E_STYLE_8 = new EStyle("http://www.worldcasinodirectory.com/layout/maps/ewindow/overlay_window_small.png", new GSize(242,108), "estyle8", new GPoint(10,28), new GPoint(-114,8), new GPoint(217, 85));

      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) {
	//html
        var div1 = document.createElement("div");
        div1.style.position = "absolute";
        //map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div1);
	//background image
        var div2 = document.createElement("div");
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div2);
	//close (x) link
	var div3 = document.createElement("div");
        div3.style.position = "absolute";
        div3.style.width = "15px";
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div3);
        this.div1 = div1;
        this.div2 = div2;
        this.div3 = div3;
      }

      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        this.div1.innerHTML = '<div class="' + this.estyle.boxClass + '" id="wcdInfoWindow"><nobr>' + html + '</nobr></div>';
        if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='scale');";
          this.div2.innerHTML = '<div style="height:' +this.estyle.stemSize.height+ 'px; width:'+this.estyle.stemSize.width+'px; ' +loader+ '" ></div>';
        } else {
          this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
        }
	if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.worldcasinodirectory.com/layout/maps/ewindow/t.gif', sizingMethod='scale');";
          this.div3.innerHTML = '<div style="text-align: right; height:15px; width:15px; ' +loader+ '" ></div>';
        } else {
          this.div3.innerHTML = '<a class="imagelink" href="javascript:closeOverlay();"><img src="http://www.worldcasinodirectory.com/layout/maps/ewindow/t.gif" width="15" height="15" border="0"></a>';
        }
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z+2;
        this.div2.style.zIndex = z;
	this.div3.style.zIndex = z+1;
        this.visible = true;
        this.show();
        this.redraw(true);
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x + this.estyle.windowOffset.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y + this.estyle.windowOffset.y;
        this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
      }
      

      EWindow.prototype.redraw = function(force) {
        if (!this.visible) {return;}
        var p = this.map.fromLatLngToDivPixel(this.point);
        this.div2.style.left   = (p.x + this.offset.x) + "px";
        this.div2.style.bottom = (-p.y + this.offset.y -this.estyle.fudge) + "px";
        this.div1.style.left   = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
        this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
        this.div3.style.left   = (p.x + this.offset.x + this.estyle.closeButtonOffset.x) + "px";
        this.div3.style.bottom = (-p.y + this.offset.y + this.estyle.closeButtonOffset.y) + "px";
       }

      EWindow.prototype.remove = function() {
      	//Effect.DropOut('wcdInfoWindow');
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.div3.parentNode.removeChild(this.div3);
        this.visible = false;
      }

      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }

      EWindow.prototype.show = function() {
        this.div1.style.display="";
        this.div2.style.display="";
        this.div3.style.display="";
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        this.div1.style.display="none";
        this.div2.style.display="none";
        this.div3.style.display="none";
        this.visible = false;
      }
      

        
