var isie = (document.all) ? true : false;
var active = null;

function nav (menu)
{
	this.menu	= 'list_' + menu;
	this.active = 2;
	this.init();
}

	nav.prototype.init = function ()
	{
		var elements = document.getElementById(this.menu).childNodes;
		
		for (var i=0; i < elements.length; i++)
		{
			var li 		= elements[i];
			var list	= li.lastChild.childNodes;
			
			if (li.className.indexOf('active') != -1)
			{
				active = i;
			}
			else
			{
				for (var j=0; j < list.length; j++)
				{
					if (list[j].className.indexOf('active') != -1)
					{
						active = i;
					}
				}
			}
			
			this.interaction(li, i);
		}
	}

	nav.prototype.interaction = function (element, index)
	{
		var self 		= element;
		var anim		= new animation(index);
		var element 	= (document.getElementById(element.id)) ? document.getElementById(element.id) : false;
		
		if (active != index)
		{
			element.onmouseover = function ()
			{
				anim.fade(true);
			}
			
			element.onmouseout = function ()
			{
				anim.fade(false);
			}
		}
		else
		{
			anim.jump();
		}
	}
	
function animation (index)
{
	this.index 		= index;
	this.timer		= null;
	this.element	= document.getElementById('opacity_' + index);
	
	this.start		=  0;
	this.end		= 66;
	this.current	=  0;
	
	this.step		=  3;
	this.speed		= 10;
}

	animation.prototype.fade = function (state)
	{
		var self  = this;
		
		clearTimeout (this.timer);
		
		switch(state)
		{
			case true:
			
				this.current = this.current + this.step;	
				
				this.setOpacity();
				
				if (this.current < this.end)
				{
					this.timer = setTimeout (function(){self.fade(state)}, this.speed);
				}
				else
				{
					this.current = this.end; this.setOpacity();
				}
				
				break;
				
			case false:
				
				this.current = this.current - this.step;
				
				this.setOpacity();
				
				if (this.current > this.start)
				{
					this.timer = setTimeout (function(){self.fade(state)}, this.speed);
				}
				else
				{
					this.current = this.start; this.setOpacity();
				}
				
				break;
		}
	}
	
	animation.prototype.jump = function ()
	{
		this.current = this.end; this.setOpacity();
	}
	
	animation.prototype.setOpacity = function ()
	{
		if (isie)
		{
			this.element.filters.alpha.opacity = this.current;
		}
		else
		{
			this.element.style.MozOpacity = this.current/100;
			this.element.style.KhtmlOpacity = this.current/100;
		}
	}
