var ETabWindow = new Class({

initialize: function(options){
	options = $merge({
		'map':'map',
		'visible': false,
		'onDetail': Class.empty,
		'html':''
	}, options);
	
    this.map = options.map;
    this.visible = options.visible;        
    this.offset = 0;
    this.windowDiv = new Element('div', { 'styles':{'left':'0px', 'bottom':'0px'} });
    this.point = new GPoint(0,0);
    this.html = options.html;
    $(this.windowDiv).style.position = "absolute";    
    this.propertyMarker = Class.empty    
    this.initialize = this.mapinit;
    this.sizeDivHeight = 154;
    this.sizeDivWidth = 200;
    this.onDetail = options.onDetail;
	this.propertyMarker = new PropertyMarker( {tabDivName: 'tab1', idAddress:'div_panel_address', idNavigation:'navarrow', 'onDetail':this.onDetail, onClose:this.hide.bind(this)} );      
    GEvent.bind(this.map, 'zoomend', this, this.hide );
},

mapinit: function(){	
	$(this.windowDiv).innerHTML = this.html;	
	$(this.windowDiv).addEvent('dblclick',this.stopClick.bind(this));
	this.map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(this.windowDiv);	
	this.propertyMarker.init();	
},

stopClick: function(event){
  event = new Event(event);
  event.stopPropagation();

},

openOnMarker: function(marker, property){
  var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
  var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
  this.openOnMap(marker.getPoint(), new GPoint(vx,vy));
  this.propertyMarker.setPropertyList(property);
  this.map.panTo(this.point);
},

openOnMap: function(point, offset){
    this.offset = offset||new GPoint(0,0);
    this.point = point;
    var z = GOverlay.getZIndex(point.lat());
    $(this.windowDiv).style.zIndex = z;    
    this.visible = true;
    this.show();
    this.redraw(true);
},

show: function() {
    $(this.windowDiv).style.display="";
    this.visible = true;
},

hide: function() {
	$(this.windowDiv).style.display="none";
	this.visible = false;
},

redraw: function(force) {
    if (!this.visible) {return;}
    var p = this.map.fromLatLngToDivPixel(this.point);
    $(this.windowDiv).setStyle('left',(p.x + this.offset.x - this.sizeDivWidth/2) + "px");
    $(this.windowDiv).setStyle('bottom',(-p.y + this.offset.y + this.sizeDivHeight) + "px");
},

copy: function(){
	return new ETabWindow(this.map);
},

remove: function(){
	$(this.windowDiv).parentNode.removeChild(this.windowDiv);
    this.visible = false;
},

moveRight:function(){
	this.propertyMarker.moveTabRight();
},

moveLeft:function(){
	this.propertyMarker.moveTabLeft();
}

});

$native(ETabWindow,GOverlay);

