/**
 * Menu 990702
 * by gary smith, July 1997
 * Copyright (c) 1997-1999 Netscape Communications Corp.
 *
 * Menu 020903
 * by doron rosenberg, September 2002
 * Copyright (c) 1997-2002 Netscape Communications Corp.
 *
 * Menu 030409
 * by doron rosenberg <doron at netscape.com>, April 2003 - fix for strict doctypes
 * Copyright (c) 1997-2003 Netscape Communications Corp. 
 *
 * Osd 040811
 * by xavier degeneve <xavier at degeneve.net>, August 2004 - fix zero item rename it.
 * Copyright (c) 2004 GPL if possible
 *
 * Netscape grants you a royalty free license to use or modify this
 * software provided that this copyright notice appears on all copies.
 * This software is provided "AS IS," without a warranty of any kind.
 */

function Osd(label) {
    this.position4disp = 0; // Special LATIAG
    this.version = "040811 [Osd; osd.js]";
    this.type = "Osd";
    this.fontSize = 14;
    this.fontWeight = "plain";
    this.fontFamily = "arial,helvetica,espy,sans-serif";
    this.fontColor = "#000000";
    this.fontColorHilite = "#ffffff";
    this.bgColor = "#555555";
    this.osdBorder = 1;
    this.osdItemBorder = 1;
    this.osdItemBgColor = "#cccccc";
    this.osdLiteBgColor = "#ffffff";
    this.osdBorderBgColor = "#777777";
    this.osdHiliteBgColor = "#000084";
    this.osdContainerBgColor = "#cccccc";
    this.childOsdIcon = "images/arrows.gif";
    this.childOsdIconHilite = "images/arrows2.gif";
    this.items = new Array();
    this.actions = new Array();
    this.colors = new Array();
    this.mouseovers = new Array();
    this.mouseouts = new Array();
    this.childOsds = new Array();

    this.addOsdItem = addOsdItem;
    this.addOsdSeparator = addOsdSeparator;
    this.writeOsds = writeOsds;
    this.showOsd = showOsd;
    this.onOsdItemOver = onOsdItemOver;
    this.onOsdItemOut = onOsdItemOut;
    this.onOsdItemDown = onOsdItemDown;
    this.onOsdItemAction = onOsdItemAction;
    this.hideOsd = hideOsd;
    this.hideChildOsd = hideChildOsd;
    this.mouseTrackerOsd = mouseTrackerOsd;
    this.setMouseTrackerOsd = setMouseTrackerOsd;

    if (!window.Osds) window.Osds = new Array();
    this.label = label || "osdLabel" + window.Osds.length;
    window.Osds[this.label] = this;
    window.Osds[window.Osds.length] = this;
    if (!window.activeOsds) window.activeOsds = new Array();
    if (!window.osdContainers) window.osdContainers = new Array();
    if (!window.mDrag) {
        window.mDrag    = new Object();
        mDrag.startOsdDrag = startOsdDrag;
        mDrag.doOsdDrag    = doOsdDrag;
        this.setMouseTrackerOsd();
    }
    if (window.OsdAPI) OsdAPI(this);
}

function addOsdItem(label, action, color, mouseover, mouseout) {
    this.items[this.items.length] = label;
    this.actions[this.actions.length] = action;
    this.colors[this.colors.length] = color;
    this.mouseovers[this.mouseovers.length] = mouseover;
    this.mouseouts[this.mouseouts.length] = mouseout;
}

function addOsdSeparator() {
    this.items[this.items.length] = "separator";
    this.actions[this.actions.length] = "";
    this.osdItemBorder = 0;
}

function writeOsds(container) {
    if (!container && document.layers) {
        if (eval("document.width")) 
            container = new Layer(1000);
    } else if (!container && document.all) {
        if (!document.all["osdContainer"]) 
            document.writeln('<SPAN ID="osdContainer" style="z-index: 20";></SPAN>');
        container = document.all["osdContainer"];
    }else if (!container && document.getElementById) {
      if (!document.getElementById("osdContainer")){ 
        container = document.createElement("span");
		container.id="osdContainer"
	    document.body.appendChild(container);
	  }
    }
		
    if (!container && !window.delayWriteOsds) {
        window.delayWriteOsds = this.writeOsds;
        window.osdContainerBgColor = this.osdContainerBgColor;
        setTimeout('delayWriteOsds()', 3000);
        return;
    }
    container.isContainer = "osdContainer" + osdContainers.length;
    osdContainers[osdContainers.length] = container;
    container.Osds = new Array();
    for (var i=0; i<window.Osds.length; i++) 
        container.Osds[i] = window.Osds[i];
    window.Osds.length = 0;
    var countOsds = 0;
    var countItems = 0;
    var top = 0;
    var content = '';
    var proto;
    for (var i=0; i<container.Osds.length; i++, countOsds++) {
        var osd = container.Osds[i];
        proto = osd.prototypeStyles || this.prototypeStyles || osd;
        content += ''+
        '<DIV ID="osdLayer'+ countOsds +'" STYLE="z-index:20;position:absolute;left:10px;top:'+ (i * 100) +'px;visibility:hidden;">\n'+
        '  <DIV ID="osdLite'+ countOsds +'" STYLE="position:absolute;left:'+ proto.osdBorder +'px;top:'+ proto.osdBorder +'px;visibility:hide;" onMouseOut="hideOsd(event);">\n'+
        '    <DIV ID="osdFg'+ countOsds +'" STYLE="position:absolute;left:1px;top:1px;visibility:hide;">\n'+
        '';
        var x=i;
        for (var i=0; i<osd.items.length; i++) {
            var item = osd.items[i];
            var childOsd = false;
            var defaultHeight = 20;
            var defaultIndent = 15;
            if (item.label) {
                item = item.label;
                childOsd = true;
            } else if (item.indexOf(".gif") != -1 && item.indexOf("<IMG") == -1) {
                item = '<IMG SRC="' + item + '" NAME="osdItem'+ countItems +'Img">';
                defaultIndent = 0;
                if (document.layers) {
                    defaultHeight = null;
                }
            }
            proto.osdItemHeight = proto.osdItemHeight || defaultHeight;
            proto.osdItemIndent = proto.osdItemIndent || defaultIndent;
            var itemProps = 'visibility:hide;font-Family:' + proto.fontFamily +';font-Weight:' + proto.fontWeight + ';fontSize:' + proto.fontSize + ';';
            if (document.getElementById || document.all) 
                itemProps += 'font-size:' + proto.fontSize + ';" onMouseOver="onOsdItemOver(event,this);" onMouseOut="onOsdItemOut(event,this);" onClick="onOsdItemAction(event,this);';
            var dTag    = '<DIV  class="osdItemText" ID="osdItem'+ countItems +'" STYLE="position:absolute;left:0;top:'+ (i * proto.osdItemHeight) +';'+ itemProps +'">';
            var dText   = '<DIV ID="osdItemText'+ countItems +'" STYLE="position:absolute;left:' + proto.osdItemIndent + 'px;top:0;color:'+ proto.fontColor +';">'+ item +'</DIV>\n<DIV ID="osdItemHilite'+ countItems +'" STYLE="position:absolute;left:' + proto.osdItemIndent + 'px;top:0;color:'+ proto.fontColorHilite +';visibility:hidden;">'+ item +'</DIV>';
            if (item == "separator") {
                content += ( dTag + '<DIV ID="osdSeparator'+ countItems +'" STYLE="position:absolute;left:1;top:2;"></DIV>\n<DIV ID="osdSeparatorLite'+ countItems +'" STYLE="position:absolute;left:1;top:2;"></DIV>\n</DIV>');
            } else if (childOsd) {
                content += ( dTag + dText + '<DIV ID="childOsd'+ countItems +'" STYLE="position:absolute;left:0;top:3;'+ itemProps +'"><IMG SRC="'+ proto.childOsdIcon +'"></DIV>\n</DIV>');
            } else {
                content += ( dTag + dText + '</DIV>');
            }
            countItems++;
        }
        content += '      <DIV ID="focusItem'+ countOsds +'" STYLE="position:absolute;left:0;top:0;visibility:hide;" onClick="onOsdItemAction(null,this);">&nbsp;</DIV>\n';
        content += '   </DIV>\n  </DIV>\n</DIV>\n';
        i=x;
    }
    if (!container) return;
    if (container.innerHTML) {
        container.innerHTML=content;
    } else {
        if (document.getElementById && !document.all)
          container.innerHTML=content;		
		else{
          container.document.open("text/html");
          container.document.writeln(content);
          container.document.close();
		}  
    }
    proto = null;
    if (document.layers) {
        container.clip.width = window.innerWidth;
        container.clip.height = window.innerHeight;
        container.onmouseout = this.hideOsd;
        container.osdContainerBgColor = this.osdContainerBgColor;
        for (var i=0; i<container.document.layers.length; i++) {
            proto = container.Osds[i].prototypeStyles || this.prototypeStyles || container.Osds[i];
            var osd = container.document.layers[i];
            container.Osds[i].osdLayer = osd;
            container.Osds[i].osdLayer.Osd = container.Osds[i];
            container.Osds[i].osdLayer.Osd.container = container;
            var body = osd.document.layers[0].document.layers[0];
            body.clip.width = proto.osdWidth || body.clip.width;
            body.clip.height = proto.osdHeight || body.clip.height;
            for (var n=0; n<body.document.layers.length-1; n++) {
                var l = body.document.layers[n];
                l.Osd = container.Osds[i];
                l.osdHiliteBgColor = proto.osdHiliteBgColor;
                l.document.bgColor = proto.osdItemBgColor;
                l.saveColor = proto.osdItemBgColor;
                l.mouseout  = l.Osd.mouseouts[n];
                l.mouseover = l.Osd.mouseovers[n];
                l.onmouseover = proto.onOsdItemOver;
                l.onclick = proto.onOsdItemAction;
                l.action = container.Osds[i].actions[n];
                l.focusItem = body.document.layers[body.document.layers.length-1];
                l.clip.width = proto.osdItemWidth || body.clip.width + proto.osdItemIndent;
                l.clip.height = proto.osdItemHeight || l.clip.height;
                if (n>0) l.top = body.document.layers[n-1].top + body.document.layers[n-1].clip.height + proto.osdItemBorder;
                l.hilite = l.document.layers[1];
                l.document.layers[1].isHilite = true;
                if (l.document.layers[0].id.indexOf("osdSeparator") != -1) {
                    l.hilite = null;
                    l.clip.height -= l.clip.height / 2;
                    l.document.layers[0].document.bgColor = proto.bgColor;
                    l.document.layers[0].clip.width = l.clip.width -2;
                    l.document.layers[0].clip.height = 1;
                    l.document.layers[1].document.bgColor = proto.osdLiteBgColor;
                    l.document.layers[1].clip.width = l.clip.width -2;
                    l.document.layers[1].clip.height = 1;
                    l.document.layers[1].top = l.document.layers[0].top + 1;
                } else if (l.document.layers.length > 2) {
                    l.childOsd = container.Osds[i].items[n].osdLayer;
                    l.icon = proto.childOsdIcon;
                    l.iconHilite = proto.childOsdIconHilite;
                    l.document.layers[2].left = l.clip.width -13;
                    l.document.layers[2].top = (l.clip.height / 2) -4;
                    l.document.layers[2].clip.left += 3;
                    l.Osd.childOsds[l.Osd.childOsds.length] = l.childOsd;
                }
            }
            body.document.bgColor = proto.bgColor;
            body.clip.width  = l.clip.width +1;
            body.clip.height = l.top + l.clip.height +1;
            body.document.layers[n].clip.width = body.clip.width;
            body.document.layers[n].captureEvents(Event.MOUSEDOWN);
            body.document.layers[n].onmousedown = proto.onOsdItemDown;
            //body.document.layers[n].onfocus = proto.onOsdItemDown;
            body.document.layers[n].onmouseout = proto.onOsdItemOut;
            body.document.layers[n].Osd = l.Osd;
            body.document.layers[n].top = -30;
            osd.document.bgColor = proto.osdBorderBgColor;
            osd.document.layers[0].document.bgColor = proto.osdLiteBgColor;
            osd.document.layers[0].clip.width = body.clip.width +1;
            osd.document.layers[0].clip.height = body.clip.height +1;
            osd.clip.width = body.clip.width + (proto.osdBorder * 2) +1;
            osd.clip.height = body.clip.height + (proto.osdBorder * 2) +1;
            if (osd.Osd.enableTrackerOsd) {
                osd.Osd.disableHide = true;
                setOsdTrackerOsd(osd.Osd);
            }
        }
    } else if (document.all) {
        var osdCount = 0;
        for (var x=0; x<container.Osds.length; x++) {
            var osd = container.document.all("osdLayer" + x);
            container.Osds[x].osdLayer = osd;
            container.Osds[x].osdLayer.Osd = container.Osds[x];
            container.Osds[x].osdLayer.Osd.container = osd;
            proto = container.Osds[x].prototypeStyles || this.prototypeStyles || container.Osds[x];
            proto.osdItemWidth = proto.osdItemWidth || 200;
            //osd.style.backgroundColor = proto.osdBorderBgColor;
            for (var i=0; i<container.Osds[x].items.length; i++) {
                var l = container.document.all["osdItem" + osdCount];
                l.Osd = container.Osds[x];
                proto = container.Osds[x].prototypeStyles || this.prototypeStyles || container.Osds[x];
                l.style.pixelWidth = proto.osdItemWidth;
                l.style.pixelHeight = proto.osdItemHeight;
                if (i>0) l.style.pixelTop = container.document.all["osdItem" + (osdCount -1)].style.pixelTop + container.document.all["osdItem" + (osdCount -1)].style.pixelHeight + proto.osdItemBorder;
                l.style.fontSize = proto.fontSize;
                //l.style.backgroundColor = proto.osdItemBgColor;
                l.style.visibility = "inherit";
                l.saveColor = proto.osdItemBgColor;
                l.osdHiliteBgColor = proto.osdHiliteBgColor;
                l.action = container.Osds[x].actions[i];
                l.hilite = container.document.all["osdItemHilite" + osdCount];
                l.focusItem = container.document.all["focusItem" + x];
                //XD remove: l.focusItem.style.pixelTop = -30;
                l.mouseover = l.Osd.mouseovers[x];
                l.mouseout  = l.Osd.mouseouts[x];
                var childItem = container.document.all["childOsd" + osdCount];
                if (childItem) {
                    l.childOsd = container.Osds[x].items[i].osdLayer;
                    childItem.style.pixelLeft = l.style.pixelWidth -11;
                    childItem.style.pixelTop = (l.style.pixelHeight /2) -4;
                    childItem.style.pixelWidth = 30 || 7;
                    childItem.style.clip = "rect(0 7 7 3)";
                    l.Osd.childOsds[l.Osd.childOsds.length] = l.childOsd;
                }
                var sep = container.document.all["osdSeparator" + osdCount];
                if (sep) {
                    sep.style.clip = "rect(0 " + (proto.osdItemWidth - 3) + " 1 0)";
                    //sep.style.backgroundColor = proto.bgColor;
                    sep = container.document.all["osdSeparatorLite" + osdCount];
                    sep.style.clip = "rect(1 " + (proto.osdItemWidth - 3) + " 2 0)";
                    //sep.style.backgroundColor = proto.osdLiteBgColor;
                    l.style.pixelHeight = proto.osdItemHeight/2;
                    l.isSeparator = true
                }
                osdCount++;
            }
            proto.osdHeight = (l.style.pixelTop + l.style.pixelHeight);
            var lite = container.document.all["osdLite" + x];
            lite.style.pixelHeight = proto.osdHeight +2;
            lite.style.pixelWidth = proto.osdItemWidth + 2;
            //lite.style.backgroundColor = proto.osdLiteBgColor;
            var body = container.document.all["osdFg" + x];
            body.style.pixelHeight = proto.osdHeight + 1;
            body.style.pixelWidth = proto.osdItemWidth + 1;
            //body.style.backgroundColor = proto.bgColor;
            container.Osds[x].osdLayer.style.pixelWidth  = proto.osdWidth || proto.osdItemWidth + (proto.osdBorder * 2) +2;
            container.Osds[x].osdLayer.style.pixelHeight = proto.osdHeight + (proto.osdBorder * 2) +2;
            if (osd.Osd.enableTrackerOsd) {
                osd.Osd.disableHide = true;
                setOsdTrackerOsd(osd.Osd);
            }
        }
        container.document.all("osdContainer").style.backgroundColor = container.Osds[0].osdContainerBgColor;
        container.document.saveBgColor = container.document.bgColor;
    }else if (document.getElementById) {
        var osdCount = 0;
        for (var x=0; x<container.Osds.length; x++) {
            var osd = document.getElementById("osdLayer" + x);
            container.Osds[x].osdLayer = osd;
            container.Osds[x].osdLayer.Osd = container.Osds[x];
            container.Osds[x].osdLayer.Osd.container = osd;
            proto = container.Osds[x].prototypeStyles || this.prototypeStyles || container.Osds[x];
            proto.osdItemWidth = proto.osdItemWidth || 200;
            //osd.style.backgroundColor = proto.osdBorderBgColor;
            var l = document.getElementById("osdItem" + osdCount)
            if (l == null) { 
                osdCount++; continue;
            }

            for (var i=0; i<container.Osds[x].items.length; i++) {
                l = document.getElementById("osdItem" + osdCount);
                l.Osd = container.Osds[x];
                proto = container.Osds[x].prototypeStyles || this.prototypeStyles || container.Osds[x];		
                l.style.width = proto.osdItemWidth + "px";
                l.style.height = proto.osdItemHeight + "px";
                if (i>0) l.style.top = (parseInt(document.getElementById("osdItem" + (osdCount -1)).style.top,10) + parseInt(document.getElementById("osdItem" + (osdCount -1)).style.height,10) + proto.osdItemBorder) + "px";
                l.style.fontSize = proto.fontSize;
                //l.style.backgroundColor = proto.osdItemBgColor;
                l.style.visibility = "inherit";
                l.saveColor = proto.osdItemBgColor;
                l.osdHiliteBgColor = proto.osdHiliteBgColor;
                l.action = container.Osds[x].actions[i];
                l.hilite = document.getElementById("osdItemHilite" + osdCount);
                l.focusItem = document.getElementById("focusItem" + x);
                l.focusItem.style.top = -30 + "px";
				
                l.mouseover = l.Osd.mouseovers[x];
                l.mouseout  = l.Osd.mouseouts[x];
                var childItem = document.getElementById("childOsd" + osdCount);
                if (childItem) {
                    l.childOsd = container.Osds[x].items[i].osdLayer;
                    childItem.style.left = (l.style.width -11) + "px";
                    childItem.style.top = ((l.style.height /2) -4) + "px";
                    childItem.style.width = (30 || 7) + "px";
                    childItem.style.clip = "rect(0px 7px 7px 3px)";
                    l.Osd.childOsds[l.Osd.childOsds.length] = l.childOsd;
                }
                var sep = document.getElementById("osdSeparator" + osdCount);
                if (sep) {
                    sep.style.clip = "rect(0 " + (proto.osdItemWidth - 3) + "px 1px 0)";
                    //sep.style.backgroundColor = proto.bgColor;
                    sep = document.getElementById("osdSeparatorLite" + osdCount);
                    sep.style.clip = "rect(1px " + (proto.osdItemWidth - 3) + "px 2px 0)";
                    //sep.style.backgroundColor = proto.osdLiteBgColor;
                    l.style.height = (proto.osdItemHeight/2) + "px" ;
                    l.isSeparator = true
                }
                osdCount++;
            }
            proto.osdHeight = (parseInt(l.style.top,10) + parseInt(l.style.height,10));
            var lite = document.getElementById("osdLite" + x);
            lite.style.height = (proto.osdHeight +2) + "px";
            lite.style.width = (proto.osdItemWidth + 2) + "px";
            //lite.style.backgroundColor = proto.osdLiteBgColor;
            var body = document.getElementById("osdFg" + x);
            body.style.height = (proto.osdHeight + 1) + "px";
            body.style.width = (proto.osdItemWidth + 1) + "px";
            //body.style.backgroundColor = proto.bgColor;

            container.Osds[x].osdLayer.style.width  = (proto.osdWidth || proto.osdItemWidth + (proto.osdBorder * 2) +2) + "px";
            container.Osds[x].osdLayer.style.height = (proto.osdHeight + (proto.osdBorder * 2) +2) + "px";
            if (osd.Osd.enableTrackerOsd) {
                osd.Osd.disableHide = true;
                setOsdTrackerOsd(osd.Osd);
            }
        }
        document.getElementById("osdContainer").style.backgroundColor = container.Osds[0].osdContainerBgColor;
        container.saveBgColor = container.bgColor;
    }	
    window.wroteOsd = true;
}

function onOsdItemOver(e, l, a) {
}
function onOsdItemOverNeverUsed(e, l, a) {
    l = l || this;
    a = a || window.ActiveOsdItem;
    if (document.layers) {
        if (a) {
            a.document.bgColor = a.saveColor;
            if (a.hilite) a.hilite.visibility = "hidden";
            if (a.childOsd) a.document.layers[1].document.images[0].src = a.icon;
        } else {
            a = new Object();
        }
        if (this.mouseover && this.id != a.id) {
            if (this.mouseover.length > 4) {
                var ext = this.mouseover.substring(this.mouseover.length-4);
                if (ext == ".gif" || ext == ".jpg") {
                    this.document.layers[1].document.images[0].src = this.mouseover;
                } else {
                    eval("" + this.mouseover);
                }
            }
        }
        if (l.hilite) {
            l.document.bgColor = l.osdHiliteBgColor;
            l.zIndex = 1;
            l.hilite.visibility = "inherit";
            l.hilite.zIndex = 2;
            l.document.layers[1].zIndex = 1;
            l.focusItem.zIndex = this.zIndex +2;
        }
        l.focusItem.top = this.top;
        l.Osd.hideChildOsd(l);
    } else if (document.all && l.style && l.Osd) {
        document.onmousedown=l.Osd.onOsdItemDown;
        if (a) {
            //a.style.backgroundColor = a.saveColor;
            if (a.hilite) a.hilite.style.visibility = "hidden";
        } else {
            a = new Object();
		}
        if (l.mouseover && l.id != a.id) {
            if (l.mouseover.length > 4) {
                var ext = l.mouseover.substring(l.mouseover.length-4);
                if (ext == ".gif" || ext == ".jpg") {
                    l.document.images[l.id + "Img"].src = l.mouseover;
                } else {
                    eval("" + l.mouseover);
                }
            }
        }
		if (l.isSeparator) return;
        //l.style.backgroundColor = l.osdHiliteBgColor;
        if (l.hilite) {
            //l.style.backgroundColor = l.osdHiliteBgColor;
            l.hilite.style.visibility = "inherit";
        }
        //l.focusItem.style.pixelTop = l.style.pixelTop;
        l.focusItem.style.zIndex = l.zIndex +1;
        l.zIndex = 1;
        l.Osd.hideChildOsd(l);
    } else if (document.getElementById){
        document.onmousedown=l.Osd.onOsdItemDown;	
        if (a) {
	        //a.style.backgroundColor = a.saveColor;
    	    if (a.hilite) a.hilite.style.visibility = "hidden";
        } else {
            a = new Object();
        }
        if (this.mouseover && this.id != a.id) {
            if (this.mouseover.length > 4) {
                var ext = this.mouseover.substring(this.mouseover.length-4);
                if (ext == ".gif" || ext == ".jpg") {
                    document.images[l.id + "Img"].src = this.mouseover;
                } else {
                    eval("" + this.mouseover);
                }
            }
        }
        if (l.hilite) {
	       // l.style.backgroundColor = l.osdHiliteBgColor;
            l.hilite.style.visibility = "inherit";
        }
        l.focusItem.style.top = l.style.top;
        l.focusItem.style.zIndex = l.zIndex +1;
        l.zIndex = 1;
        l.Osd.hideChildOsd(l);
	}		
    window.ActiveOsdItem = l;
}

function onOsdItemOut(e, l, a) {
    if (!document.all && !document.layers && e.currentTarget.nodeType == 1 && e.currentTarget.tagName == 'DIV')
      return true;
    l = l || this;
	a = a || window.ActiveOsdItem;
    if (l.id.indexOf("focusItem")) {
        if (a && l.top) {
            l.top = -30;
			if (a.mouseout && a.id != l.id) {
				if (a.mouseout.length > 4) {
					var ext = a.mouseout.substring(a.mouseout.length-4);
					if (ext == ".gif" || ext == ".jpg") {
						a.document.layers[1].document.images[0].src = a.mouseout;
					} else {
						eval("" + a.mouseout);
					}
				}
			}
        } else if (a && l.style) {
            document.onmousedown=null;
			if(window.event)
              window.event.cancelBubble=true;
			else
			  e.cancelBubble=true;
	        if (l.mouseout) {
				if (l.mouseout.length > 4) {
					var ext = l.mouseout.substring(l.mouseout.length-4);
					if (ext == ".gif" || ext == ".jpg") {
						l.document.images[l.id + "Img"].src = l.mouseout;
					} else {
						eval("" + l.mouseout);
					}
				}
			}
        }
    }
}

function onOsdItemAction(e, l) {
    l = window.ActiveOsdItem;
    if (!l) return;
//    if (!ActiveOsd.Osd.disableHide) hideActiveOsds(ActiveOsd.osdLayer);
    if (l.action) {
        eval("" + l.action);
    }
}

function showOsd(osd, x, y, child) {
    if (!window.wroteOsd) return;
    if (document.layers) {
        if (osd) {
            var l = osd.osdLayer || osd;
            if (typeof(osd) == "string") {
                for (var n=0; n < osdContainers.length; n++) {
                    l = osdContainers[n].Osds[osd];
                    for (var i=0; i<osdContainers[n].Osds.length; i++) {
                        if (osd == osdContainers[n].Osds[i].label) l = osdContainers[n].Osds[i].osdLayer;
                        if (l) break;
                    }
                }
				if (!l) return;
            }
            l.Osd.container.document.bgColor = null;
            l.left = 1;
            l.top = 1;
            hideActiveOsds(l);
            if (this.visibility) l = this;
            window.ActiveOsd = l;
            window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
            setTimeout('if(window.ActiveOsd)window.ActiveOsd.Osd.setMouseTrackerOsd();', 300);
        } else {
            var l = child;
        }
        if (!l) return;
        for (var i=0; i<l.layers.length; i++) {                
            if (!l.layers[i].isHilite) 
                l.layers[i].visibility = "inherit";
            if (l.layers[i].document.layers.length > 0) 
                showOsd(null, "relative", "relative", l.layers[i]);
        }
        if (l.parentLayer) {
            if (x != "relative") 
                l.parentLayer.left = x || window.pageX || 0;
            if (l.parentLayer.left + l.clip.width > window.innerWidth) 
                l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
            if (y != "relative") 
                l.parentLayer.top = y || window.pageY || 0;
            if (l.parentLayer.isContainer) {
                l.Osd.xOffset = window.pageXOffset;
                l.Osd.yOffset = window.pageYOffset;
                l.parentLayer.clip.width = window.ActiveOsd.clip.width +2;
                l.parentLayer.clip.height = window.ActiveOsd.clip.height +2;
                if (l.parentLayer.osdContainerBgColor) l.parentLayer.document.bgColor = l.parentLayer.osdContainerBgColor;
            }
        }
        l.visibility = "inherit";
        if (l.Osd) l.Osd.container.visibility = "inherit";
    } else if (document.all) {
        var l = osd.osdLayer || osd;
        hideActiveOsds(l);
        if (typeof(osd) == "string") {
            l = document.all[osd];
            for (var n=0; n < osdContainers.length; n++) {
                l = osdContainers[n].Osds[osd];
                for (var i=0; i<osdContainers[n].Osds.length; i++) {
                    if (osd == osdContainers[n].Osds[i].label) l = osdContainers[n].Osds[i].osdLayer;
                    if (l) break;
                }
            }
        }
        window.ActiveOsd = l;
        l.style.visibility = "inherit";
        if (x != "relative") 
            l.style.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
        if (y != "relative") 
            l.style.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
        l.Osd.xOffset = document.body.scrollLeft;
        l.Osd.yOffset = document.body.scrollTop;
    } else if (document.getElementById) {
        var l = osd.osdLayer || osd;
        hideActiveOsds(l);
        if (typeof(osd) == "string") {
            l = document.getElementById(osd);
            for (var n=0; n < osdContainers.length; n++) {
                l = osdContainers[n].Osds[osd];
                for (var i=0; i<osdContainers[n].Osds.length; i++) {
                    if (osd == osdContainers[n].Osds[i].label) l = osdContainers[n].Osds[i].osdLayer;
                    if (l) break;
                }
            }
        }
        window.ActiveOsd = l;
        l.style.visibility = "inherit";
        if (x != "relative") 
            l.style.left = (x || (window.pageX) || 0) + "px";
        if (y != "relative") 
            l.style.top = (y || (window.pageY) || 0) + "px";
        l.Osd.xOffset = document.body.scrollLeft;
        l.Osd.yOffset = document.body.scrollTop;
    }
	
    if (osd) {
        window.activeOsds[window.activeOsds.length] = l;
    }
}

function hideOsd(e) {
    if (!document.all && e.currentTarget && e.currentTarget.tagName && e.currentTarget.tagName == 'DIV')
      return true;
	  
    var l = e || window.ActiveOsd;
    if (!l) return true;
    if (l.osdLayer) {
        l = l.osdLayer;
    } else if (this.visibility) {
        l = this;
    }
    if (l.osdLayer) {
        l = l.osdLayer;
    }
    var a = window.ActiveOsdItem;
    document.saveMousemove = document.onmousemove;
    document.onmousemove = mouseTrackerOsd;
    if (a && document.layers) {
        a.document.bgColor = a.saveColor;
        a.focusItem.top = -30;
        if (a.hilite) a.hilite.visibility = "hidden";
        if (a.childOsd) a.document.layers[1].document.images[0].src = a.icon;
        if (mDrag.oldX <= e.pageX+3 && mDrag.oldX >= e.pageX-3 && mDrag.oldY <= e.pageY+3 && mDrag.oldY >= e.pageY-3) {
            if (a.action && window.ActiveOsd) setTimeout('window.ActiveOsd.Osd.onOsdItemAction();', 2);
        } else if (document.saveMousemove == mDrag.doOsdDrag) {
            if (window.ActiveOsd) return true;
        }
    } else if (window.ActiveOsd && document.all) {
        document.onmousedown=null;
        if (a) {
            //a.style.backgroundColor = a.saveColor;
            if (a.hilite) a.hilite.style.visibility = "hidden";
        }
        if (document.saveMousemove == mDrag.doOsdDrag) {
            return true;
        }
    } else if (window.ActiveOsd && document.getElementById) {
        document.onmousedown=null;
        if (a) {
           // a.style.backgroundColor = a.saveColor;
            if (a.hilite) a.hilite.style.visibility = "hidden";
        }
        if (document.saveMousemove == mDrag.doOsdDrag) {
            return true;
        }
	}		
    if (window.ActiveOsd) {
        if (window.ActiveOsd.Osd) {
            if (window.ActiveOsd.Osd.disableHide) return true;
            e = window.event || e;
            if (!window.ActiveOsd.Osd.enableHideOnMouseOut && e.type == "mouseout") return true;
        }
    }
    hideActiveOsds(l);
    return true;
}

function hideChildOsd(osdLayer) {
    var l = osdLayer || this;
    for (var i=0; i < l.Osd.childOsds.length; i++) {
        if (document.getElementById || document.all) {
            l.Osd.childOsds[i].style.visibility = "hidden";
        } else if (document.layers) {
            l.Osd.childOsds[i].visibility = "hidden";
        }
        l.Osd.childOsds[i].Osd.hideChildOsd(l.Osd.childOsds[i]);
    }
    if (l.childOsd) {
        if (document.layers) {
            l.Osd.container.document.bgColor = null;
            l.Osd.showOsd(null,null,null,l.childOsd.layers[0]);
            l.childOsd.zIndex = l.parentLayer.zIndex +1;
            l.childOsd.top = l.top + l.parentLayer.top + l.Osd.osdLayer.top;
            if (l.childOsd.left + l.childOsd.clip.width > window.innerWidth) {
                l.childOsd.left = l.parentLayer.left - l.childOsd.clip.width + l.Osd.osdLayer.top + 15;
                l.Osd.container.clip.left -= l.childOsd.clip.width;
            } else if (l.Osd.childOsdDirection == "left") {
                l.childOsd.left = l.parentLayer.left - l.parentLayer.clip.width;
                l.Osd.container.clip.left -= l.childOsd.clip.width;
            } else {
                l.childOsd.left = l.parentLayer.left + l.parentLayer.clip.width  + l.Osd.osdLayer.left -5;
            }
            l.Osd.container.clip.width += l.childOsd.clip.width +100;
            l.Osd.container.clip.height += l.childOsd.clip.height;
            l.document.layers[1].zIndex = 0;
            l.document.layers[1].document.images[0].src = l.iconHilite;
            l.childOsd.visibility = "inherit";
        } else if (document.all) {
            l.childOsd.style.zIndex = l.Osd.osdLayer.style.zIndex +1;
            l.childOsd.style.pixelTop = l.style.pixelTop + l.Osd.osdLayer.style.pixelTop;
            if (l.childOsd.style.pixelLeft + l.childOsd.style.pixelWidth > document.width) {
                l.childOsd.style.pixelLeft = l.childOsd.style.pixelWidth + l.Osd.osdLayer.style.pixelTop + 15;
            } else if (l.Osd.childOsdDirection == "left") {
                //l.childOsd.style.pixelLeft = l.parentLayer.left - l.parentLayer.clip.width;
            } else {
                l.childOsd.style.pixelLeft = l.Osd.osdLayer.style.pixelWidth + l.Osd.osdLayer.style.pixelLeft -5;
            }
            l.childOsd.style.visibility = "inherit";
        } else if (document.getElementById) {
            l.childOsd.style.zIndex = l.Osd.osdLayer.style.zIndex +1;
            l.childOsd.style.top = (parseInt(l.style.top,10) + parseInt(l.Osd.osdLayer.style.top, 10)) + "px";
            if ( parseInt(l.childOsd.style.left) + parseInt(l.childOsd.style.width) > document.width) {
                l.childOsd.style.left = (parseInt(l.childOsd.style.width,10) + parseInt(l.Osd.osdLayer.style.top,10) + 15) + "px";
            } else if (l.Osd.childOsdDirection == "left") {
                //l.childOsd.style.pixelLeft = l.parentLayer.left - l.parentLayer.clip.width;
            } else {
                l.childOsd.style.left = (parseInt(l.Osd.osdLayer.style.width,10) + parseInt(l.Osd.osdLayer.style.left,10) -5) + "px";
            }
            l.childOsd.style.visibility = "inherit";
        }		
		
        if (!l.childOsd.disableHide) 
            window.activeOsds[window.activeOsds.length] = l.childOsd;
    }
}

function hideActiveOsds(l) {
    if (!window.activeOsds) return;
    for (var i=0; i < window.activeOsds.length; i++) {
    if (!activeOsds[i]) return;
   	    if (document.layers && activeOsds[i].visibility && activeOsds[i].Osd) {
            activeOsds[i].visibility = "hidden";
            activeOsds[i].Osd.container.visibility = "hidden";
            activeOsds[i].Osd.container.clip.left = 0;
        } else if (activeOsds[i].style) {
            activeOsds[i].style.visibility = "hidden";
        }
    }
    document.onmousemove = mouseTrackerOsd;
    window.activeOsds.length = 0;
}

function mouseTrackerOsd(e) {
    e = e || window.Event || window.event;
    window.pageX = parseInt(e.pageX,10) || e.clientX;
    window.pageY = parseInt(e.pageY,10) || e.clientY;
}

function setMouseTrackerOsd() {
    if (document.captureEvents) {
        document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    }
    document.onmousemove = this.mouseTrackerOsd;
    document.onmouseup = this.hideOsd;
}

function setOsdTrackerOsd(osd) {
    if (!window.osdTrackerOsds) window.osdTrackerOsds = new Array();
    osdTrackerOsds[osdTrackerOsds.length] = osd;
    window.osdTrackerOsdID = setInterval('osdTrackerOsd()',10);
}

function osdTrackerOsd() {
    for (var i=0; i < osdTrackerOsds.length; i++) {
        if (!isNaN(osdTrackerOsds[i].xOffset) && document.layers) {
            var off = parseInt((osdTrackerOsds[i].xOffset - window.pageXOffset) / 10);
            if (isNaN(off)) off = 0;
            if (off < 0) {
                osdTrackerOsds[i].container.left += -off;
                osdTrackerOsds[i].xOffset += -off;
            } else if (off > 0) {
                osdTrackerOsds[i].container.left += -off;
                osdTrackerOsds[i].xOffset += -off;
            }
        }
        if (!isNaN(osdTrackerOsds[i].yOffset) && document.layers) {
            var off = parseInt((osdTrackerOsds[i].yOffset - window.pageYOffset) / 10);
            if (isNaN(off)) off = 0;
            if (off < 0) {
                osdTrackerOsds[i].container.top += -off;
                osdTrackerOsds[i].yOffset += -off;
            } else if (off > 0) {
                osdTrackerOsds[i].container.top += -off;
                osdTrackerOsds[i].yOffset += -off;
            }
        }
        if (!isNaN(osdTrackerOsds[i].xOffset) && document.body) {
            var off = parseInt((osdTrackerOsds[i].xOffset - document.body.scrollLeft) / 10);
            if (isNaN(off)) off = 0;
            if (off < 0) {
                osdTrackerOsds[i].osdLayer.style.pixelLeft += -off;
                osdTrackerOsds[i].xOffset += -off;
            } else if (off > 0) {
                osdTrackerOsds[i].osdLayer.style.pixelLeft += -off;
                osdTrackerOsds[i].xOffset += -off;
            }
        }
        if (!isNaN(osdTrackerOsds[i].yOffset) && document.body) {
            var off = parseInt((osdTrackerOsds[i].yOffset - document.body.scrollTop) / 10);
            if (isNaN(off)) off = 0;
            if (off < 0) {
                osdTrackerOsds[i].osdLayer.style.pixelTop += -off;
                osdTrackerOsds[i].yOffset += -off;
            } else if (off > 0) {
                osdTrackerOsds[i].osdLayer.style.pixelTop += -off;
                osdTrackerOsds[i].yOffset += -off;
            }
        }
    }
}

function onOsdItemDown(e, l) {
    l = l || window.ActiveOsdItem || this;
    if (!l.Osd) {
    } else {
        if (document.layers) {
            mDrag.dragLayer = l.Osd.container;
            mDrag.startOsdDrag(e);
            document.captureEvents(Event.MOUSEMOVE);			
        } else if (document.all) {
            mDrag.dragLayer = l.Osd.container.style;
            mDrag.startOsdDrag(e);
            window.event.cancelBubble=true;
        } else if (document.getElementById) {
            mDrag.dragLayer = l.Osd.container.style;
            mDrag.startOsdDrag(e);
            document.captureEvents(Event.MOUSEMOVE);			
        }
        var x = !document.all? e.pageX : window.event.clientX;
        var y = !document.all? e.pageY : window.event.clientY;
    
    }
}

function startOsdDrag(e) {
    if (document.layers) {
        if (e.which > 1) {
            if (window.ActiveOsd) ActiveOsd.Osd.container.visibility = "hidden";
            window.ActiveOsd = null;
            return true;
        }
        document.captureEvents(Event.MOUSEMOVE);
        var x = e.pageX;
        var y = e.pageY;
    } else if (document.all) {
        var x = window.event.clientX;
        var y = window.event.clientY;
    } else if (document.getElementById) {
        if (e.which > 1) {
            if (window.ActiveOsd) ActiveOsd.Osd.container.visibility = "hidden";
            window.ActiveOsd = null;
            return true;
        }
        document.captureEvents(Event.MOUSEMOVE);
        var x = e.pageX;
        var y = e.pageY;
    }
	
    mDrag.offX = x;
    mDrag.offY = y;
    mDrag.oldX = x;
    mDrag.oldY = y;
    if (!ActiveOsd.Osd.disableDrag) document.onmousemove = mDrag.doOsdDrag;
    return false;
}

function doOsdDrag(e) {
    if (document.layers) {
        mDrag.dragLayer.moveBy(e.pageX-mDrag.offX,e.pageY-mDrag.offY);
        mDrag.offX = e.pageX;
        mDrag.offY = e.pageY;
    } else if(document.all) {
        mDrag.dragLayer.pixelLeft = window.event.offsetX;
        mDrag.dragLayer.pixelTop  = window.event.offsetY;
        return false; //for IE
    } else if (document.getElementById){
//    alert(mDrag.dragLayer.left)
        mDrag.dragLayer.left = e.pageX + "px";
        mDrag.dragLayer.top  = e.pageY  + "px";	
	}

}
