var d = document;
var doDHTML = 0;
var toolbarButton;

if (d.layers || d.all)
{
    var vers = navigator.appVersion.split ("MSIE ");
    vers = vers[vers.length - 1];
    if (navigator.appVersion.indexOf ("MSIE") < 0 ||  vers.indexOf ("Mac") < 0 || parseInt (vers) >= 5)
	{
		doDHTML = 1;
		initFlyLyr ();
		initToShow ();
		initDelay ();
    }
}

function makeLayer (id, imgPath, title)
{
    if (! doDHTML)
		return;

    var a = arguments;
    var numsp = new Array;
    numsp.max = new Array;
    var pos = 0;
    numsp.max[0] = 0;
    for (var j = 2; j < a.length; ++j)
	{
		numsp[j] = a[j].length;
		if (numsp[j])
		{
	    	a[j] = a[j].replace (/^ +/, '');
	    	numsp[j] -= a[j].length;
	    	numsp.max[pos] = Math.max (numsp[j], numsp.max[pos]);
		}
		else
	    numsp.max[++pos] = 0;
    }
    
	var fd = FlyLyr.defs;
    d.write ("<div id='l_" + id + "' class='flyout'>" + "<table class='flyoutMenu' cellpadding='0' cellspacing='0' border='0'>");
    
	if (title)
	{
		var titleargs = "align='center'";
		if (fd.titlebackground)
	    	titleargs += " class='toolbar'";
	
		d.write ("<tr><td class='borderFlyout' height='1' rowspan='3'><img width='1' height='1' src='" + imgPath + "spacer.gif'></td><td height='1'><img width='80' height='1' src='" + imgPath + "spacer.gif'></td><td class='borderFlyout' height='1' rowspan='3'><img width='1' height='1' src='" + imgPath + "spacer.gif'></td><\/tr>");
	}
    
	var divstart = "<tr><td><br><table cellpadding='1' cellspacing='0' " + "border='0'>\n";
    d.write (divstart);
	pos = 0;
    
	for (j = 3; j < a.length; ++j)
	{
		if (! a[j])
		{
	    	d.write ("<\/table><\/td><\/tr>" + divstart);
	    	++pos;
	    	continue;
		}
		var args = null;
		var i = numsp[j];
		if (i < numsp.max[pos])
	    	args = "colspan=" + (numsp.max[pos] - i + 1);
	
		d.write ("<tr><td height='1' colspan='2' background='" + imgPath + "dashH.gif'><\/td><\/tr>");
		d.write ("<tr>");
		d.write ("<td class='smallText' onMouseOver='changeMenuClassOn(this)'; onMouseOut='changeMenuClassOff(this)';>&#160;");
	
		while (i-- > 0)
			d.write ("&#160;&#160;&#160;");

    	d.write ("<img src='" + imgPath + "arrow.gif'>&#160;");
		d.write (buildCell (a[j], fd.useclass, args) + "<\/td><\/tr>\n");
    }
	
	d.write ("<tr><td height='1' colspan='2' background='" + imgPath + "dashH.gif'><\/td><\/tr>");
    d.write ("<\/table><br><\/td><\/tr>");
    d.write ("<tr><td class='borderFlyout' height='1'><img width='80' height='1' src='" + imgPath + "spacer.gif'></td><\/tr>");
    d.write ("<\/table><\/div>\n");
    new FlyLyr (id);
}

function changeMenuClassOn(object)
{
 		 object.className = 'menuItemOn';
}

function changeMenuClassOff(object)
{
 		 object.className = 'smallText';
}

function buildCell (str, fc, args) {
	var retstr = "";
    var eqpos = str.indexOf ("=");
    var atpos = str.indexOf ("@");
    if (eqpos > 0) {
	if (atpos > eqpos)
	    retstr += "<a href='" + str.substr (eqpos + 1, atpos - eqpos - 1) + "'" + " target='" + str.substr (atpos + 1) + "'";
	else
	    retstr += "<a href='" + str.substr (eqpos + 1) + "'";
	retstr += "><font class='smallText'>" + str.substr (0, eqpos) +
			"&#160;&#160;&#160;<\/font><\/a>";
    } else
	retstr += " class='smallText'>" + str;
    return retstr;
}

function positionLayerNS () {
    var img = this.image;
    var ypos = img.y - 2;
    var moveup = ypos + this.lyr.clip.bottom + FlyLyr.unmacOffset -	window.pageYOffset - window.innerHeight;
    if (moveup > 0)
    	ypos -= moveup;
    var xpos = img.x + img.width + 2;
    if (this.positionleft)
	xpos = img.x - this.lyr.clip.right - 2;
    this.lyr.moveTo (xpos-13, ypos+5);
}

function positionLayer ()
{
    var img = this.image;
    var xpos = img.offsetWidth;
    var ypos = -2;
    if (this.positionleft)
    	xpos = -this.lyr.offsetWidth - 2;
    if (FlyLyr.usepos['startX'])
	xpos += FlyLyr.usepos['startX'];
    if (FlyLyr.usepos['startY'])
	ypos += FlyLyr.usepos['startY'];
    for (; img && img.parentElement; img = img.parentElement)
	if (FlyLyr.usepos[img.tagName])
	{
	    xpos += img.offsetLeft;
	    ypos += img.offsetTop;
	}
    var moveup = ypos + this.lyr.offsetHeight -   d.body.scrollTop - d.body.clientHeight;
    if (moveup > 0)
	ypos -= moveup;
    this.lyr.style.pixelLeft = xpos-2;
    this.lyr.style.pixelTop = ypos + 8;
    if (this.tbl)
	this.lyr.style.clip = 'rect ( 0px ' + this.tbl.offsetWidth + 'px ' + this.tbl.offsetHeight + 'px 0px )';
}

function FlyLyr(id)
{
    this.lyr = findObj ('l_' + id);

    if (! d.all) {
        this.lyr.captureEvents (Event.MOUSEOUT | Event.MOUSEOVER);
	this.lyr.bgColor = FlyLyr.defs.background;
    }
    this.lyr.onmouseover = function () {
	FlyLyr.showing.stopdelay ()
	ToShow.stopdelay ();
    };
    this.lyr.onmouseout = function () { mOut () };
    this.id = id;
    if (this.lyr.children && FlyLyr.unmacOffset)
	this.tbl = this.lyr.children[0];
    FlyLyr.lyrs[id] = this;
    for (var a in FlyLyr.defs)
	this[a] = FlyLyr.defs[a];
}

function flyDefs (defs) {
    if (! defs)
	return;
    for (var d in defs)
	FlyLyr.defs[d] = defs[d];
}

function initFlyLyr ()
{
    FlyLyr.prototype.doHide = function () {
		this.stopdelay ();
		this.realHide ();
		//this.image.src = this.outimg;
		FlyLyr.showing = null;
    };
    FlyLyr.prototype.doShow = function () {
	if (! this.image && ! (this.image = findObj (this.id)))
	    return;
	this.position ();
	this.realShow ();
	//this.image.src = this.overimg;
	FlyLyr.showing = this;
    };
    FlyLyr.prototype.delayCallback = function () {
	if (this == FlyLyr.showing)
	    this.doHide ();
    };
    FlyLyr.prototype.setdelay = function () {
	this.delay = new Delay (this.timeout, this);
    };
    FlyLyr.prototype.stopdelay = function () {
	if (this.delay)
	    this.delay.stop ();
	return this.delay;
    };

    FlyLyr.lyrs = new Object ();
    FlyLyr.defs = {
	background: '#ffffff',
	titlebackground: '#333399',
	border: '#333399',
	useclass: 'navlink',
	titleclass: 'barlink',
	overimg: '7/images/spacer.gif',
	outimg: '7/images/spacer.gif',
	pause: 250,
	timeout: 1000,
	positionleft: 0
    }
    FlyLyr.unmacOffset = navigator.platform.indexOf ("Mac") != -1 ? 0 : 16;

    if (d.all) {
    	FlyLyr.prototype.realHide = function () {
    	    this.lyr.style.visibility = 'hidden';
			document.getElementById(toolbarButton).className='toolbarButtons';
	};
    	FlyLyr.prototype.realShow = function () {
    	    this.lyr.style.visibility = 'visible';
	};
    	FlyLyr.prototype.position = positionLayer;
	var vers = navigator.appVersion.split ("MSIE ");
	vers = vers[vers.length - 1];
	FlyLyr.usepos = {
	    'BODY': 1,
	    'IMG': 1,
	    'TABLE': 1,
	    'TD': 1
	};
	if (parseInt (vers) < 5)
	    FlyLyr.usepos["TR"] = 1;
	else if (! FlyLyr.unmacOffset) {
	    FlyLyr.usepos["startX"] = 8;
	    FlyLyr.usepos["startY"] = 12;
	}
    } else {
    	FlyLyr.prototype.realHide = function () {
    	    this.lyr.visibility = 'hide';
	};
    	FlyLyr.prototype.realShow = function () {
    	    this.lyr.visibility = 'show';
	};
    	FlyLyr.prototype.position = positionLayerNS;
    }
}

function ToShow (lyr)
{
    if (! lyr || lyr == FlyLyr.showing)
	   return;

    this.lyr = lyr;
    ToShow.stopdelay ();
    ToShow.queued = this;
    this.delay = new Delay(FlyLyr.defs.pause, this);
}

function initToShow () {
    ToShow.stopdelay = function () {
	var q = ToShow.queued;
	if (q) {
	    q.delay.stop ();
	    ToShow.queued = null;
	}
	return q;
    };
    ToShow.prototype.delayCallback = function () {
	ToShow.queued = null;
	if (FlyLyr.showing)
	    FlyLyr.showing.doHide ();
	if (this.lyr)
	    this.lyr.doShow ();
    };
}

function Delay (delay, obj)
{
    this.obj = obj;
    var uid = ++Delay.nuid;
    this.timeoutid = setTimeout ('Delay.dispatch (' + uid + ')', delay);
    this.uid = uid;
    Delay.disparr[uid] = this;
}

function initDelay () {
    Delay.prototype.stop = function () {
	clearTimeout (this.timerid);
	delete Delay.disparr[this.uid];
    };
    Delay.dispatch = function (uid) {
	var item = Delay.disparr[uid];
	if (! item)
	    return;
	item.obj.delayCallback ();
	item.stop ();
    };
    Delay.nuid = 0;
    Delay.disparr = new Object;
}

function findObj (n, od) { // was MM_findObj v3.0 from Macromedia Dreamweaver
    var p, i, x;
    if (! od)
	od = d;
    if ((p = n.indexOf ("?")) > 0 && parent.frames.length) {
	od = parent.frames[n.substring (p + 1)].document;
	n = n.substring (0, p);
    }
    if (! (x = od[n]) && d.all)
	x = od.all[n];
    for (i = 0; ! x && i < od.forms.length; i++)
	x = od.forms[i][n];
    for (i = 0; ! x && od.layers && i < od.layers.length; i++)
	x = findObj (n, od.layers[i].document);
    return x;
}

function mIn (id)
{
    if (! doDHTML)
    	return;
	
	document.getElementById(toolbarButton).className='toolbarButtons';

    var lyr = FlyLyr.lyrs[id];

    if (! lyr)
		return;

    if (lyr == FlyLyr.showing)
		lyr.stopdelay ();
    else
		new ToShow (lyr);
}

function mOut (toolbarButtonName)
{
    if (! doDHTML)
		return;

	toolbarButton = toolbarButtonName + 'ToolbarButton';

	var lyr = FlyLyr.showing;
    if (! ToShow.stopdelay () && lyr)
	lyr.setdelay ();
}
