var _TimeOut = null;
var _CI = null;
var _ItemList = new Array();
var _arrowGif = '<img align="right" border="0" alt="" width="7" height="7" vspace="3" src="../img/_arrow.gif">';
var _delay = 200;
var _count = 0;

function ActionItem(item, P, isMain, idSub, O)
{
	_ItemList[_ItemList.length] = item;
	var index = _ItemList.length - 1;
	idSub =(!idSub) ? 'null' :('\'' + idSub + '\'');
	O = '\'' + O + '\'';
	P = '\'' + P + '\'';
	return ' onmouseover="Over(this,' + P + ',' + isMain + ',' + idSub + ',' + O + ',' + index + ')" onmouseout="Out(this,' + _delay + ')" ';
}

function Draw(menu, O, P)
{
	var P =(P != null) ? P : '';
	var str = '<div class="'+ P +'M">';
	var strSub = '';
	if(!O) O = 'hbr';
	var OStr = String(O);
	var OSub = 'v' + OStr.substr(1, 2);
	var item, idSub, hasChild;

	for(var i = 0; i < menu.length; ++i)
	{
		item = menu[i];
		if(!item) continue;
		if(!item) continue;
		if (document.URL.match("/"+item[2])){
		str += '<a href="'+ item[2] +'" title="'+ item[4] +'" class="'+ P +'lvl1a"';
		}
		else
		{
		str += '<a href="'+ item[2] +'" title="'+ item[4] +'" class="'+ P +'lvl1"';
		}
		hasChild =(item.length > 5);
		idSub = hasChild ? '_' +(++_count) : null;
		str += ActionItem(item, P, 1, idSub, O ) + '>';
		str += hasChild ? _arrowGif : "";
		str += item[1];
		str += '</a>';
		if(hasChild) strSub += DrawSM(item, P, idSub, OSub );
	}
	document.write( str + strSub + '</div>' );
}

function DrawSM(sm, P, id, O )
{
	var str = '<div class="SM" id="' + id + '">';
	var strSub = '';
	var item, idSub, hasChild;

	for(var i = 5; i < sm.length; ++i)
	{
		item = sm[i];
		if(!item) continue;
		hasChild =(item.length > 5);
		idSub = hasChild ? '_' + (++_count) : null;
		str += '<a href="'+ item[1] +'" class="'+ P +'lvl2"' + ActionItem(item, P, 0, idSub, O ) + '>';
		if(hasChild)
		{
			str += _arrowGif;
			strSub += DrawSM(item, P, idSub, O);
		}
		str += item[1];
		str += '</a>';
	}
	str += '</div>' + strSub;
	return str;
}

function Over(o, P, isMain, idSub, O, index)
{
	clearTimeout(_TimeOut);

	if(!o.Prefix)
	{
		o.Prefix = P;
		o.IsMain = isMain;
	}

	var thisM = GetThisM(o, P);
	if(!thisM.Items) thisM.Items = new Array();
	for(var i = 0; i < thisM.Items.length; ++i)
	{
		if(thisM.Items[i] == o) break;
	}
	if(i == thisM.Items.length)
	{
		thisM.Items[i] = o;
	}

	if(_CI)
	{
		if(_CI == thisM) return;

		var thatPrefix = _CI.Prefix;
		var thatM = GetThisM(_CI, thatPrefix);
		if(thatM != thisM.PM)
		{
			if(thatM.id != idSub) HideM(thatM, thisM, thatPrefix);
		}
	}

	_CI = o;

	var item = _ItemList[index];

	if(idSub)
	{
		var sm = document.getElementById(idSub);
		ShowSM(o, P, sm, O);
	}
}

function Out(o, delayTime)
{
	if(!delayTime) delayTime = _delay;
	_TimeOut = window.setTimeout('HideMTime()', delayTime);
}


function MoveSM(o, sm, O)
{
	var mode = String(O);
	if(mode.charAt(0) == 'h')
	{
		if(mode.charAt(1) == 'b') sm.style.top =(GetY(o) + o.offsetHeight) + 'px';
		else sm.style.top =(GetY(o) - sm.offsetHeight) + 'px';
		if(mode.charAt(2) == 'r') sm.style.left =(GetX(o)) + 'px';
		else sm.style.left =(GetX(o) + o.offsetWidth - sm.offsetWidth) + 'px';
	}
	else
	{
		if(mode.charAt(2) == 'r') sm.style.left =(GetX(o) + o.offsetWidth) + 'px';
		else sm.style.left =(GetX(o) - sm.offsetWidth) + 'px';
		if(mode.charAt(1) == 'b')sm.style.top =(GetY(o)) + 'px';
		else sm.style.top =(GetY(o) + o.offsetHeight - sm.offsetHeight) + 'px';
	}
}

function ShowSM(o, P, sm, O)
{
	if(!sm.PM)
	{
		var thisM = GetThisM(o, P);
		sm.PM = thisM;
		if(!thisM.SM) { thisM.SM = new Array(); }
		thisM.SM[thisM.SM.length] = sm;
	}

	MoveSM(o, sm, O);
	sm.style.visibility = 'visible';

	if(document.all)
	{
		sm.Overlap = new Array();
		// IFRAME?, OBJECT?
		HideControl("SELECT", sm);
	}
}

function HideMTime()
{
	if(_CI)
	{
		var P = _CI.Prefix;
		HideM(GetThisM(_CI, P), null, P);
	}
}

function HideM(thisM, currentM, P)
{
	var str = P + 'SM';
	if(thisM.SM)
	{
		for(var i = 0; i < thisM.SM.length; ++i)
		{
			HideSM(thisM.SM[i], P);
		}
	}

	while(thisM && thisM != currentM)
	{
		if(thisM.className == str)
		{
			thisM.style.visibility = 'hidden';
			ShowControl(thisM);
		}
		else break;
		thisM = GetThisM(thisM.PM, P);
	}
}

function HideSM(thisM, P)
{
	if(thisM.style.visibility == 'hidden') return;
	if(thisM.SM)
	{
		for(var i = 0; i < thisM.SM.length; ++i)
		{
			HideSM(thisM.SM[i], P);
		}
	}
	thisM.style.visibility = 'hidden';
	ShowControl(thisM);
}

function HideControl(tagName, sm)
{
	var x = GetX(sm);
	var y = GetY(sm);
	var w = sm.offsetWidth;
	var h = sm.offsetHeight;

	for(var i = 0; i < document.all.tags(tagName).length; ++i)
	{
		var o = document.all.tags(tagName)[i];
		if(!o || !o.offsetParent) continue;

		var ox = GetX(o);
		var oy = GetY(o);
		var ow = o.offsetWidth;
		var oh = o.offsetHeight;

		if(ox >(x + w) ||(ox + ow) < x) continue;
		if(oy >(y + h) ||(oy + oh) < y) continue;
		sm.Overlap[sm.Overlap.length] = o;
		o.style.visibility = "hidden";
	}
}

function ShowControl(sm)
{
	if(sm.Overlap)
	{
		var i;
		for(i = 0; i < sm.Overlap.length; ++i)
			sm.Overlap[i].style.visibility = "";
	}
	sm.Overlap = null;
}

function GetThisM(o, P)
{
	var str1 = P + 'SM';
	var str2 = P + 'M';
	while(o)
	{
		if(o.className == str1 || o.className == str2)
			return o;
		o = o.parentNode;
	}
	return null;
}

function GetX(o)
{
	var x = 0;
	do
	{
		x += o.offsetLeft;
		o = o.offsetParent;
	}
	while(o);
	return x;
}

function GetY(o)
{
	var y = 0;
	do
	{
		y += o.offsetTop;
		o = o.offsetParent;
	}
	while(o);
	return y-114;
}