function exO(a){return Math.round(a)+"px"}

GMap2.prototype.applyZoom = function(a)
{
        var b = this;
        var c = Math.floor(Math.log(b.viewSize.width) * Math.LOG2E - 2);
        var d = b.zoomLevel - a;
        if (d > c)
        {
                d = c;
        }
        else if (d < -c)
        {
                d = -c;
        }

        var e = Math.pow(2, d);
        b.div.style.zoom = e;
        var f = b.viewSize.width * b.centerScreen.x;
        var h = b.viewSize.height * b.centerScreen.y;
        b.div.style.left = exO((this._savedOffset.x - f) * e + f);
        b.div.style.top = exO((this._savedOffset.y - h) * e + h);

}

GMap2.prototype.smoothZoomTo = function(zoom_in)
{
        var a = this;

        if (!a._zoomInterval)
                a._targetZoom = a.getZoomLevel();

        a._targetZoom = clamp(a._targetZoom + (zoom_in ? 1 : -1), 0, 17);
        // it's not easy to do the nice zoom on browsers that don't support zoom
        if (a.div.style.zoom == undefined)
        {
                a.zoomTo(a._targetZoom);
                return;
        }

        if (a._zoomInterval)
                return;

        a._currentZoom = parseInt(a.getZoomLevel());
        a._savedOffset={"x" : a.div.offsetLeft, "y" : a.div.offsetTop};
        a.hideOverlays();

        this._zoomInterval = setInterval(function() {
                a._currentZoom += 0.3 * (a._targetZoom - a._currentZoom);

                if (Math.abs(a._targetZoom - a._currentZoom) < 0.05)
                {
                        if (a._savedOffset)
                        {
                                a.div.style.left=exO(a._savedOffset.x);
                                a.div.style.top=exO(a._savedOffset.y);
                        }
                        a.div.style.zoom = 1;
                        a.showOverlays();
                        a.zoomTo(a._targetZoom);
                        a._savedOffset = null;
                        window.clearInterval(a._zoomInterval);
                        a._zoomInterval = null;
                }
                else
                {
                        a.applyZoom(a._currentZoom);
                }
        }, 50);

} 

function clamp(i, min, max)
{
        if (i <= min)
                return min;
        else if (i >= max)
                return max;
        return i;

} 

function zoom(oEvent, scr)
{
        var zoom_in = true;

        if (scr >= 120)
                zoom_in = false;

        map.smoothZoomTo(zoom_in);
        if (oEvent.preventDefault)
                oEvent.preventDefault();

} 


function hookMouseWheelHandlers(id)
{
        var d = document.getElementById(id);
        if (d)
        {
                try
                {
                        if (document.body.addEventListener)
                                d.addEventListener('DOMMouseScroll', function(oEvent) {
zoom(oEvent, oEvent.detail * -40); }, false);
                        else
                                d.onmousewheel = function() { zoom(event, event.wheelDelta); return
false; }
                } catch (ex) {}
        }

}

