function Browser() {
        this.opera = 0;
        this.ie = 0;
        this.ns = 0;
        this.moz = 0;
    this.konq = 0;
    this.none;
    this.browser = navigator.userAgent;
    this.version = navigator.appVersion;

    if (this.version.toLowerCase().indexOf("98") != -1) {
        this.win = 1;
    }

    if (this.browser.toLowerCase().indexOf("opera") != -1 && this.version.toLowerCase().indexOf("7.0") != -1) {
        this.opera = 1;
        return;
    }
    if (this.browser.toLowerCase().indexOf("opera") != -1 && this.version.toLowerCase().indexOf("9.10") != -1) {
        this.opera = 1;
        return;
    }
    if (this.browser.toLowerCase().indexOf("msie") != -1) {
        this.ie = 1;
        return;
    }
    if (document.layers) {
        this.ns = 1;
        return;
    }
    if (this.browser.toLowerCase().indexOf("gecko") != -1){
        this.moz = 1;
        return;
    }
    if (this.browser.toLowerCase().indexOf("konq") != -1){
        this.konq = 1;
        return;
    }
    this.none = 1;
}

var is = new Browser();

function EventGetX(e) {
        if (is.ns || is.moz)
                return e.pageX;

        if (is.opera)
                return e.clientX+pageXOffset;

        if (is.ie)
                return event.clientX + document.body.scrollLeft;
}

function EventGetY(e) {
        if (is.ns || is.moz)
                return e.pageY;

        if (is.opera)
                return e.clientY+pageYOffset;

        if (is.ie)
                return event.clientY + document.body.scrollLeft;
}

var _x, _y, _dx, _dy, _selected = -1;

function MouseDown(ev) {
    _selected  = this.id;
    lay = document.getElementById(_selected);
    _x = EventGetX(ev);
    _y = EventGetY(ev);
    _dx = _x-parseInt(lay.style.left)
    _dy = _y-parseInt(lay.style.top)

    return(false);
}

function MouseUp(ev){
    _selected = -1;
    return(false);
}

function MouseMove(ev) {
    if (_selected != -1) {
        _x = EventGetX(ev)-_dx;
        _y = EventGetY(ev)-_dy;

        moveToDLayer(_selected, _x, _y);
    }
    return(false);
}

function moveToDLayer(id,x,y) {
    lay = document.getElementById(id);

    if (is.opera || is.ie || is.moz || is.konq) {
        lay.style.left = x;
        lay.style.top = y;
    }
    if (is.ns)
        lay.moveTo(x,y);
}

function showDLayer(id) {
    lay = document.getElementById(id);
    lay.style.visibility = 'visible';
}


function windowWidth() {
    if (is.ie) {
        width = document.body.offsetWidth;
    }
    else {
        width = window.innerWidth;
    }
    return width;
}

function windowHeight() {
    if (is.ie) {
        height = document.body.offsetHeight;
    }
    else {
        height = window.innerHeight;
    }

    return height;
}

function windowOffset(owidth,oheight) {

    this.xoff = 0;
    this.yoff = 0;
    this.width = 0;
    this.height = 0;

    while (this.width == 0) {
        this.width = windowWidth();
        this.height = windowHeight();
    }

    this.xoff = (this.width-owidth)/2;
    this.yoff = (this.height-oheight)/2;

    if (this.xoff < 0) this.xoff = 0;
    if (this.yoff < 0) this.yoff = 0;
}

function enableActions(){
        document.onmousemove = MouseMove;
        document.onmouseup = MouseUp;
}

function addDImage(parent, name, x, y){
    lay = document.getElementById(parent);
    img = document.createElement("img");
    expid = /\/(.*)\./;
    expz = /_(\d*)?/;
    expid.exec(name);
    id = RegExp.$1;
    expz.exec(id);
    if (RegExp.$1) {
        z = RegExp.$1;
    }
    else {
        z = 10;
    }
    if (is.ie) {
        img.src = name;
        img.id = id;
        img.alt = "bild laedt...";
    }
    else {
        alt = document.createAttribute("alt");
        alt.nodeValue = "bild laedt...";
        img.setAttributeNode(alt);
        src = document.createAttribute("src");
        src.nodeValue = name;
        img.setAttributeNode(src);
        imgid = document.createAttribute("id");
        imgid.nodeValue = id;
        img.setAttributeNode(imgid);
    }
    img.style.position = "absolute";
    img.style.top = y;
    img.style.left = x;
    img.style.zIndex = z;
    img.onmousedown = MouseDown;
    lay.appendChild(img);

    return(id);
}


function setimg(id, state) {
    eval ("document.getElementById(id).src = "+id+state+".src");
}
