﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("dk.advokatnoglen");

dk.advokatnoglen.MapHover = function(sourceArea, subMapElement) {
    this._sourceArea = sourceArea;
    this._subMapElement = subMapElement;
    this._hideTimer = null;
    this._DEBUG = true;
}

dk.advokatnoglen.MapHover.prototype = {
    initialize: function() {
        $addHandler(window, "unload", Function.createDelegate(this, this.dispose));
        $addHandlers(this._sourceArea, { "mouseover": this._areaMouseOver, "mouseout": this._areaMouseOut }, this);
        $addHandlers(this._subMapElement, {
            "mouseover": this._areaMouseOver,
            "mousemove": this._areaMouseOver,
            "mouseout": this._areaMouseOut
        }, this);

        var map = this._subMapElement.getAttribute("usemap").substring(1);
        $addHandlers($get(map), {
            "mouseover": this._areaMouseOver,
            "mousemove": this._areaMouseOver,
            "mouseout": this._areaMouseOut
        }, this);
    },

    _resetTimer: function() {
        if (this._hideTimer)
            clearTimeout(this._hideTimer);
    },

    _areaMouseOver: function(e) {
        var evt = new Sys.UI.DomEvent(e);
        this._resetTimer();
        this._subMapElement.style.display = "block";
        if (this._DEBUG)
            Sys.Debug.trace("mouse over: " + evt.target.tagName);
    },

    _areaMouseOut: function(e) {
        var evt = new Sys.UI.DomEvent(e);
        if (this._DEBUG)
            Sys.Debug.trace("mouse out: " + evt.target.tagName);
        this._resetTimer();
        this._hideTimer = setTimeout(Function.createDelegate(this, this._hideArea), 200);
    },

    _hideArea: function() {
        if (this._DEBUG)
            Sys.Debug.trace("hiding");
        this._subMapElement.style.display = "none";
    },

    dispose: function() {
    }
}


if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
