/**
 * Copyright (c) 2000 Nimbus Partners Ltd.
 * http://www.nimbuspartners.com
 */

function Bubble(id, image, title, left, top, width, height, ofs, visibility) {
    this.id = id;
    this.image = image;
    this.title = title;
    this.left = left;
    this.top = top;
    this.width = width;
    this.height = height;
    this.ofs = ofs;
    if (visibility) {
        this.visibility = "visible";
    } else {
        this.visibility = "hidden";
    }

    this.writeBubbles = writeBubbles;

    if (!window.bubbles) window.bubbles = new Array();
    window.bubbles[window.bubbles.length] = this;
}

function bubbleOriginOpen() {
    if (is.ie4up || is.nav5up) {
        document.write('<div id="bubbleOrigin">');
    } else if (is.nav4up) {
        document.write('<layer id="bubbleOrigin">');
    }
}

function bubbleOriginClose() {
    if (is.ie4up || is.nav5up) {
        document.write('</div>');
    } else if (is.nav4up) {
        document.write('</layer>');
    }
}

function writeBubbles() {
    if (is.nav5up) {
        var container = document.createElement('SPAN');
        container.setAttribute('ID', 'bubbleContainer');
        
        container.bubbles = new Array();
        for (var i = 0; i < window.bubbles.length; i++)
            container.bubbles[i] = window.bubbles[i];
        window.bubbles.length = 0;

        var countBubbles = 0;
        var content = '';
        var bubbleOrigin = document.getElementById('bubbleOrigin');
        var body = document.getElementsByTagName('BODY').item(0);

        for (var i = 0; i < container.bubbles.length; i++, countBubbles++) {
            var bubble = container.bubbles[i];

            bubble.left += bubbleOrigin.offsetLeft + body.offsetLeft;
            bubble.top += bubbleOrigin.offsetTop + body.offsetTop;
            var bubbleLayer = document.createElement('DIV');
            container.bubbles[i].bubbleLayer = bubbleLayer;
            bubbleLayer.setAttribute('ID', 'bubbleLayer' + countBubbles);
            bubbleLayer.setAttribute('STYLE', 'position: absolute; left: ' + bubble.left + '; top: ' + bubble.top + '; width: ' + bubble.width + '; height: ' + bubble.height + '; visibility: ' + bubble.visibility);

            var image = document.createElement('IMG');
            image.setAttribute('SRC', bubble.image);
            image.setAttribute('BORDER', '0');
            image.setAttribute('USEMAP', '#bubbleMap' + countBubbles);
            var map = document.createElement('MAP');
            map.setAttribute('NAME', 'bubbleMap' + countBubbles);
            var area = document.createElement('AREA');
            area.setAttribute('SHAPE', 'RECT');
            area.setAttribute('COORDS', '0, 0, ' + bubble.width + ', ' + (bubble.height - bubble.ofs));
            area.setAttribute('HREF', 'javascript:hideBubble(' + bubble.id + ')');
            area.setAttribute('ALT', bubble.title);

            map.appendChild(area);
            bubbleLayer.appendChild(image);
            bubbleLayer.appendChild(map);
            container.appendChild(bubbleLayer);
        }
        document.documentElement.appendChild(container);
    } else if (is.ie4up) {
        if (!window.bubbleContainerCreated) {
            document.writeln('<SPAN ID="bubbleContainer"></SPAN>');
            window.bubbleContainerCreated = true;
        }
        var container = document.all["bubbleContainer"];
        if (!container) {
            if (!window.delayWriteBubbles) {
                window.delayWriteBubbles = this.writeBubbles;
            }
            setTimeout('delayWriteBubbles()', 500);
            return;
        }
        container.bubbles = new Array();
        for (var i = 0; i < window.bubbles.length; i++)
            container.bubbles[i] = window.bubbles[i];
        window.bubbles.length = 0;

        var countBubbles = 0;
        var content = '';
        var bubbleOrigin = document.all.bubbleOrigin;
        for (var i = 0; i < container.bubbles.length; i++, countBubbles++) {
            var bubble = container.bubbles[i];
            bubble.left += bubbleOrigin.offsetLeft;
            bubble.top += bubbleOrigin.offsetTop;
            var href = ' HREF="javascript:hideBubble(' + bubble.id + ')"';
            var coords = ' COORDS="0, 0, ' + bubble.width + ', ' + (bubble.height - bubble.ofs) + '"';
            var title = ' ALT="' + bubble.title + '"';
            content += '<DIV ID="bubbleLayer' + countBubbles + '" STYLE="position: absolute; left: ' + bubble.left + '; top: ' + bubble.top + '; width: ' + bubble.width + '; height: ' + bubble.height + '; visibility: ' + bubble.visibility + '">\n';
            content += '  <IMG SRC="' + bubble.image + '" BORDER=0 USEMAP="#bubbleMap' + countBubbles + '">\n';
            content += '  <MAP NAME="bubbleMap' + countBubbles + '">\n';
            content += '    <AREA SHAPE=RECT' + coords + href + title + '>\n';
            content += '  </MAP>\n';
            content += '</DIV>\n';
        }

        container.document.open("text/html");
        container.document.writeln(content);
        container.document.close();

        for (var i = 0; i < container.bubbles.length; i++) {
            var bubbleLayer = container.document.all["bubbleLayer" + i];
            container.bubbles[i].bubbleLayer = bubbleLayer;
        }
    } else if (is.nav4up) {
        var countBubbles = 0;
        var bubbleOrigin = document.layers.bubbleOrigin;
        for (var i = 0; i < window.bubbles.length; i++, countBubbles++) {
            var bubble = window.bubbles[i];
            bubble.left += bubbleOrigin.pageX;
            bubble.top += bubbleOrigin.pageY;
            var container = new Layer(1000);
            bubble.bubbleLayer = container;
            container.position = "absolute";
            container.left = bubble.left;
            container.top = bubble.top;
            container.visibility = bubble.visibility;

            var href = ' HREF="javascript:hideBubble(' + bubble.id + ')"';
            var coords = ' COORDS="0, 0, ' + bubble.width + ', ' + (bubble.height - bubble.ofs) + '"';
            var title = ' ALT="' + bubble.title + '"';
            var content = '';
            content += '<IMG SRC="' + bubble.image + '" BORDER=0 USEMAP="#bubbleMap' + countBubbles + '">\n';
            content += '<MAP NAME="bubbleMap' + countBubbles + '">\n';
            content += '  <AREA SHAPE=RECT' + coords + href + title + '>\n';
            content += '</MAP>\n';

            container.document.open("text/html");
            container.document.writeln(content);
            container.document.close();
        }
        window.bubbles.length = 0;
    }
}

function hideBubble(bubble) {
    if (bubble.bubbleLayer) {
        bubble = bubble.bubbleLayer;
    }
    if (is.ie4up || is.nav5up) {
        bubble.style.visibility = "hidden";
    } else if (is.nav4up) {
        bubble.visibility = "hidden";
    }
}

function showBubble(bubble) {
    if (bubble.bubbleLayer) {
        bubble = bubble.bubbleLayer;
    }
    if (is.ie4up || is.nav5up) {
        bubble.style.visibility = "visible";
    } else if (is.nav4up) {
        bubble.visibility = "visible";
    }
}

function switchBubble(bubble) {
    if (bubble.bubbleLayer) {
        bubble = bubble.bubbleLayer;
    }
    if (is.ie4up || is.nav5up) {
        bubble = bubble.style;
    }
    if ((bubble.visibility == "hidden") || (bubble.visibility == "hide")) {
        bubble.visibility = "visible";
    } else {
        bubble.visibility = "hidden";
    }
}


