function OlMap(mapSettings)
{
  
  var satlayer              = null;
  var monolitlayer          = null;
  var monolitlayerhybrid    = null;
  var topolayer1            = null;
  var topolayer2            = null;
  
  var serverWmsUrl          = mapSettings['serverWmsUrl'];
  var serverImageUrl        = mapSettings['serverImageUrl'];
  var mapPrj                = mapSettings['mapPrj'];
  var dispPrj               = mapSettings['dispPrj'];
  var mapUnit               = mapSettings['mapUnits'];
  var maxExtent             = mapSettings['maxExtent'];
  var maxExtentSlovenia     = mapSettings['maxExtentSlovenia'];
  var minExtent             = mapSettings['minExtent'];
  var layersList            = mapSettings['layersList'];
  var zoomResolutions       = mapSettings['zoomResolutions'];
  var zoomResolutionsSlovenia = mapSettings['zoomResolutionsSlovenia'];
  var mapDiv                = mapSettings['div'];
  var imageFormat           = mapSettings['imageFormat'];
  var tileSize              = mapSettings['tileSize'];
  var tileBuffer            = mapSettings['tileBuffer'];
  var mapOptions            = {maxExtent:maxExtent,minExtent:minExtent,units:mapUnit,projection:mapPrj,displayProjection:dispPrj,resolutions:zoomResolutions}
  var map                   = new OpenLayers.Map (mapDiv,{controls:[]});
  
  this.showTopo1            = showTopo1;
  this.showTopo2            = showTopo2;
  this.showHybrid           = showHybrid;
  this.showMap              = showMap;
  this.getMapInstance       = getMapInstance;
  this.getNextView          = getNextView;
  this.getPrevView          = getPrevView;
  

  map.setOptions(mapOptions);
  //showMap();
 
  
   
  //custom buttons
  var toolListeners = {
	                    "activate": toolActivate,
 	                    "deactivate": toolDeactivate
	                };

 ctlTopo1 = new OpenLayers.Control({
 	                    type: OpenLayers.Control.TYPE_TOGGLE,
	                    eventListeners: toolListeners,
 	                    displayClass: "mapCtlButtonTopo1",
                        title:'topography1'

 	                });
  ctlTopo1.id="ctlTopo1";

  ctlTopo2 = new OpenLayers.Control({
 	                    type: OpenLayers.Control.TYPE_TOGGLE,
	                    eventListeners: toolListeners,
 	                    displayClass: "mapCtlButtonTopo2",
                        title:'topography2'

 	                });
  ctlTopo2.id="ctlTopo2";
  
  ctlHybrid = new OpenLayers.Control({
 	                    type: OpenLayers.Control.TYPE_TOGGLE,
	                    eventListeners: toolListeners,
 	                    displayClass: "mapCtlButtonHybrid",
                        title:'aero'
                            
 	                });
  ctlHybrid.id="ctlHybrid";

  ctlMap = new OpenLayers.Control({
 	                    type: OpenLayers.Control.TYPE_TOGGLE,
	                    eventListeners: toolListeners,
 	                    displayClass: "mapCtlButtonMap",
                        title:'map'
                            
 	                });                        
  ctlMap.id="ctlMap";

  ctlToggle = new OpenLayers.Control({
                            type: OpenLayers.Control.TYPE_TOGGLE,
                            eventListeners: toolListeners,
                            displayClass: "mapCtlToggle",
                            title:'show/hide'
                        });
  ctlToggle.id="ctlToggle";

  ctlPan  = new OpenLayers.Control.Navigation({displayClass: "mapCtlButtonPan", title:'pan'}),
  ctlZoom = new OpenLayers.Control.ZoomBox({displayClass: "mapCtlButtonZoom", title:'zoom'})

  navipanel = new OpenLayers.Control.Panel({defaultControl:ctlMap,'div':OpenLayers.Util.getElement('map_menu')});
  tooglepanel = new OpenLayers.Control.Panel({'div':OpenLayers.Util.getElement('map_menu_container_toggle')});

  navipanel.addControls([ctlTopo1,ctlTopo2,ctlMap,ctlPan,ctlZoom]);
  tooglepanel.addControls([ctlToggle]);
  
  nav = new OpenLayers.Control.NavigationHistory();
                
  map.addControl(navipanel);
  map.addControl(tooglepanel);
  map.addControl(nav);
 

  pzbctl = new OpenLayers.Control.PanZoomBar();
  pzbctl.position = new OpenLayers.Pixel(3,3);
  map.addControl(pzbctl);
  
  map.addControl(new OpenLayers.Control.Scale('olMapFooterScale'));
  map.addControl(new OpenLayers.Control.Navigation());
  map.addControl(new OpenLayers.Control.ScaleLine({'div':OpenLayers.Util.getElement('olMapFooterScaleLine')}));
  map.addControl(new OpenLayers.Control.MousePosition({'div':OpenLayers.Util.getElement('olMapFooterMousePos')}));
  map.addControl(new OpenLayers.Control.OverviewMap({mapOptions:mapOptions}));
  map.addControl(new OpenLayers.Control.KeyboardDefaults());
  //map.addControl(new OpenLayers.Control.LayerSwitcher());
  map.zoomToMaxExtent();
  
  function getNextView()
  {
       nav.nextTrigger();
  }
  
  function getPrevView()
  {
       nav.previousTrigger();
  }



  // define custom event listeners
  function toolActivate(event) {
      if (event.object.id == 'ctlMap'){ctlHybrid.deactivate();ctlTopo1.deactivate();ctlTopo2.deactivate(); showMap();}
      
      if (event.object.id == 'ctlHybrid'){ctlMap.deactivate();ctlTopo1.deactivate(); ctlTopo2.deactivate(); showHybrid();}
      
      if (event.object.id == 'ctlTopo1'){ctlMap.deactivate();ctlHybrid.deactivate(); ctlTopo2.deactivate(); showTopo1();}

      if (event.object.id == 'ctlTopo2'){ctlMap.deactivate();ctlHybrid.deactivate();ctlTopo1.deactivate();showTopo2();}

      if (event.object.id == 'ctlToggle'){jQuery('#map_menu_container').toggle(200);}
  }
  
  function toolDeactivate(event) {
      
      if (event.object.id == 'ctlMap'){ if (! ctlHybrid.active && ! ctlTopo1.active &&  ! ctlTopo2.active ) ctlMap.activate(); }

      if (event.object.id == 'ctlHybrid'){if (! ctlMap.active && ! ctlTopo1.active &&  ! ctlTopo2.active ) ctlHybrid.activate(); }

      if (event.object.id == 'ctlTopo1'){if (! ctlHybrid.active && ! ctlMap.active &&  ! ctlTopo2.active ) ctlTopo1.activate(); }

      if (event.object.id == 'ctlTopo2'){if (! ctlHybrid.active && ! ctlMap.active &&  ! ctlTopo1.active ) ctlTopo2.activate(); }

      if (event.object.id == 'ctlToggle'){jQuery('#map_menu_container').toggle(200);}
  }

  function showTopo1()
  {
   
      hideHybrid();   
      hideMap();
      hideTopo2();
      
      mapOptionsSlo = {maxExtent:maxExtentSlovenia,minExtent:minExtent,units:mapUnit,projection:mapPrj,displayProjection:dispPrj,resolutions:zoomResolutionsSlovenia};
      map.setOptions(mapOptionsSlo);

      if (map.getLayer('Topo1') == null )
      {
          topolayer1 = new OpenLayers.Layer.WMS
          (
                "Topo1",
                serverImageUrl,
                {layers: 'cache_monolit_maps_topo1_2009_04' ,format: imageFormat,transparent: "false"},
                {tileSize: tileSize,'isBaseLayer': true}
          );

          topolayer1.id="Topo1";
          topolayer1.buffer = tileBuffer;
          map.addLayers([topolayer1]);
      }
      //map.zoomToMaxExtent();
   
  }

  function hideTopo1()
  {
     
     if(map.getLayer('Topo1') != null)
     {
        topolayer1.destroy();
     }
  }


  function showTopo2()
  {
      hideHybrid();
      hideMap();
      hideTopo1();

      mapOptionsSlo = {maxExtent:maxExtentSlovenia,minExtent:minExtent,units:mapUnit,projection:mapPrj,displayProjection:dispPrj,resolutions:zoomResolutionsSlovenia};
      map.setOptions(mapOptionsSlo);

      if (map.getLayer('Topo2') == null )
      {
          topolayer2 = new OpenLayers.Layer.WMS
          (
                "Topo2",
                serverImageUrl,
                {layers: 'cache_monolit_maps_topo2_2009_04' ,format: imageFormat,transparent: "false"},
                {tileSize: tileSize,'isBaseLayer': true}
          );

          topolayer2.id="Topo2";
          topolayer2.buffer = tileBuffer;
          map.addLayers([topolayer2]);
      }

  }

  function hideTopo2()
  {
     if(map.getLayer('Topo2') != null)
     {
        topolayer2.destroy();
     }
  }

  function showHybrid()
  {
        
      hideTopo1();
      hideMap();
      hideTopo2()
      jQuery.setAddsZoom(16);//ni tega zooma se ne prikazuje , ker rendra prepočasi
      map.setOptions(mapOptions);

      if(map.getLayer('Satellite') == null && map.getLayer('MonolitHybrid') == null)
      {

          
          monolitlayerhybrid = new OpenLayers.Layer.WMS
          (
                "MonolitHybrid",
                serverWmsUrl,
                {layers: 'eu_svn:streets' ,format: imageFormat,transparent: "true"},
                {tileSize: tileSize,'isBaseLayer': false,opacity: 0.7}
          );
          
         
          monolitlayerhybrid.id="MonolitHybrid";
          
         
         
          satlayer = new OpenLayers.Layer.Yahoo(
 	                "Satellite",
	                {'type': YAHOO_MAP_SAT, 'sphericalMercator': true }
	      );
          
         
         
          satlayer.id="Satellite";
          
          satlayer.buffer = tileBuffer;
         
          map.addLayers([satlayer,monolitlayerhybrid]);
         // map.addLayers([satlayer]);
           la = new OpenLayers.LonLat(14.61195, 45.97347).transform
            (
                   new OpenLayers.Projection("EPSG:4326"),
                   new OpenLayers.Projection("EPSG:900913")
            );
                //map.panTo(la);
          
      }

      //map.zoomToMaxExtent();

  }
  
  function hideHybrid()
  {
       
       if(map.getLayer('Satellite') != null && map.getLayer('MonolitHybrid') != null)
       {
                jQuery.setAddsZoom(10);
                monolitlayerhybrid.destroy();
                satlayer.destroy();
       }
  }


  function showMap()
  {
      
      hideTopo1();
      hideHybrid();
      hideTopo2();

      map.setOptions(mapOptions);
       
      if (map.getLayer('Monolit') == null )
      {
          monolitlayer = new OpenLayers.Layer.WMS
          (
            "Monolit",
            serverImageUrl,
            {layers: layersList ,format: imageFormat},
            {tileSize: tileSize,transitionEffect: 'null'}
          );
          monolitlayer.id = "Monolit";
          monolitlayer.buffer = tileBuffer;
          map.addLayers([monolitlayer]);
      }
  }

  function hideMap()
  {
       if (map.getLayer('Monolit') != null)
       {
             monolitlayer.destroy();
       }  
  }

  function getMapInstance(){return map;}
 
  
}
