/* Copyright (c) 2008 Hochsauerlandkreis
 * FD 55/2 GeoService, published under the Clear BSD
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 * full text of the license. */

/**
 * @requires OpenLayers/Control.js
 *
 * Class: OpenLayers.Control.phpNAV
 * In some applications, it makes sense to alert the user that something is 
 * happening while tiles are loading. This control displays a div across the 
 * map when this is going on.
 *
 * Inherits from:
 *  - <OpenLayers.Control>
 */
OpenLayers.Control.phpNAV = OpenLayers.Class(OpenLayers.Control, {

    /**
     * Property: phpNAVurl
     * {text} Die Adresse mit dem Frame für die Adressensuche
     */ 
    
    phpNAVurl: '<IFRAME SRC="http://www.geoserver.hochsauerlandkreis.de/php/phpNAV/navPOI.php" name="HNR1" width="100%" height="460" frameborder="yes" border-width="10" BORDERCOLOR="#00844A" MARGINWIDTH="10" MARGINHEIGHT="10" SCROLLING="no"></iframe>' ,
    
        
    /**
     * Property: maximized
     * {Boolean} A boolean indicating whether or not the control is maximized
    */
    maximized: false,

    /**
     * Constructor: OpenLayers.Control.phpNAV
     * Display a panel across the map that says 'loading'. 
     *
     * Parameters:
     * options - {Object} additional options.
     */
    initialize: function(options) {
         OpenLayers.Control.prototype.initialize.apply(this, [options]);
    },


    /**
     * Method: draw
     * Create and return the element to be splashed over the map.
     */
    draw: function () {	
        OpenLayers.Control.prototype.draw.apply(this, arguments);
        this.loadContents();
	return this.div;
    },

    /**
     *   Method: loadContents
     *   Aufbau des Menüs
     */
    loadContents: function() {
    	
    	//  Haupt Div
    	this.div.id = "hskphpNAV_BAR";        
        this.div.style.width = "125px";
        this.div.style.height = "20px";
      
        
        var img = "/php/phpNAV/images/strasse_1.gif";
        
        this.divmin = document.createElement("div");
        this.divmin.id = this.id + "_min";
        this.divmin = OpenLayers.Util.createAlphaImageDiv(
        			       'hskphpNAV_min', 
                                       new OpenLayers.Pixel(15,0), 
                                       new OpenLayers.Size(96,18), 
                                       img, 
                                       'absolute');
        this.divmin.style.display = '';
        //this.minimizeDiv.className = this.displayClass + 'MinimizeButton';
        OpenLayers.Event.observe(this.divmin, 'click', OpenLayers.Function.bindAsEventListener(this.maximizeControl,this));
        


        this.divmax = document.createElement("div");
        this.divmax.id = this.id + "_max";
        this.divmax = OpenLayers.Util.createDiv(
        'hskphpNAV_max',
        new OpenLayers.Pixel(0,0), 
        new OpenLayers.Size(425,460),
        '',
        'absolute', 
        '','','');
        this.divmax.style.display = 'none';
        this.divmax.innerHTML = this.phpNAVurl;
        
        this.div.appendChild(this.divmin);
        this.div.appendChild(this.divmax);
        
        
    },
     
    /**
     * Method: minimizeControl
     * Set the display properties of the control to make it disappear.
     *
     * Parameters:
     * evt - {Event}
     */
    minimizeControl: function(evt) {

        
        this.divmax.style.display= 'none';
        this.divmin.style.display= '';
        
        this.maximized = false;
    
        if (evt != null) {
            OpenLayers.Event.stop(evt);
        }
    },
    
    /**
     * Method: maximizeControl
     * Make the control visible.
     *
     * Parameters:
     * evt - {Event}
     */
    maximizeControl: function(evt) {
    	
    	this.divmax.innerHTML = this.phpNAVurl;
        this.divmax.style.display= '';
        this.divmin.style.display= 'none';
        
        
        if (evt != null) {
            OpenLayers.Event.stop(evt);
        }
    },
    
    
    zoomToExtent: function(a,b,c,d) {
    	//  Koordinaten im maxExtent?
    	var nav1=true;
    	var nav2=true;

	nav1 = this.map.maxExtent.contains(a,b,true);
    	nav2 = this.map.maxExtent.contains(c,d,true);

    
        if ((nav1) && (nav2)) {
        	this.map.zoomToExtent(new OpenLayers.Bounds(a,b,c,d), true);
	} else {
		alert ("Die Koordinate liegt ausserhalb des maximalen Darstellungsbereiches. Der Bereich kann nicht dargestellt werden!");
        }
    },

    /** 
     * Method: destroy
     * Destroy control.
     */
    destroy: function() {
        OpenLayers.Control.prototype.destroy.apply(this, arguments);
    },     

    CLASS_NAME: "OpenLayers.Control.phpNAV"

});
