/*
///////////////////////////////////////////////////////// (c) Cornua Multimedia /////
@Geschreven door: Joep Roebroek;
@Bedrijf: Cornua Multimedia;
@Bestandsnaam: DivMap.js;
@Beschrijving:
Omdat een <map> alleen op een <img> kan, hebben we een Dynamische 
Layer Mapper geschreven.

Met area's die naar eigen wens zijn te plaatsen en waarvan
de acties dynamisch te bepalen zijn;
///////////////////////////////////////////////////////// (c) Cornua Multimedia /////
*/

function DivMap(oParent, iWidth, iHeight)
{
    this.SetConfig();
    this.oMap = document.createElement('div');
    oParent.appendChild(this.oMap);
    this.oMap.style.height = iHeight + 'px';
    this.oMap.style.width  = iWidth + 'px';
    this.oMap.style.cursor = 'default';
}

DivMap.prototype.SetConfig = function()
{
    this.strDefaultTarget = 'ContentFrame';
    this.bPositioning     = false;
}

DivMap.prototype.AddArea = function(iCoX, iCoY, iCoXAndWidth, iCoYAndHeight)
{
    var oNewArea = document.createElement('div');
    this.oMap.appendChild(oNewArea);
    oNewArea.style.position = 'absolute';
    if (navigator.appName.indexOf('Microsoft') != -1) {
        oNewArea.style.background = '#000000';
        oNewArea.style.filter = 'alpha(opacity=0)';
    }
    oNewArea.style.height = (iCoYAndHeight - iCoY) + 'px';
    oNewArea.style.width  = (iCoXAndWidth - iCoX)  + 'px';
    oNewArea.style.marginTop  = iCoY + 'px';
    oNewArea.style.marginLeft = iCoX + 'px';
    oNewArea.style.cursor = 'pointer';
    oNewArea.Url = new Array;
    oNewArea.Target = new Array;
    if (this.bPositioning) {
        oNewArea.style.border = '1px solid #000000';
    }
    return oNewArea;
}

DivMap.prototype.CreateMap = function()
{
    var oCurrentArea;
    for(var iChildKey = 0; iChildKey < this.oMap.childNodes.length; iChildKey++) {
        oCurrentArea = this.oMap.childNodes[iChildKey];
        if (typeof oCurrentArea.OnClickHandler != 'undefined') {
            oCurrentArea.onclick = oCurrentArea.OnClickHandler;
            continue;
        }
        if (typeof oCurrentArea.Url == 'undefined') {
            continue;
        }
        oCurrentArea.strDefaultTarget = this.strDefaultTarget;
        oCurrentArea.onclick = function()
        {
            this.LoadNextPage = function()
            {
                if (typeof this.Target[iKey] == 'undefined') {
                    this.Target[iKey] = this.strDefaultTarget;
                }
                window.open(this.Url[iKey], this.Target[iKey]);
                iKey++;
                if (typeof this.Url[iKey] != 'undefined') {
                    this.LoadNextPage();
                }
            }
            if (typeof this.Url == 'object') {
                var iKey = 0;
                this.LoadNextPage();
            } else {
                if (typeof this.Target == 'object') {
                    this.Target = this.strDefaultTarget;
                }
                window.open(this.Url, this.Target);
            }
        }
    }
}
