/*****************************************
* Written by Terry Friesen, tfriesen@mts.net  copyright 1998-2002
* http://www.mts.net/~tfriesen/
*
* last update: July 29, 2002
*
* This script may be used freely on non-commercial web pages
* It is not to be sold or profit made from it without the consent of the author
*
*
* JavaScript functions used to handle layer
*
******************************************/

/**
* set mouse coordinates
*/
function setCoords(e)
{
    if (typeof(event) == "undefined") {
        posX = parseInt(e.pageX+10);
        posY = parseInt(e.pageY);
    } else
    {
        posX = parseInt(event.clientX+10) + parseInt(document.body.scrollLeft);
        posY = parseInt(event.clientY) + parseInt(document.body.scrollTop);
    }
    
/*    
    
    var ns6 = document.getElementById&&!document.all;
    if (document.layers || ns6)
    {
        posX = parseInt(e.pageX+10);
        posY = parseInt(e.pageY);
    } else
    {
        posX = parseInt(event.clientX+10) + parseInt(document.body.scrollLeft);
        posY = parseInt(event.clientY) + parseInt(document.body.scrollTop);
    }*/
    if (stillOver)
        showInfotext(myLayer);
}

/**
* show selected layer
*/
function showInfotext(layer_id)
{
    myLayer = eval("cssLayers." + layer_id);
    myLayer.Visibility('visible');
    myLayer.moveTo(posX,posY);
    stillOver = true;
    myLayer = layer_id;
}

/**
* hide selected layer
*/
function hideInfotext(layer_id)
{
    myLayer = eval("cssLayers." + layer_id);
    myLayer.Visibility('hidden');
    stillOver = false;
}


/**
* set variables depending on used browser
*/
function cbSetup(a2,a1)
{
    var w = self;
    if(a1)
        w = a1.self ? a1 : a1.owner.frames[a1.name]||a1;
    var d = w.page = w.document
    var c = w.Client = navigator;
    c.kon = c.product == "Konqueror/khtml";
    c.kon3 = c.kon && !!d.width;
    c.kon2 = c.kon && !c.kon3;
    c.opera = !!w.opera;
    c.style = !!d.styleSheets;
    c.nodes = !!d.createTextNode;
    c.ns = !!d.watch;
    c.ns4 = c.ns && !c.nodes;
    c.ns6 = c.ns && !c.ns4;
    c.moz = !!d.compatMode && c.ns;
    c.ie = !!w.execScript && !w.debug;
    c.ie4 = c.ie && !c.nodes;
    c.ie5 = c.ie && !c.ie4;
    c.ie6 = !!d.compatMode && c.ie;
    c.cssBox = c.ie || c.ns ? d.compatMode == 'CSS1Compat' || c.ns6 : true;
    var e = a1 || w;
    var wa = w.Array;
    e.frameWindow = w.frameWindow = d.window = w;
    e.cssLayers = d.cssLayers = w.cssLayers = new Array();
    w.getParent = getParent;
    w.setupEvent = setupEvent;
    w.setEventHandler = d.setEventHandler = setEventHandler;
    w.sendEvent = d.sendEvent = sendEvent;
    w.createEvent = createEvent;
    w.doNothing = doNothing;
    w.insertElement = insertElement;
    w.selectedText = selectedText;
    w.setupFrame = setupFrame;
    w.setupCollection = setup_Col;
    if(wa)
    {
        wa.prototype.addMethod = ad_Meth;
        wa.prototype.add_nam = new Array();
        wa.prototype.add_func = new Array();
    }
    d.holds = _holds;
    if(!w.pxWidth)
    {
        w.pxWidth = pxWidth;
        w.pxHeight = pxHeight;
        w.h_sBar = h_sBar;
        w.v_sBar = v_sBar;
    }
    if(!d.pxWidth)
    {
        d.pxWidth = doc_Width;
        d.pxHeight = doc_Height;
    }
    if(!d.self && !d.Index)
        d.owner =e
    if(!w.offsetTop)
    {
        w.offsetTop = offsetTop;
        w.offsetLeft = offsetLeft;
    }
    if(!w.allLayers)
        w.allLayers = e.allLayers = allLayers;
    if(this.runBatch)
    {
        if(wa)
            wa.prototype.runBatch = runBatch;
        w.insertCoverLayer = insertCoverLayer;
    }
    if(c.ns4)
    {
        if(w.self)
        {
            w.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE | Event.CLICK | Event.DBLCLICK | Event.KEYDOWN | Event.KEYUP | Event.KEYPRESS);
            w.onmousedown = w.onmouseup = w.onmousemove = w.onclick = w.ondblclick = w.onkeydown = w.onkeyup = w.onkeypress = ns4_Evt;
        }
        var lay = d.layers.length ? d.layers[0] : 0;
        while(lay)
        {
            var ls = lay.src;
            cb_index(lay,!!ls,w,e);
            lay = ls ? lay.siblingAbove : lay.above;
            if(lay&&lay.Index)
                break;
        }
        orig_Width = innerWidth;
        orig_Height = innerHeight;
        setEventHandler("resize",ns4_reSize,"cb");
    }
    if(!d.all && c.style)
        d.all = d.getElementsByTagName("*");
    if(d.body)
    {
        d.body.window = w;
        var va = a2 || "DIV";
        var we = c.ie ? d.all.tags(va) : d.body.getElementsByTagName(va);
        for(var i=0; i<we.length; i++)
            cb_index(we[i],false,w,e);
    }
}

/**
*
*/
function setupFrame(a1,a2)
{
    var p = this.page;
    var f = a1.self ? a1:Client.ns4 ? p.layers[a1] || allLayers[a1] : p.all[a1];
    if(!f.self)
        cb_index(f,true,this,this);
    cbSetup(a2,f);
    return f;
}

/**
*
*/
function setup_Col(a1)
{
    for(var ab=0; ab<a1.length; ab++)
        basicMethods(a1[ab]);
    a1.addMethod = addMethod;
}

allLayers = new Array();

function cb_index(lay,noadd,w,e)
{
    var wl = w.cssLayers;
    var al = allLayers;
    var ln = lay.layerName = lay.layerName || lay.id || lay.name || ("cb_layer" + al.length);
    var lw = lay.frameWindow = w.Index ? lay : w.frames[ln] || lay;
    lay.page = lw.document || w.document;
    lay.owner = e;
    lay.nextLayer = lay.previousLayer = lay.previous = lay.next = null;
    var winl = wl.length;
    var alay = lay.arrayIndex = al.length;
    wl[ln] = al[ln] = al[al.length] = lay;
    lay.cssLayers = new Array();
    if(!noadd)
    {
        if(alay > 0)
        {
            lay.previous = al[alay-1];
            lay.previous.next = lay;
        }
        var par =getParent(lay);
        lay.isNested = !!par.Index;
        if(lay.isNested)
        {
            var pl = par.cssLayers;
            var parl = pl.length;
            pl[ln] = pl[parl] = lay;
            if(parl > 0)
            {
                lay.previousLayer = pl[parl-1];
                lay.previousLayer.nextLayer = lay;
            }
        } else
        {
            if(winl > 0)
            {
                lay.previousLayer = wl[winl-1];
                lay.previousLayer.nextLayer = lay;
            }
        }
        if(!lay.isNested)
            wl[winl]=lay;
    }
    cb_addon(lay,wl,al);
}

function cb_addon(lay,wl,al)
{
    basicMethods(lay);
    if(self.runPath)
        pathMethods(lay);
    if(self.runBatch)
        utilityMethods(lay);
    if(self.clipTo)
        clipMethods(lay);
    if(self.make3d)
        lay.make3d = make3d;
    if(!lay.src)
    {
        for(var a=0; a<wl.add_nam.length; a++)
            lay[wl.add_nam[a]] = wl.add_func[a];
        for(var a=0; a<al.add_nam.length; a++)
            lay[al.add_nam[a]] = al.add_func[a];
    }
}

function basicMethods(lay)
{
    var lp = lay.page = lay.page || lay;
    if(Client.ns4)
    {
        lp.pxHeight = doc_Height;
        lp.pxWidth = doc_Width;
        lay.images = lp.images;
        lay.forms = lp.forms;
        lay.links = lp.links;
        lay.pxHeight = ns_height;
        lay.pxWidth = ns_width;
        lay.pxLeft = ns_left;
        lay.pxTop = ns_top;
        lay.Index = ns_index;
        lay.Visibility = ns_visible;
        lay.innerHTML = "";
    } else
    {
        lay.pxHeight = ie_height;
        lay.pxWidth = ie_width;
        lay.pxLeft = ie_left;
        lay.pxTop = ie_top;
        lay.page = lay.page == (lay.ownerDocument || lay.document) ? lay : lay.page;
        lay.Index = ie_index;
        lay.Visibility = ie_visible;
        lay.load = ie_load;
        lay.tags = lay.getElementsByTagName || lay.all.tags;
        lay.images = lay.tags("IMG");
        lay.forms = lay.tags("FORM");
        lay.links = lay.tags("A");
        if(Client.ie4)
            ie4_Width(lay);
    }
    lay.moveTo = move_To;
    lay.absLeft = ab_Left;
    lay.absTop = ab_Top;
    lay.resizeTo = resize_To;
    lay.setBgColor = set_BgC;
    lay.setBgImage = set_BgI;
    lay.isNewLayer = false;
    lay.percentX = per_X;
    lay.percentY = per_Y;
    lay.posX = pos_X;
    lay.posY = pos_Y;
    lay.setEventHandler = lay.page.setEventHandler = setEventHandler;
    lay.setContent = set_Cont;
    lay.insertElement = insertElement;
    lay.sendEvent = sendEvent;
    lay.holds = _holds
}

function ns_height(a1,a2)
{
    var c = this.clip;
    if(!isNaN(parseInt(a1)))
    {
        c.height = (String(a1).search('%') > 0 ? this.percentY(a1) : a1) + (a2 || 0);
        return this;
    }
    return Math.max(c.height,this.page.height);
}

function ie_height(a1,a2)
{
    var s = this.style;
    if(!isNaN(parseInt(a1)) && (a1 != self.undefined))
    {
        s.height = (String(a1).search('%') > 0 ? this.percentY(a1) : a1) + (a2 || 0) + "px";
        return this;
    }
    return this.offsetHeight || s.pixelHeight;
}

function ns_width(a1,a2)
{
    var c = this.clip;
    if(!isNaN(parseInt(a1)))
    {
        c.width = (String(a1).search('%') > 0 ? this.percentX(a1) : a1) + (a2 || 0);
        return this;
    }
    return Math.max(c.width,this.page.width);
}

function ie_width(a1,a2)
{
    var s = this.style;
    if(!isNaN(parseInt(a1)) && (a1 != self.undefined))
    {
        s.width=(String(a1).search('%') > 0 ? this.percentX(a1) : a1) + (a2 || 0) + "px";
        return this;
    }
    return this.offsetWidth || s.pixelWidth;
}

function resize_To(a1,a2,a3,a4)
{
    return this.pxWidth(a1,a3).pxHeight(a2,a4);
}

function ns_left(a1,a2)
{
    if(!isNaN(parseInt(a1)))
    {
        this.x = (!isNaN(a1) ? a1 : (a1.search('%') > 0 ? this.percentX(a1) : this.posX(a1))) + (a2 || 0);
        return this;
    }
    return this.x;
}

function ie_left(a1,a2)
{
    var p = self.opera ? "" : "px";
    var s = this.style;
    if(!isNaN(parseInt(a1)) && (a1 != self.undefined))
    {
        s.left = (!isNaN(a1) ? a1 : (a1.search('%') > 0 ? this.percentX(a1) : this.posX(a1))) + (a2 || 0) + p;
        return this;
    }
    return this.offsetLeft - ((this.isNested && !this.offsetParent) ? getParent(this).offsetLeft : 0);
}

function ns_top(a1,a2)
{
    if(!isNaN(parseInt(a1)))
    {
        this.y = (!isNaN(a1) ? a1 : (a1.search('%') > 0 ? this.percentY(a1) : this.posY(a1))) + (a2||0);
        return this;
    }
    return this.y;
}

function ie_top(a1,a2)
{
    var p = self.opera ? "" : "px";
    var s = this.style;
    if(!isNaN(parseInt(a1)) && (a1 != self.undefined))
    {
        s.top = (!isNaN(a1) ? a1 : (a1.search('%') > 0 ? this.percentY(a1) : this.posY(a1))) + (a2||0) + p;
        return this;
    }
    return this.offsetTop - ((this.isNested && !this.offsetParent) ? getParent(this).offsetTop : 0);
}

function ab_Left()
{
    var l = this.pageX || this.offsetLeft;
    var p = this.offsetParent;
    if(Client.ns4)
        return this.owner.src ? l-this.owner.pageX : l;
    if(p)
    {
        while(p)
        {
            l += p.offsetLeft;
            p = p.offsetParent;
        }
    }
    return l;
}

function ab_Top()
{
    var t = this.pageY || this.offsetTop;
    var p = this.offsetParent;
    if(Client.ns4)
        return this.owner.src ? t-this.owner.pageY : t;
    if(p)
    {
        while(p)
        {
            t += p.offsetTop;
            p = p.offsetParent;
        }
    }
    return t
}

function move_To(a1,a2,a3,a4)
{
    return this.pxLeft(a1,a3).pxTop(a2,a4);
}

function ns_index(a1)
{
    if(!isNaN(a1))
    {
        this.zIndex = a1;
        return this;
    }
    return this.zIndex;
}

function ie_index(a1)
{
    if(!isNaN(a1) && (a1!=self.undefined))
    {
        this.style.zIndex = a1;
        return this;
    }
    return this.style.zIndex || 0;
}

function ns_visible(a1)
{
    var v = this.visibility;
    if(a1)
    {
        this.visibility = a1;
        return this;
    }
    if(v == 'hide')
        return 'hidden';
    if(v == 'show')
        return 'visible';
    return 'inherit';
}

function ie_visible(a1)
{
    if(a1)
    {
        this.style.visibility = a1;
        return this;
    }
    return this.style.visibility || 'inherit';
}

function set_BgC(a1)
{
    if(this.style)
        this.style.backgroundColor = a1 || "transparent";
    this.bgColor = a1||null;
    return this;
}

function set_BgI(a1)
{
    if(this.style)
        this.style.backgroundImage = "url(" + a1 + ")";
    else
        this.background.src = a1 || null;
    this.bgImage = a1;
    return this;
}

function set_Cont(a1)
{
    if(Client.ns4)
    {
        with(this.page)
        {
            write(a1 || "");
            close();
        }
    }
    this.innerHTML = a1 || "";
    return this;
}

function _holds(a1)
{
    var r = a1;
    while(r && !r.self && r != this)
        r = r.parentNode || r.__parent__ || r.parentElement;
    return r ? this==r : !!this.open && !!a1;
}

function insertElement(a1,a2,a3,a4)
{
    if(a1 && allLayers[a1])
    {
        alert("insertElement() failed\nID '" + a1 + "' is already in use");
        return true;
    }
    var ln = a1 || ("cb_layer" + allLayers.length);
    var t = a3 || "DIV";
    var p = this;
    var d;
    if(Client.style)
    {
        if(p.self)
            p = p.page.body;
        if(p.src)
            p = p.frameWindow.page.body;
        if(Client.ie)
        {
            var iediv = "<" + t + " ID=" + ln + " frameBorder=0 style='position:absolute;height:0;top:0;left:0;visibility:hidden;'></" + t + ">";
            p.insertAdjacentHTML("BeforeEnd",iediv);
            d = p.document.all[ln];
        } else
        {
            d = p.ownerDocument.createElement(t);
            with(d.style)
            {
                position = "absolute";
                top = 0;
                left = 0;
                visibility = "hidden";
            }
            d.id = d.name = ln;
            d.frameBorder = 0;
            p.appendChild(d);
        }
    } else
    {
        d = new Layer(a2||screen.width,p);
        d.zIndex = 0;
    }
    var dh =this.allLayers ? this : this.owner;
    d.layerName = ln;
    cb_index(d,a4,dh,dh);
    d.isNewLayer = true;
    d.pxWidth(a2 || 0);
    return d;
}

function selectedText()
{
    var d = this.page;
    return d.selection ? d.selection.createRange().text : d.getSelection();
}

function ie_load(a1,a2)
{
    this.pxWidth(a2);
    this.src = a1
}

function pxWidth()
{
    var d = this.page.compatMode == 'CSS1Compat' ? this.page.documentElement : this.page.body;
    return this.v_sBar() ? this.innerWidth-16 : this.innerWidth||d.clientWidth;
}

function pxHeight()
{
    var d = this.page.compatMode == 'CSS1Compat' ? this.page.documentElement : this.page.body;
    return this.h_sBar() ? this.innerHeight-16 : this.innerHeight||d.clientHeight;
}

function offsetTop()
{
    var d = this.page;
    var w = d.body || this;
    var e = d.documentElement || w;
    if(w.clip)
        return w.clip.top;
    return Math.max(e.scrollTop || w.scrollTop || this.pageYOffset || 0,0);
}

function offsetLeft()
{
    var d = this.page;
    var w = d.body || this;
    var e = d.documentElement || w;
    if(w.clip)
        return w.clip.left;
    return Math.max(e.scrollLeft || w.scrollLeft || this.pageXOffset || 0,0);
}

function doc_Height(a1)
{
    var d =this.compatMode == 'CSS1Compat' ? this.documentElement : this.body || this;
    if(Client.ns4 && a1)
        d.height = a1;
    return d.scrollHeight || d.offsetHeight || d.height || 0;
}

function doc_Width(a1)
{
    var d = this.compatMode == 'CSS1Compat' ? this.documentElement : this.body || this;
    if(Client.ns4 && a1)
        d.width = a1;
    return d.scrollWidth || d.offsetWidth || d.width || 0;
}

function createEvent(a1)
{
    var o = new Object();
    o.type = a1;
    o.cbEvent = true;
    return o;
}

function setEventHandler(a1,a2,a3,a4)
{
    var an = a1.toLowerCase();
    var ae = this["cb"+an];
    if(!ae)
        ae = this["cb"+an] = new Array();
    ae[a3||0] = a2;
    ae[0] = ae[0]||0;
    if(this.self && an.search(new RegExp("mouse?|click?|key?","g"))!=-1)
    {
        alert(a1 + " event not allowed on window");
        return;
    }
    var f = a4 ? a2 : sendEvent;
    if(an == "dblclick" && Client.ns6)
    {
        this.addEventListener(an,f,false);
        return;
    }
    this["on"+an] = f;
}

function ns4_Evt(e)
{
    sendEvent.apply(get_Targ.apply(e),e);
}

function setupEvent(a1)
{
    var h = this;
    var e = a1 || h.event;
    var d = new Date();
    var s;
    if(Client.ie4)
    {
        var eo = new Object();
        for(s in e)
            eo[s] = e[s];
        e = eo;
    }
    if(Client.ie || h.opera || Client.kon)
    {
        var eb = e.button;
        if(eb == 2)
            e.click = 3;
        if(eb == 4)
            e.click = 2;
        e.pageX = e.clientX + (Client.ie ? h.offsetLeft() : 0);
        e.pageY = e.clientY + (Client.ie ? h.offsetTop() : 0);
    }
    e.time = d.getTime();
    e.window = h;
    e.getTarget = get_Targ;
    e.getPhase = get_Phas;
    if(!e.stopPropagation)
        e.stopPropagation = stop_Flo;
    e.getLayerX = getL_X;
    e.getLayerY = getL_Y;
    var r = !h.opera ? e.relatedTarget : null;
    e.relatedElement = r?r.splitText?r.parentNode:r:e.type=="mouseover"?e.fromElement||e.relatedTarget:e.type=="mouseout"?e.toElement||e.relatedTarget:null;
    e.key = e.keyCode || e.which || e.charCode;
    e.click = e.which || e.click || 1;
    if(Client.ns4)
    {
        e.clientX = (h.src?e.pageX-h.pageX:e.pageX)-h.offsetLeft();
        e.clientY = (h.src?e.pageY-h.pageY:e.pageY)-h.offsetTop();
        var m = e.modifiers;
        e.altKey = m==1||m==3||m==5||m==7;
        e.ctrlKey = m==2||m==3||m==6||m==7;
        e.shiftKey = m==4||m==5||m==6||m==7;
    }
    return e;
}

function sendEvent(a1)
{
    var h = (this.owner||this).frameWindow || self;
    var q = a1 || h.event;
    var t = q.type || q;
    var ae = this["cb"+t];
    var e = q;
    if(Client.ns6 && t=="mouseout" && !e.relatedTarget)
        return;
    if(this['on'+t] || ae)
    {
        e = h.setupEvent(q);
        e.evt = q;
        e.caller = this;
        if(ae)
        {
            e.previous = ae.last || e;
            ae.last = e;
            this.tmp_m = ae["cb"];
            if(this.tmp_m)
                this.tmp_m(e);
            for(var b=0; b<ae.length; b++)
            {
                if(ae[b])
                {
                    this.tmp_m = ae[b];
                    this.tmp_m(e);
                }
            }
        } else
            this['on'+t](e);
    }
    if((Client.ns4 || e.cbEvent) && !e.cancelBubble && !this.open)
        getParent(this,1).sendEvent(e);
}

function getL_X()
{
    var e = this;
    var et = e.getTarget("l");
    return e.layerX+1 || e.pageX-(et.Index?et.absLeft()+1:0);
}

function getL_Y()
{
    var e = this;
    var et = e.getTarget("l");
    return e.layerY+1 || e.pageY-(et.Index?et.absTop()+1:0);
}

function get_Targ(a)
{
    var t = this.target || this.srcElement;
    if(a == 2)
        return t.splitText ? t : null;
    if(t.splitText)
        t = t.parentNode;
    if(a == 1)
        return t.tagName ? t : null;
    var p = getParent(t);
    if(Client.ns4 && t.links && p && !p.setupFrame)
        t = t.__parent__;
    if(t.tagName)
    {if(!t.type&&!t.href&&!t.src&&!t.Index)p.tags?t=p:t=t.ownerDocument||t.document}
    return a&&a!=0?t.Index?t:p:t
}

function get_Phas(a1)
{
    return this.caller == this.getTarget(a1) ? 2 : 3;
}

function stop_Flo()
{
    var e = this.evt || this;
    e.cancelBubble = true;
}

function ad_Meth(a1,a2)
{
    for(var i=0; i<this.length; i++)
    {
        if(this[i])
            this[i][a1] = a2;
    }
    var n = this.add_nam;
    var f = this.add_func;
    n[n.length] = a1;
    f[f.length] = a2;
}

function pos_X(a1)
{
    var num = parseInt(a1)/100;
    var p = getParent(this);
    var v = p.pxWidth()*num-this.pxWidth()*num;
    return p.Index ? v : v+p.offsetLeft();
}

function pos_Y(a1)
{
    var num = parseInt(a1)/100;
    var p = getParent(this);
    var v = p.pxHeight()*num-this.pxHeight()*num;
    return p.Index ? v : v+p.offsetTop();
}

function per_X(a1)
{
    var p =getParent(this);
    return parseInt(a1)*(Math.max(p.pxWidth(),p.page.pxWidth())/100);
}

function per_Y(a1)
{
    var p = getParent(this);
    return parseInt(a1)*(Math.max(p.pxHeight(),p.page.pxHeight())/100);
}

function getParent(a1,a2)
{
    var p = a1;
    var w;
    if(p)
    {
        p = p.form || p;
        if(Client.ns4)
            w = p.parentLayer || p.window || p.__parent__.__parent__;
        else
        {
            if(!p.window)
            {
                while((!p.window&&!p.Index)||p==a1)
                    p = p.parentNode || p.parentElement;
            }
            if(p.Index)
                return p;
            w = p.window;
        }
    }
    return a2&&w.setupFrame?a1.open?w:w.page:w;
}

function ie4_Width(a1)
{
    if(a1.getAttribute('wrap'))
        a1.style.width = a1.scrollWidth || a1.offsetWidth;
}

function h_sBar()
{
    return Client.ns?this.page.pxWidth()>this.innerWidth:false;
}

function v_sBar()
{
    return Client.ns?this.page.pxHeight()>this.innerHeight:false;
}

function ns4_reSize()
{
    if(innerWidth!=orig_Width || innerHeight!=orig_Height)
        location.reload();
}

function doNothing()
{
}

cbSetup()
