/**
* Mobilitaetsportal Rheinland-Pfalz
* 
* @version $Id: openlayers_addon.js 403 2009-11-20 09:41:17Z wolt $
*/

//disable the autosize for the purpose of our matrix
/*
OpenLayers.Popup.FramedCloud.prototype.autoSize = false;

AutoSizeFramedCloud = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true
});

AutoSizeFramedCloudMinSize = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true, 
    'minSize': new OpenLayers.Size(400,400)
});

AutoSizeFramedCloudMaxSize = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true, 
    'maxSize': new OpenLayers.Size(100,100)
});
//OpenLayers.Feature.prototype.popupClass = OpenLayers.Popup.FramedCloud;

*/

/*  
OpenLayers.Popup.FramedCloud.prototype.autoSize = false;
OpenLayers.Feature.prototype.popupClass =  
OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true
});
*/

OpenLayers.Feature.prototype.popupClass =  
OpenLayers.Class(OpenLayers.Popup.Anchored, {
    //'autoSize': true
});

EnhancedTextLayer = OpenLayers.Class.create();
EnhancedTextLayer.postPopupHook = function(){
};
EnhancedTextLayer.prototype = OpenLayers.Class.inherit( OpenLayers.Layer.Text, {
 /**
   * @param {Event} evt
   */
   
  markerClick: function(evt) {
  
    var sameMarkerClicked = (this == this.layer.selectedFeature);

    
    this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
    for(var i=0, len=this.layer.map.popups.length; i<len; i++) {
        this.layer.map.removePopup(this.layer.map.popups[i]);
    }
    if (!sameMarkerClicked) {
        // no close box, exclusive
        //this.layer.map.addPopup(this.createPopup(), true); 
        // close box, but doesn't open again when clicked! reason: hide (toggle) not remove
        this.layer.map.addPopup(this.createPopup(false), true); 
        
        // add lightbox-init function for webcams
        if(typeof initLightbox == 'function'){
          initLightbox();
        }
        
    }
        

    /*
    if (this.popup) {
      this.popup.toggle(); 
    } else {
      this.layer.map.addPopup(this.createPopup(true), true);
    }
    this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;
    */
    
    OpenLayers.Event.stop(evt);
    }, 
  /*  
  markerClick: function(evt) {
      var sameMarkerClicked = (this == this.layer.selectedFeature);
      
      
      if (this.popup) {
        this.popup.toggle(); 
      } else {
        this.layer.map.addPopup(this.createPopup(true));
      }
      this.layer.selectedFeature = (!sameMarkerClicked) ? this : null;

      OpenLayers.Event.stop(evt);
  },
*/
  /** @final @type String */
  CLASS_NAME: "EnhancedTextLayer"
});

