/**
 * @class
 * 
 * @requires OpenLayers/Map.js
 * @requires he.js
 */
 
 
 //==========================================================
 
 /**
	 OpenLayers.Control.FMButton, a button to be diplayed on the map.
	 To set the on click functionality override the onClick function in the options.
	
	 additional options to a standard Control options:
	 onClick - override to implement on click behaviour
	 label - the label appearing on the button
	
 */
 OpenLayers.Control.FMButton = OpenLayers.Class(OpenLayers.Control,
	{
		
		initialize: function(options){
			OpenLayers.Control.Button.prototype.initialize.call(this,options);
		},
		label:"",
		onClick:null,
		
		draw: function (px) {
		
			var btnDiv = OpenLayers.Control.Button.prototype.draw.call(this,px);
			
			//overide parent Events CTOR to enable us to pass the button div to the CTOR
			//to make it respond to the events
			this.events = new OpenLayers.Events(this, btnDiv, this.EVENT_TYPES);
			
			//now register events ... Moo ha ha - it's alive
			if(this.onClick!=null)
				this.events.register("click", this,this.onClick);
			
			btnDiv.innerHTML=this.label;
			return btnDiv;
		},
		
		 CLASS_NAME: "OpenLayers.Control.FMButton"
	});
 //==========================================================
OpenLayers.Map.FreeMapIL = 
  OpenLayers.Class(OpenLayers.Map, 
  {
	
	initialize: function (div, options){
	
		OpenLayers.Lang.setCode("he");
		OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
		//call OpenLayers.Map super ...
		OpenLayers.Map.prototype.initialize.apply(this, arguments);
		
		//for some odd reason I can't seem to be able to override mapExtent when my value appears in the options (Map initialize
		//ignores my value) thus I'll override it here!
		this.maxExtent =  new OpenLayers.Bounds(33.75,28.125,36.5625,33.75);
		
		//add base layer
		var layer = new OpenLayers.Layer.WMS(OpenLayers.Lang.translate("israel-base"), 
			[ "http://t5.maps.freemap.co.il/wms-c/", 
			  "http://t6.maps.freemap.co.il/wms-c/", 
			  "http://t7.maps.freemap.co.il/wms-c/", 
			  "http://t8.maps.freemap.co.il/wms-c/"
			], 
			{layers: 'base', format: 'image/png' },
			{'attribution':'<a href="http://www.freemap.co.il">FreeMap Israel&copy;</a>'});

		this.addLayer(layer);
		
		this.addControl(new OpenLayers.Control.Navigation());
		this.addControl(new OpenLayers.Control.Scale());
		this.addControl(new OpenLayers.Control.MousePosition());
		this.addControl(new OpenLayers.Control.Permalink());
	//	this.addControl(new OpenLayers.Control.LayerSwitcher());
		
		//add overview layer
		var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
		"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
		var options = {
			layers: [wms],
			minRatio: 8,
			maxRatio: 256
			};

		var overview = new OpenLayers.Control.OverviewMap(options);
		this.addControl(overview);
		
		//add error report button
		var reportErrorBtn = new OpenLayers.Control.FMButton(
			{
				displayClass:"mapButton",
				title:OpenLayers.Lang.translate("reportErrorBtnTooltip"),
				label:OpenLayers.Lang.translate("reportErrorBtnLabel"),
				onClick: function(evt) {
					res = confirm("? "+"כדי לדווח על הטעות"+" Freemap "+"האם ברצונך לגלוש לאתר");
					if(res==true){
					
						//get the permalink href from the map
						var href = (this.map.getControlsByClass("OpenLayers.Control.Permalink")[0]).element.href;
						
						//get the parameters from the href
						params = href.split("?")[1];
						
						//navigate to the map page with the appropriate params
						window.open("/map.html?mistake=true&"+params);
					}
				}
			});
		this.addControl(reportErrorBtn);
		
		if (!this.getCenter()) 
			this.zoomToMaxExtent();
                    
	},
	
	//add the attribution control before init or the display class will not affect the attrib
	//OpenLayers only so-so ...
	//init other controls in init or IE6 will cry
	controls: [new OpenLayers.Control.Attribution({displayClass:"attrib"})],
	maxResolution: .010986328125,
       
	numZoomLevels: 11,
       
	/** @final @type String */
	CLASS_NAME: "OpenLayers.Map.FreeMapIL"
 
  
});

