/*
CMS Menu v1.0
(C)2003 Aptus s.c.
*/

cm_borderTable_color='';
cm_bgcolor='#549ef2';
cm_bgcolor_over='#7ebaff';

cm_style_menu='background-color:'+cm_borderTable_color+';';
cm_style_hdr='';
cm_style_item='height:22px; width:130px; font-family:Tahoma, Arial, Verdana; font-size:11px; color:#fff; background-color:'+cm_bgcolor+'; padding:2px 10px 2px 10px;';
cm_style_link='font-family:Tahoma, Arial, Verdana; font-size:13px; color:#31383E; text-decoration:none;';
cm_link_over='this.offsetParent.style.backgroundColor=\'#FFFFFF\';';
cm_link_out='this.offsetParent.style.backgroundColor=\'#000000\';';

cm_shiftx=0;
cm_shifty=0;

cm_list=Array();
cm_timer=null;
cm_inited=false;

function cm_init()
{
	var i;
	var d='';
	for(i=0; i<cm.length; i++) {
		d+='<div id="cm'+i+'" style="z-index:3;position:absolute;left:0px;top:0px;visibility:hidden;" onMouseOver="cm_over();" onMouseOut="cm_out();">';
		d+=cm_menustart();
		var j;
		for(j=0; j<cm[i].length; j++)
			d+=cm_menuitem(cm[i][j],i);
		d+=cm_menuend();
		d+='</div>';
	}
	document.getElementById('cm').innerHTML=d;
	cm_inited=true;
}

function cm_menu(id,t)
{
	if(!cm_inited)
		return;
	cm_hideall();
	var e=document.getElementById('cm'+id).style;
	var x=0;
	var y=0;
	var tmp=t;
	while(tmp!=null) {
		x+=tmp.offsetLeft;
		y+=tmp.offsetTop;
		tmp=tmp.offsetParent;
	}
	e.left=x;
	e.top=y+t.offsetHeight;
	e.visibility='visible';
	cm_list=Array();
	cm_list[0]=id;
}

function cm_hidesub(m)
{
	var i;
	for(i=0; i<cm_list.length; i++)
		if(cm_list[i]==m) {
			var j=i;
			for(i++; i<cm_list.length; i++)
				document.getElementById('cm'+cm_list[i]).style.visibility='hidden';
			cm_list=cm_list.slice(0,j+1);
			break;
		}
}

function cm_submenu(id,t,m)
{
	var i;
	for(i=0; i<cm_list.length; i++)
		if(cm_list[i]==m) {
			var j=i;
			for(i++; i<cm_list.length; i++)
				document.getElementById('cm'+cm_list[i]).style.visibility='hidden';
			cm_list=cm_list.slice(0,j+1);
			break;
		}
	var e1=document.getElementById('cm'+id);
	var e2=document.getElementById('cm'+m);
	if(t.offsetLeft+t.offsetWidth+e2.offsetLeft+cm_shiftx+e1.offsetWidth<document.body.clientWidth)
		e1.style.left=t.offsetLeft+t.offsetWidth+e2.offsetLeft+cm_shiftx;
	else
		e1.style.left=t.offsetLeft+e2.offsetLeft-e1.offsetWidth-cm_shiftx-1;
	e1.style.top=t.offsetTop+e2.offsetTop+cm_shifty;
	e1.style.visibility='visible';
	cm_list[cm_list.length]=id;
}

function cm_over()
{
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=null;
}

function cm_out()
{
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=setTimeout('cm_hideall();',500);
}

function cm_hideall()
{
	if(!cm_inited)
		return;
	if(cm_timer!=null)
		clearTimeout(cm_timer);
	cm_timer=null;
	var i;
	for(i=0; i<cm.length; i++)
		document.getElementById('cm'+i).style.visibility='hidden';
	cm_list=Array();
}

function cm_menustart()
{
	return '<table cellspacing=0 cellpadding=0 style="'+cm_style_menu+'">';
}

function cm_menuend()
{
	return '</table>';
}

function cm_menuitem(t,m)
{
	if(t.length>1) {
		var s='<tr><td style="'+cm_style_item+'"';
		if(t.length>2)
			s+=' onmouseover="cm_submenu('+t[2]+',this,'+m+');this.style.backgroundColor=\''+cm_bgcolor_over+'\';this.style.cursor=\'pointer\';window.status=\''+t[0]+'\';return true;" onmouseout="this.style.backgroundColor=\''+cm_bgcolor+'\';window.status=\'\';return true;"';
		else
			s+=' onMouseover="cm_hidesub('+m+');this.style.backgroundColor=\''+cm_bgcolor_over+'\';this.style.cursor=\'pointer\';window.status=\''+t[0]+'\';return true;" onmouseout="this.style.backgroundColor=\''+cm_bgcolor+'\';window.status=\'\';return true;"';
		if(t[1].length>0)
		{
			s+=' onClick="location.href=\''+t[1]+'\';"';
		}
		s+='>';
		s+=''+t[0];
		if(t.length>2)
			s+='';
		s+='</td></tr>';
		return s;
	}
	return '<tr><td style="'+cm_style_hdr+'">'+t[0]+'</td></tr>';
}

