if(typeof(MooTools) != 'undefined')
{
	var subnav = new Array();

	Element.extend(
	{
		hide: function(timeout)
		{
			this.status = 'hide';
			clearTimeout(this.timeout);
			if(timeout)
			{
				this.timeout = setTimeout(this.anim.bind(this), timeout);
			}else{
				this.anim();
			}
		},

		show: function(timeout)
		{
			this.status = 'show';
			clearTimeout(this.timeout);
			if(timeout)
			{
				this.timeout = setTimeout(this.anim.bind(this), timeout);
			}else{
				this.anim();
			}
		},

		anim: function() 
		{
			if (this.status == 'show' && this.hiding == 1) return;
			
			if(this.status == 'show') {
				this.hiding = 1;
				//this.hideAll();
			}
			if(this.status == 'hide')
			{
				this.hiding = 0;
				this.myFx1.stop();
				// this.myFx2.stop();
				this.myFx1.start(1,0);
				// this.myFx2.slideOut();
			}else{
				this.myFx1.stop();
				// this.myFx2.stop();
				this.myFx1.start(0,1);
				// this.myFx2.slideIn();
			}
		},

		init: function() 
		{
			this.myFx1 = new Fx.Style(this, 'opacity');
			this.myFx1.set(0);
			if(this.parent._id)
			{
				// this.myFx2 = new Fx.Slide(this,{mode:'horizontal'});
			}else{
				// el = new Element('img',{'src':'/templates/viewray_light/img/arrow_down.gif','border':'0','styles':{'margin-left':'5px'}});
				// this.getParent().getFirst().adopt(el);
				// this.myFx2 = new Fx.Slide(this,{mode:'vertical'});
			}
			// this.myFx2.hide();
		},

		hideAll: function() 
		{
			for(var i=0;i<subnav.length; i++) {
				if(!this.isChild(subnav[i]))
				{
					subnav[i].hide(0);
				}
			}
		},

		isChild: function(_obj) {
			obj = this;
			while(obj.parent)
			{
				if(obj._id == _obj._id)
				{
					return true;
				}
				obj = obj.parent;
			}
			return false;
		}

	});


	var DropdownMenu = new Class(
	{
		initialize: function(element)
		{
			$A($(element).childNodes).each(function(el)
			{
				if(el.nodeName.toLowerCase() == 'li')
				{
					$A($(el).childNodes).each(function(el2)
					{
						if(el2.nodeName.toLowerCase() == 'ul')
						{
							$(el2)._id = subnav.length+1;
							$(el2).parent = $(element);
							subnav.push($(el2));
							el2.init();
							el.addEvent('mouseover', function() { el2.show(0); return false; });
							el.addEvent('mouseout', function() { el2.hide(20); });
							new DropdownMenu(el2);
						}
					});
				}
			});
			return this;
		}
	});

}
