HIDE_DELAY=500

opera=window.opera?1:0;
ie=(document.getElementById&&!this.opera)?1:0;
ns4=(document.layers&&!document.getElementById)?1:0;
ns6=(this.dom&&parseInt(navigator.appVersion)>=5)?1:0;
browser=(this.ie||this.ns4||this.ns6||this.opera);

var MakoTimer_2

function undefined(value)
{
 return typeof(value) == 'undefined';
}

function MakoMenu_2(items)
{
	window.MainMenu_2=this;
	this.items=new Array;
	this.root=new Array;
	this.root.children=new Array;
	this.root.properties=items[0];

		
	for (i=1;i<items.length;i++)
		new MakoMenu_2Item(this, this.root, items[i], this.root.properties, i);

	this.hideMenu=function()
	{
			for (var i=0;i<this.root.children.length;i++)
				if (this.root.children[i].submenu_visible)
				{	
					this.root.children[i].submenu_visible(0);
				}
	}

	for (var i=0;i<this.items.length;i++)
	  document.write(this.items[i].drawMenu());

	for (var i=0; i<this.root.children.length; i++)
		this.root.children[i].visible(1);
}


function MakoMenu_2Item(menu, parent, item, properties, rootindex)
{
	this.menu=menu;
	this.rootindex=rootindex
	this.parent=parent;
	this.content=item.content;
	this.bg_image=item.bg_image;
	this.bg_image_over=item.bg_image_over;
	this.contenttxt=item.contenttxt;
	this.href=undefined(item.href)?"#":item.href;
	this.properties=properties;
	this.children=new Array;
	this.index=menu.items.length;
	if (parent.children.length>0) this.young_brother=this.parent.children[this.parent.children.length-1]
	menu.items[menu.items.length]=this;
	parent.children[parent.children.length]=this;
	this.id="MakoMenu_2div"+this.index;
	this.size=this.properties["size"];
	this.size=undefined(item.size)?this.properties["size"]:item.size;
	this.offset=this.properties["offset"];
	this.content_over=undefined(item.content_over)?null:item.content_over
	this.active=null
	
	this.visible=function(s)
	{
		if (ns4) {
			layer=document.layers[this.id].visibility=s?'show':'hide';
			if (document.layers[this.id+'_top']) layer=document.layers[this.id+'_top'].visibility=s?'show':'hide';
			if (document.layers[this.id+'_bg_image']) layer=document.layers[this.id+'_bg_image'].visibility=s?'show':'hide';
		}
		else {
			document.getElementById(this.id).style.visibility=s?'visible':'hidden';
			if (document.getElementById(this.id+'_top')) document.getElementById(this.id+'_top').style.visibility=s?'visible':'hidden';
			if (document.getElementById(this.id+'_bg_image')) document.getElementById(this.id+'_bg_image').style.visibility=s?'visible':'hidden';
		}
	}
	
	this.drawMenu=function ()
	{	
		var mouseout='',cont,cont_over
		if (this.children.length==0)
			mouseout='MakoMenu_2_rollover(\'' + this.id + '\', false)'
		
		if (!this.contenttxt && !this.content) this.contenttxt=' ';

		if (this.contenttxt) {
			cont=this.contenttxt
			cont_over=cont
		}
		else {
			cont='<img src="'+this.content+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0">'
			cont_over='<img src="'+this.content_over+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0">'+this.contenttxt
		}
		if (this.style) cont='<div class="'+this.style+'">'+cont+'</div>'
		if (this.style_over) cont_over='<div class="'+this.style_over+'">'+cont_over+'</div>'

		top_cont='<a href="'+this.href+'" onmouseover="mouse_event_2(\'over\','+this.index+');MakoMenu_2_rollover(\'' +this.id + '\', true)" onmouseout="mouse_event_2(\'out\','+this.index+');' + mouseout + '">'+'<img src="'+SPACER+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0"></a>'
		
		diwek=''
		diwek=make_div(this.id, this.zindex+1, this.location, this.size, cont, this.bgcolor);

		if (this.bg_image_over && this.overcolor) {
			cont_bg_image_over='<table border="0" width="'+this.size[0]+'" height="'+this.size[1]+'" cellspacing=0 cellpadding=0><tr><td valign=top background="'+this.bg_image_over+'">' + cont_over + '</td></tr></table>'
			//alert (cont_bg_image_over)
			
			//cont_bg_image_over='<img src="'+this.bg_image_over+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0">'
			
			diwek+='\n\n'+make_div(this.id+'_over', this.zindex+4, this.location, this.size, cont_bg_image_over, this.overcolor);
			//diwek+='\n\n'+make_div(this.id+'_over', this.zindex+2, this.location, this.size, cont_over, this.overcolor);
		}
		else if(this.bg_image_over) {
			cont_bg_image_over='<img src="'+this.bg_image_over+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0">'
			diwek+='\n\n'+make_div(this.id+'_over', this.zindex+4, this.location, this.size, cont_bg_image_over, false);
		}
		else if (this.overcolor) {
      diwek+='\n\n'+make_div(this.id+'_over', this.zindex+2, this.location, this.size, cont_over, this.overcolor);
    }
		if (this.bg_image) {
			cont_bg_image='<img src="'+this.bg_image+'" width="'+this.size[0]+'" height="'+this.size[1]+'" border="0">'
			diwek+='\n\n'+make_div(this.id+'_bg_image', this.zindex+3, this.location, this.size, cont_bg_image, false);
		}

		//diwek+='\n\n'+make_div(this.id+'_top', this.zindex+4, this.location, this.size, top_cont, false);
		diwek+='\n\n'+make_div(this.id+'_top', this.zindex+4, this.location, this.size, top_cont, false);
		//alert (diwek)
		return diwek
	}
	
	
		if (item.bgcolor)
			this.bgcolor=item.bgcolor
		else if (this.properties.bgcolor)
			this.bgcolor=this.properties.bgcolor
		else if (this.parent.bgcolor)
			this.bgcolor=this.parent.bgcolor

		if (item.overcolor)
			this.overcolor=item.overcolor
		else if (this.properties.overcolor)
			this.overcolor=this.properties.overcolor
		else if (this.parent.overcolor)
			this.overcolor=this.parent.overcolor

		if (item.style)
			this.style=item.style
		else if (this.properties.style)
			this.style=this.properties.style
		else if (this.parent.style)
			this.style=this.parent.style

		if (item.style_over)
			this.style_over=item.style_over
		else if (this.properties.style_over)
			this.style_over=this.properties.style_over
		else if (this.parent.style_over)
			this.style_over=this.parent.style_over
		
		if (item.location)
		{
			this.location=item.location
			this.zindex=50
		}
		else
		{
			if (this.young_brother==null)
			{
				this.zindex=this.parent == this.menu.root? 0: parseInt(this.parent.zindex)+10;
					this.location=undefined(this.properties.location)?
					(this.parent == this.menu.root? 
						this.menu.root.properties.location :
						this.location=[this.parent.location[0]+this.offset[0], this.parent.location[1]+this.offset[1]]):
					this.properties.location;
		
			}else{
		
					if (this.parent==this.menu.root) offset=[this.offset[0],this.offset[1]]
					else offset=[0,this.size[1]]
					this.zindex=this.young_brother.zindex;
					this.location=[this.young_brother.location[0]+offset[0], this.young_brother.location[1]+offset[1]];
			}
		}

		this.submenu_visible=function(shown)
		{
				for (var i=0; i<this.children.length; i++)
				{
					var child=this.children[i];
					child.visible(shown);
					if (shown==0 )
					{
						MakoMenu_2_rollover(this.id,false)
					}
					if (child.children.length && shown==0 )
					{
						child.submenu_visible(0);
					}
				}
		}
		this.show_submenu=function(index)
		{
	    var submenu_item=this.menu.items[index];
			if(this.parent.active && submenu_item!=this.parent.active) this.parent.active.submenu_visible(0);
			if(submenu_item.children.length>0) submenu_item.submenu_visible(1);
			this.parent.active=submenu_item;
		}

	this.submenu=item.submenu;
	if (!undefined(this.submenu))
	{
		for (var i=1;i<this.submenu.length;i++)
			new MakoMenu_2Item(this.menu, this, this.submenu[i], this.submenu[0], rootindex);
	}

	return this;
}

function mouse_event_2(event_type,index,id)
{
	if (MakoTimer_2)
	{
		window.clearTimeout(MakoTimer_2);
		MakoTimer_2=null;
	}
	
	if (event_type=='over') {
		if(window.MainMenu_2.items[index].show_submenu) window.MainMenu_2.items[index].show_submenu(index);
	}
	if (event_type=='out') MakoTimer_2=setTimeout('window.MainMenu_2.hideMenu()', HIDE_DELAY);
}


function make_div(id,zindex,location,size,content,bgcolor)
{
//		alert (content)
	var div;

	if (ns4) {
		div='<layer id="'+id+'" z-index='+zindex
		if (bgcolor) div+=' bgcolor="' + bgcolor + '"'
		div+=' top='+location[1] + ' left="'+location[0]+'" width="'+size[0]+'" height="'+size[1]+'" visibility="hidden">'
		div+=content+'</layer>\n'
		//alert (div)


	}
	else {
		div='<div id="'+id+'" style="position:absolute; z-index:'+zindex
		if (bgcolor) div+='; background-color: ' + bgcolor
		div+='; top:'+location[1]+'px; left:'+location[0]+'px; width:'+size[0]+'px; height:'+size[1]+'px; visibility:hidden'+'; " >'
		div+=content+'</div>';
	}	
	return div
}

function MakoMenu_2_rollover(obj, s)
{
	//alert ('rollover')
	//alert (document.getElementById(obj).parent)
	/*if (img_over!='null')
	{
		if (ns4) document.layers[obj].document.images[obj+'_roll'].src=img_over
		else{
			if (document.images[obj+'_roll'])  document.images[obj+'_roll'].src=img_over
		}
	}*/
		if (ns4) {
			if (document.layers[obj+'_over']) layer=document.layers[obj+'_over'].visibility=s?'show':'hide';
		}
		else {
			if (document.getElementById(obj+'_over')) document.getElementById(obj+'_over').style.visibility=s?'visible':'hidden';
		}

	
}
