var layerNo=0; 
var layerObjects = new Array(); 
function xLayer(newLayer, x, y) { 
    if(browser.ns4Layer) { 
        if(typeof newLayer == "string") { 
            if(x==null) {x=0;} 
            if(y==null) {y=0;} 
            this.layer=new Layer(2000); 
            this.layer.document.open(); 
            this.layer.document.write(newLayer); 
            this.layer.document.close(); 
            this.layer.moveTo(x,y); 
        } else { 
            this.layer=newLayer; 
        } 
        this.css = this.layer; 
        this.images=this.layer.document.images; 
    } else if(browser.ie4Layer) { 
        var id; 
        if(typeof newLayer == "string") { 
            id = "layer" + layerNo++;
            var txt = "<" + "DIV ID='" + id + "' STYLE=\"position:absolute;" 
                    + "left:" + x + ";" + "top:" + y + ";" + "overflow:hidden;" 
                    + "visibility:hidden\">" + newLayer + "<" + "/na/DIV>"; 
            document.body.insertAdjacentHTML("BeforeEnd",txt); 
        } else { 
            id = newLayer.id; 
        } 
        this.layer = document.all[id]; 
        this.css = document.all[id].style; 
        this.images = document.images; 
    } else if (browser.dom) { 
        var newDiv; 
        if(typeof newLayer == "string") { 
            var id="layer" + layerNo++; var txt = "" + "position:absolute;" 
                 + "left:" + x + "px;" + "top:" + y + "px;" + "visibility:hidden"; 
            var newRange = document.createRange(); 
            newDiv = document.createElement("DIV"); 
            newDiv.setAttribute("style",txt); 
            newDiv.setAttribute("id", id); 
            document.body.appendChild(newDiv); 
            newRange.setStartBefore(newDiv); 
            strFrag = newRange.createContextualFragment(newLayer); 
            newDiv.appendChild(strFrag); 
         } else { 
             newDiv = newLayer; 
         } 
         this.layer = newDiv; 
         this.css = newDiv.style; 
         this.images = document.images; 
     } 
     this.doc = (browser.dom || browser.ie4Layer) ? document : this.css.document; 
     this._x = parseInt(this.css.left) || this.css.pixelLeft || this.layer.offsetLeft || 0; 
     this._y = parseInt(this.css.top) || this.css.pixelTop || this.layer.offsetTop || 0; 
     this._width = this.layer.offsetWidth || this.css.clip.width || this.doc.width || this.css.pixelWidth || 0; 
     this._height = this.layer.offsetHeight || this.css.clip.height || this.doc.height || this.css.pixelHeight || 0; 
     this.c=0; 
     if((browser.dom || browser.ie4Layer) && this.css.clip) { 
         this.c = this.css.clip; this.c = this.c.slice(5, this.c.length-1); 
         this.c = this.c.split(' '); 
         for(var i=0;i<4;i++) { this.c[i]=parseInt(this.c[i]); } 
     } 
     this.ct = this.css.clip.top || this.c[0] || 0; 
     this.cr = this.css.clip.right || this.c[1] || this.w || 0; 
     this.cb = this.css.clip.bottom || this.c[2] || this.h || 0; 
     this.cl = this.css.clip.left || this.c[3] || 0; 
     if(typeof newLayer == "string") { 
         this.obj = "Object" + (layerNo); 
         eval(this.obj + "=this"); 
     } else { 
         this.obj = newLayer.id + "Object"; eval(this.obj + "=this"); 
     } 
     return(this); 
}; 
function xLayerFromID(id) { 
    if(layerObjects[id]) {return layerObjects[id];} 
    var l; 
    if(browser.ns4Layer) { l = new xLayer(document.layers[id]); } 
    else if(browser.ie4Layer) { l = new xLayer(document.all[id]); } 
    else if(browser.dom) { l = new xLayer(document.getElementById(id)); } 
    layerObjects[id] = l; 
    return (l); 
}; 
xLayer.prototype.moveTo = function(x,y) { this._x = x; this._y = y; this.css.left = x; this.css.top = y; }; 
xLayer.prototype.resizeTo = function(w,h) { if (browser.ns4Layer) { this.layer.resizeTo(w, h); } else if (typeof this.css.pixelWidth != "undefined") { this.css.pixelWidth = w; this.css.pixelHeight = h; } else { this.css.width = w; this.css.height = h; } }; 
xLayer.prototype.show = function() { this.css.visibility = "visible"; }; 
xLayer.prototype.hide = function() { this.css.visibility = "hidden"; }; 
xLayer.prototype.isVisible = function() { if(browser.dom || browser.ie4Layer) {return this.css.visibility == "visible";} else if(browser.ns4Layer) {return this.layer.visibility == "show";} }; 
function getAbsX(elt) { 
    return (elt.x) ? elt.x : getAbsPos(elt,"Left"); 
}; 
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }; 
function getAbsPos(elt,which) { iPos = 0; while (elt != null) { iPos += elt["offset" + which]; elt = elt.offsetParent; } return iPos; }; 
function setPosition(elt,positionername,dx,dy) { var positioner; if (browser.ie4Layer) { positioner = document.all[positionername]; } else { if (browser.dom) { positioner = document.getElementById(positionername); } else { positioner = document.images[positionername]; } } elt.left = getAbsX(positioner) + parseInt(dx)+"px";elt.top = getAbsY(positioner) + parseInt(dy)+"px"; }; 
xLayer.prototype.fixPosition = function(imgname, dx, dy) { setPosition(this.css,imgname,dx,dy); if(browser.ns4Layer) { this._x = this.css.left; this._y = this.css.top; } }; 
function getLeft(id) { return (new xLayerFromID(id))._x; }; 
function getTop(id) { return (new xLayerFromID(id))._y; }; 
function getWidth(id) { return (new xLayerFromID(id))._width; }; 
function getHeight(id) { return (new xLayerFromID(id))._height; }; 
function moveTo(id, x, y) { (new xLayerFromID(id)).moveTo(x,y); }; 
function resizeTo(id, w, h) { (new xLayerFromID(id)).resizeTo(w,h); }; 
function show(id) { (new xLayerFromID(id)).show(); }; 
function hide(id) { (new xLayerFromID(id)).hide(); }; 
function isVisible(id) { (new xLayerFromID(id)).isVisible(); }; 
function fixPosition(id,imgname,dx,dy) { (new xLayerFromID(id)).fixPosition(imgname,dx,dy); }; 
