// Version 0.0  Initial version
      function EStyle(stemImage, stemSize, boxClass, boxOffset, borderOffset) {
        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 = 0;
        }   
        if (agent.indexOf("firefox") > -1) {
          fudge = 0;
        }   
        if (agent.indexOf("safari") > -1) {
          fudge = 0;
        }   
        if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)){
		    if(agent.substr(agent.indexOf('msie')+5,1) < "7"){
		    	fudge = 0;
		    }else{
				fudge = 0;
		    }
        }
        this.fudge = fudge;
        this.borderOffset = borderOffset;
      }
      
      var E_STYLE_1 = new EStyle(localVar.hostUrl + "mapResources/$File/stem.png",
      							 new GSize(localVar.stemSize[0],localVar.stemSize[1]),
      							 "estyle1",
      							 new GPoint(0,localVar.stemSize[1]),
      							 20);
      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.createElement("div");
        div1.id = "EWindowMain";
        div1.style.position = "absolute";
        map.getPane(G_MAP_FLOAT_PANE).appendChild(div1);
        var div2 = document.createElement("div");
        div2.id = "EWindowSub";
        div2.style.position = "absolute";
        div2.style.width = this.estyle.stemSize.width+"px";
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
        this.div1 = div1;
        this.div2 = div2;
        
        //catch mouseevents in flyout
        addEventHandler(div1, "mousedown", stopPropagation);
		addEventHandler(div1, "mousemove", stopPropagation);
		addEventHandler(div1, "dblclick", stopPropagation);
      }
      EWindow.prototype.openOnMap = function(point, html, offset) {
        this.offset = offset||new GPoint(0,0);
        this.point = point;
        //Draw InfoWindow
        this.div1.innerHTML = 
        		'				<div id="infoWindowContainer" class="infoWindowContainer">' +
        		'					<div id="dataInfoWindow" class="'+ localVar.flyoutStyle +'">' + html + 
				'					</div>'+
				'				</div>';
		//draw Stem
        if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png")>-1) {
          this.estyle.stemImage = localVar.hostUrl + "mapResources/$File/stem.png";
		  var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.estyle.stemImage+"', sizingMethod='crop');";
          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="' + localVar.hostUrl + 'mapResources/$File/stem.png" width="' + this.estyle.stemSize.width +'" height="' + this.estyle.stemSize.height +'">';
        }
		//Set Opacity to 0
		if(localVar.fade){
			changeOpac(0,"EWindowMain","EWindowSub");
		}
		//correct Z-Index
        var z = GOverlay.getZIndex(this.point.lat());
        this.div1.style.zIndex = z;
        this.div2.style.zIndex = z+1;
        this.visible = true;
   		
        this.show();
        this.redraw(true);
        
        // move down  if infobox is not visible
		var mapBounds = localVar.mapGlobal.getBounds();
		var ne = mapBounds.getNorthEast();
		var pixelTop 	= localVar.mapGlobal.fromLatLngToDivPixel(ne).y;
		var pixelRight	= localVar.mapGlobal.fromLatLngToDivPixel(ne).x;
		var pixelMarker = localVar.mapGlobal.fromLatLngToDivPixel(point);
		var distanceTop 	= Math.abs(pixelTop - pixelMarker.y);
		var distanceRight = Math.abs(pixelRight - pixelMarker.x);
		var mapcenter_lat_lng = localVar.mapGlobal.getCenter();
		var mapcenter_point   = localVar.mapGlobal.fromLatLngToDivPixel(mapcenter_lat_lng);
		var posY 	= mapcenter_point.y;
		var posX 	= mapcenter_point.x;
		var boolMove = false; // must i move the map to see the info
		if ( distanceTop < (document.getElementById('infoWindowContainer').clientHeight + this.estyle.stemSize.height + this.estyle.borderOffset)) {
			posY = mapcenter_point.y - ((document.getElementById('infoWindowContainer').clientHeight + this.estyle.stemSize.height + this.estyle.borderOffset)-distanceTop);
			boolMove = true;
		}
		if ( distanceRight < (document.getElementById('infoWindowContainer').clientWidth + this.estyle.borderOffset)) {
			var mapcenter_lat_lng = localVar.mapGlobal.getCenter();
			var mapcenter_point   = localVar.mapGlobal.fromLatLngToDivPixel(mapcenter_lat_lng);
			posX = mapcenter_point.x + ((document.getElementById('infoWindowContainer').clientWidth + this.estyle.borderOffset)-distanceRight)
			boolMove = true;
		}
		if (boolMove) {
			var new_point  = new GPoint(posX, posY);
			var gp_center  = localVar.mapGlobal.fromDivPixelToLatLng(new_point);
			localVar.mapGlobal.panTo(gp_center);
		}
      }
      
      EWindow.prototype.openOnMarker = function(marker,html) {
        var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
        var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.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";
      }
      EWindow.prototype.remove = function() {
        this.div1.parentNode.removeChild(this.div1);
        this.div2.parentNode.removeChild(this.div2);
        this.visible = false;
      }
      EWindow.prototype.copy = function() {
        return new EWindow(this.map, this.estyle);
      }
      EWindow.prototype.show = function() {
        if(localVar.fade){
        	opacity("EWindowMain","EWindowSub",0,99,600);
        }else{		
        	this.div1.style.display="";
        	this.div2.style.display="";
        }
        this.visible = true;
      }
      
      EWindow.prototype.hide = function() {
        if(localVar.fade){
	        opacity("EWindowMain","EWindowSub",99,0,300);
        }else{		        
	        hideFlyout("EWindowMain","EWindowSub");
        }
      }
      
	 function opacity(id1, id2, opacStart, opacEnd, millisec) {
	    //speed for each frame
	    var speed = Math.round(millisec / 100);
	    var timer = 0;
	
	    //determine the direction for the blending, if start and end are the same nothing happens
	    if(opacStart > opacEnd) {
	    	//timeouts are generated, but it isnt waited until one timer ends, ther will be created
	    	//more ones, each with a higher waiting time
	        for(i = opacStart; i >= opacEnd; i--) {
	            setTimeout("changeOpac(" + i + ",'" + id1 + "','" + id2 + "')",(timer * speed));
	            timer++;
	        }
	        //hide them also in DOM
			setTimeout("hideFlyout('" + id1 + "','" + id2 + "')",(timer * speed));
	    } else if(opacStart < opacEnd) {
	        for(i = opacStart; i <= opacEnd; i++)
	            {
	            setTimeout("changeOpac(" + i + ",'" + id1 + "','" + id2 + "')",(timer * speed));
	            timer++;
	        }
	        document.getElementById(id1).style.display="";
	    	document.getElementById(id2).style.display="";
	    }
	  } 
		
	  //change the opacity for different browsers
	  function changeOpac(opacity, id1,id2) {
	    var object1 = document.getElementById(id1).style;
	    var object2 = document.getElementById(id2).style;
	    
	    object1.opacity = (opacity / 100);
   	    object2.opacity = (opacity / 100);
   	    
	    object1.MozOpacity = (opacity / 100);
   	    object2.MozOpacity = (opacity / 100);
   	    
	    object1.KhtmlOpacity = (opacity / 100);
   	    object2.KhtmlOpacity = (opacity / 100);
   	    
	    object1.filter = "alpha(opacity=" + opacity + ")";
   	    object2.filter = "alpha(opacity=" + opacity + ")";
	  } 
	  function hideFlyout(id1,id2){
	  	document.getElementById(id1).style.display="none";
	    document.getElementById(id2).style.display="none";
        ew.visible = false;
        markerObj = null;
	  }
        

