function sgmenu(args){
	if(!args.mtree) alert("You should give a menu structure");

	var _main = args.parent ? args.parent : document.getElementById("menu");

	this.rollover = args.rollover?args.rollover:true;
	this.width=args.width ? args.width : 130;
	this.height=args.height? args.height : 16;
	this.imgdir = args.imgdir ? args.imgdir : "";
	if (_main){
		this.Process(args.mtree,_main,1,"0");
	}
	else
		alert("A div object should exist to place the menu or a parent should be pass");
}

sgmenu.prototype = {
Process: function(t,parent,d,curid){
var i;
for(i=0;i<t.items.length;i++){
var ci = t.items[i];
var menu = document.createElement("DIV");
menu.isCollapsed = false;
menu.className = "menuItem"+d;
menu.id = "i-"+curid+"-"+i;
var s = menu.style;
s.margin    = "0px";
s.listStyle = "none";
s.overflow  = "hidden";
parent.appendChild(menu);

var hdr = document.createElement("DIV");

with(hdr.style){
position = "relative";
/*height=(this.height-2)+"px";
paddingTop="2px";*/
cursor="hand";
}

var h = this.height;
if (d > 2) h = h - 2;
hdr.className = "menuItemNiv"+d+" menuItemNiv"+d+"-"+ci.status;
hdr.innerHTML = "<table  height='"+h+"' width='100%' topmargin='0' style='margin:0px' border='0' cellspacing='0' cellpadding='0'><tr><td valign='center'><img  src='"+this.imgdir+"/mitem_"+d+"_"+ci.status+".gif' width='8' style='margin:2px;margin-top:2px'></td><td width='100%' style='padding-left:2px'>"+ci.text+"</td></tr></table>";
hdr.curid = curid+"-"+i;
hdr.depth = d;
if(ci.target) hdr.target = ci.target;
if( ci.status == "on") {parent.curopen = hdr;}
if(ci.link) hdr.lnk = ci.link;
hdr.status = ci.status;
if(this.rollover){
//sgmenu.addEvent(hdr,"mouseover",this._OnOver);
//sgmenu.addEvent(hdr,"mouseout",this._OnOut);
}
sgmenu.addEvent(hdr,"click",this._OnClick);
menu.appendChild(hdr);

if(ci.items) {
this.Process(ci,menu,d+1,curid+"-"+i);
}

if(ci.status=="off"){
menu.isCollapsed = true;
for(j=1;j<menu.childNodes.length;j++){
s=menu.childNodes[j].style;
s.display="none";
s.cursor="default";
}
 }
}

},

_OnOver: function(evt){
  var e = evt ? evt : window.event;
	if(e.target) target = e.target;
  else if(e.srcElement) target = e.srcElement;
	curitem = sgmenu.findParent(target,"DIV");
	curitem .className = curitem .className.replace(/-off/g,"-on");

if(!curitem.lnk){ oimg = curitem.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
oimg.src = oimg.src.replace(/off/g,"on");}
},
_OnOut:function(evt){
  var e = evt ? evt : window.event;
	if(e.target) this.target = e.target;
  else if(e.srcElement) this.target = e.srcElement;
	curitem = sgmenu.findParent(target,"DIV");
	curitem.className = curitem.className.replace(/-on/g,"-"+curitem.status);
if(!curitem.lnk) { oimg = curitem.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0];
oimg.src = oimg.src.replace(/on/g,curitem.status);}
},
_OnClick:function(evt){
  var e = evt ? evt : window.event;
	if(e.target) this.target = e.target;
  else if(e.srcElement) this.target = e.srcElement;
  citem = sgmenu.findParent(this.target,"DIV");
  pitem =citem.parentNode.parentNode;
	 subm = document.getElementById("i-"+citem.curid);

	 var oitem = pitem.curopen;
	 //if (oitem != citem){
	 
	   if (citem.lnk) {
				if(citem.lnk.substr(0,4)=="http"){
          window.open(citem.lnk);
        } else if(citem.target == "_blank") {
					window.open(citem.lnk);
        } else{
		   location=citem.lnk;
        }
	  }else {
     for(i=1;i<citem.parentNode.childNodes.length;i++)
       sgmenu.show(citem.parentNode.childNodes[i]);
   }
		 
		 pitem.curopen = citem;
		   
		 if(oitem){
			 oitem.className = oitem.className.replace(/-on/g,"-off");
			 oitem.status="off";
for(i=1;i<oitem.parentNode.childNodes.length;i++)
sgmenu.hide(oitem.parentNode.childNodes[i]);

			 
		 citem.className = citem.className.replace(/-off/g,"-on");
	  	citem.status="on";
		 }
			 
 		
//	 } 

}				 
};

sgmenu._addItem=function(text,lnk,lvl,idx){

return e;
}

sgmenu.hide = function(elm){
if (elm.style){
elm.style.display = "none";
}
}
sgmenu.show = function(elm){
if (elm.style){
elm.style.display = "block";
//elm.style.visibility = "visible";
}
}
sgmenu.addEvent = function(elm,eType,eListener){
if(elm.addEventListener) elm.addEventListener(eType,eListener,false);
else if(elm.attachEvent) elm.attachEvent("on"+eType,eListener);
};
sgmenu.findParent = function(n,t){
	while(n.parentNode){
	if (n.nodeName==t) return n;
	 n = n.parentNode;
	}
	return null;
};

		