   // Function to convert normal latitude/longitude to mercator easting/northings
      function lonLatToMercator(ll) {
        var lon = ll.lon * 20037508.34 / 180;
        var lat = Math.log (Math.tan ((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180);
        lat = lat * 20037508.34 / 180;
        return new OpenLayers.LonLat(lon, lat);
      }

      // make map available for easy debugging
      var map;

      // avoid pink tiles
      OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
      OpenLayers.Util.onImageLoadErrorColor = "transparent";

function init(){
	var options = {
    	projection: new OpenLayers.Projection("EPSG:900913"),
    	displayProjection: new OpenLayers.Projection("EPSG:4326"),
    	units: "m",
    	maxResolution: 156543.0339,
    	maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34),
          controls:[], numZoomLevels:19
    };
    init_slider(); 
    map = new OpenLayers.Map('map', options);
    var gmap = new OpenLayers.Layer.Google( "Google Streets", { 'sphericalMercator': true, attribution: '<a href="http://www.google.com/intl/en_ALL/help/terms_maps.html">Terms of Use</a> for <a href="http://maps.google.com/">Google Maps</a>.',numZoomLevels:18,  } );
    var gsat = new OpenLayers.Layer.Google( "Google Satellite", { type: G_SATELLITE_MAP, 'sphericalMercator': true,attribution: '<a href="http://www.google.com/intl/en_ALL/help/terms_maps.html">Terms of Use</a> for <a href="http://maps.google.com/">Google Maps</a>.',numZoomLevels:19 } );
    var gphy = new OpenLayers.Layer.Google( "Google Physical", { type: G_PHYSICAL_MAP, 'sphericalMercator': true, attribution: '<a href="http://www.google.com/intl/en_ALL/help/terms_maps.html">Terms of Use</a> for <a href="http://maps.google.com/">Google Maps</a>.', numZoomLevels:16 } );
    var ymap = new OpenLayers.Layer.Yahoo( "Yahoo Street", { 'sphericalMercator': true, attribution: '<a href="http://info.yahoo.com/legal/us/yahoo/maps/mapstou/">Terms of Use</a> for <a href="http://maps.yahoo.com/">Yahoo Local Maps</a>.',  numZoomLevels:16 } );
//        var ysat = new OpenLayers.Layer.Yahoo( "Yahoo Satellite", { 'type': YAHOO_MAP_SAT, 'sphericalMercator': true, numZoomLevels:16 } );

    var mapnik = new OpenLayers.Layer.TMS( "OSM Mapnik (Standard)", "http://tile.openstreetmap.org/",
                         { type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true, attribution: ' - <a href="http://www.openstreetmap.org/">OpenStreetMap</a> maps are licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons CC-BY-SA license.</a>',
                           opacity: 0.5, isBaseLayer: false, visibility: true, numZoomLevels:19 } );
    var osmarender = new OpenLayers.Layer.TMS( "OpenStreetMap (Tiles@Home)", "http://tah.openstreetmap.org/Tiles/tile/",
                             { type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true, attribution: ' - <a href="http://www.openstreetmap.org/">OpenStreetMap</a> maps are licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons CC-BY-SA license.</a>',
                               opacity: 0.5, isBaseLayer: false, visibility: false, numZoomLevels:19 } );
    var cycle = new OpenLayers.Layer.TMS("Cycle Map", "http://b.andy.sandbox.cloudmade.com/tiles/cycle/",
                        { type: 'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true, attribution: ' - <a href="http://www.openstreetmap.org/">OpenStreetMap</a> maps are licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons CC-BY-SA license.</a>',
                          opacity: 0.5, isBaseLayer: false, visibility: false, numZoomLevels:18 } );
    var maplint = new OpenLayers.Layer.TMS( "Maplint", "http://tah.openstreetmap.org/Tiles/maplint.php/",
                          { type:'png', getURL: osm_getTileURL, displayOutsideMaxExtent: true, attribution: ' - <a href="http://www.openstreetmap.org/">OpenStreetMap</a> maps are licensed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons CC-BY-SA license.</a>',
                            opacity: 0.5, isBaseLayer: false, visibility: false, numZoomLevels:17 } );

    map.addLayers([gmap, gsat, gphy, ymap, mapnik, osmarender, cycle, maplint ]);

    map.addControl(new OpenLayers.Control.ArgParser());
    map.addControl(new OpenLayers.Control.Attribution());
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.addControl(new OpenLayers.Control.Navigation());
    map.addControl(new OpenLayers.Control.PanZoomBar() );
    map.addControl(new OpenLayers.Control.Permalink());
    //map.addControl(new OpenLayers.Control.ScaleLine());
    //map.addControl(new OpenLayers.Control.MousePosition());

    if (!map.getCenter()) {
          map.setCenter( lonLatToMercator(new OpenLayers.LonLat(10,51)),6);
        }
      }

    function osm_getTileURL(bounds) {
        var res = this.map.getResolution();
        var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
        var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
        var z = this.map.getZoom();
        var limit = Math.pow(2, z);

        if (y < 0 || y >= limit) {
          return OpenLayers.Util.getImagesLocation() + "404.png";
        } else {
          x = ((x % limit) + limit) % limit;
          return this.url + z + "/" + x + "/" + y + "." + this.type;
        }
      }

    function init_slider() {
        var Event = YAHOO.util.Event,
            Dom   = YAHOO.util.Dom,
            lang  = YAHOO.lang,
            slider,
            bg="slider-bg", thumb="slider-thumb",
            textfield="slider-converted-value"
        var topConstraint = 0;
        var bottomConstraint = 200;
        var scaleFactor = .005;
        var keyIncrement = 20;
        var tickSize = 1;

        slider = YAHOO.widget.Slider.getHorizSlider(bg, thumb, topConstraint, bottomConstraint, 10);
        slider.getRealValue = function() {
          return Math.round(this.getValue() * scaleFactor * 100) / 100;
        }
        slider.setValue(100);
        slider.subscribe("change", function(offsetFromStart) {
          map.layers[4].setOpacity(slider.getRealValue());
          map.layers[5].setOpacity(slider.getRealValue());
          map.layers[6].setOpacity(slider.getRealValue());
          map.layers[7].setOpacity(slider.getRealValue());
        });
      }
 
