window.addEvent('domready', function()
{
	$$('.inside_left_nav ul li').each(function(element)
	{
		if ( element.hasClass('selected') == false )
		{
			element.getElements('ul').each(function(the_list)
			{
				
					the_list.setStyles({'overflow': 'hidden','display': 'block'});
					the_list.store('final_height', the_list.getSize().y);
					the_list.setStyles({'height':'0','display': 'none'});
					the_list.set('morph', {
								   'duration': 350, 
								   'transition': 'linear', 
								   'link':'cancel',
								   'onStart': function()
								   {
										if ( this.getStyle('display')  == 'none' )
										{
											this.setStyle('height', '0');
											this.setStyle('display', 'block');
										}
								   }.bind(the_list),
								   'onComplete': function()
								   {
										if ( (this.getStyle('height').toInt() == 1) && (! Browser.Engine.trident) )
										{
											this.setStyle('display', 'none');
										}
								   }.bind(the_list)});
			});
				
			element.addEvent('mouseenter', function()
			{
				this.getElements('ul').each(function(the_list)
				{
					the_list.morph({'height': the_list.retrieve('final_height')});
				});
			});
		}
		else
		{
			element.getElements('ul').each(function(the_list)
			{
				the_list.setStyle('display', 'block');
			});
		}
	});
	
	$$('.inside_left_nav').addEvent('mouseleave', function()
	{
		$$('.inside_left_nav ul li').each(function(element)
		{
			if ( element.hasClass('selected') == false )
			{
				element.getElements('ul').each(function(the_list)
				{
					if ( the_list.getStyle('display') == 'block' )
					{
							the_list.morph({'height': 0});
					}	
				});
			}
		});
	});
});

var Management = new Class({
	Implements: Options,
	options: {
	},
	_openBio: '',
	initialize: function(options)
	{
		this.setOptions(options);
		$$('#management .profile').each(function(element)
		{
			var bio = element.getFirst('.bio_info');
			bio.setStyles({'overflow': 'hidden','display': 'block'});
			bio.store('final_height', bio.getSize().y);
			bio.setStyles({'height':'0','display': 'none'});
			bio.store('isopen', false);
			
			bio.set('morph', {
							   'duration': 350, 
							   'transition': 'linear', 
							   'link':'cancel',
							   'onStart': function()
							   {
								   if ( bio.retrieve('isopen') === false )
								   {
									   this.setStyle('display', 'block');
									   this.setStyle('height', '0');
								   }
							   }.bind(bio),
							   'onComplete': function()
							   {
									if ( bio.retrieve('isopen') === false )
									{
										bio.store('isopen', true);
									}
									else
									{
										bio.store('isopen', false);
										this.setStyle('display', 'none');
									}
							   }.bind(bio)
						   	});
			
			this.title = element.getFirst('.title');
			this.title.setProperty('html', this.title.getProperty('html') + '<a href="#"><span></span> View Bio</a>');
			
			this.title.getFirst('a').addEvent('click', function(e)
			{
				e.preventDefault();
				if (bio.getStyle('display') == 'block')
				{
					this.close(bio);	
				}
				else
				{
					this.open(bio);	
				}
			}.bind(this));
		}, this);
	},
	open: function(bio)
	{
		if (this._openBio)
		{
			this.close(this._openBio);
		}
		bio.morph({'height': bio.retrieve('final_height')});
		this._openBio = bio;
		bio.getParent().addClass('open');
	},
	close: function(bio)
	{
		if (bio == this._openBio)
		{
			this._openBio = '';	
		}
		bio.morph({'height': 0});
		bio.getParent().removeClass('open');
	}
});

window.addEvent('domready', function()
{
	//if not ie6
	if (! Browser.Engine.trident4)
	{
		var manager = new Management();
	}
});