NavigationManager = Class.create();

NavigationManager.prototype = {

	initialize : function(container)
	{
		this.container = $(container);

		this.container.getElementsBySelector('a').each(function(btn) {
			btn.observe('mouseover',
						this.onMenuShow.bindAsEventListener(this));
		}.bind(this));

		this.container.getElementsBySelector('a').each(function(btn) {
			btn.observe('mouseout',
						this.onMenuHide.bindAsEventListener(this));
		}.bind(this));
	},
	

	onMenuShow : function(e)
	{
		Event.stop(e);
		var a = Event.findElement(e);
		var li = Event.findElement(e).up('li');
		
		var options = {
			x          : -200, 
			y          : 0, 
			mode       : 'relative'
//			transition : Effect.Transitions.spring
		}

		new Effect.Move(a, options);
		var options = {
			style    : 'border: 5px solid #ff00ff;',
			duration : 0.5
		}
		
//		new Effect.Move(a, { x: 20, y: -30, mode: 'relative' });
//		new Effect.Morph(a, options);
	},

	
	onMenuHide : function(e)
	{
		Event.stop(e);
		var li = Event.element(e).up('li');
		
		var options = {
				x          : 200, 
				y          : 0, 
				mode       : 'relative',
				transition : Effect.Transitions.spring
			}

//		new Effect.Move(li, options);
		var options = {
				style    : 'width: 74px',
				duration : 0.5
			}
		
		new Effect.Morph(li, options);
	},

	onOpenhomeRemove : function(e)
	{
		Event.stop(e);

		var rowItem = Event.element(e).up('tr');
		if (rowItem) {
			var options = {
				duration    : 0.5,
				from        : 1, 
				to          : 0,
				afterFinish : function(effect) {
					effect.element.remove();
				}
			}

			new Effect.Fade(rowItem, options);
			return;
		}
	},

	rebindButtons : function(elmt)
	{
		elmt.getElementsBySelector('a[class=removeButton]').each(function(btn) {
			btn.observe('click',
						this.onOpenhomeRemove.bindAsEventListener(this));
		}.bind(this));

		elmt.getElementsBySelector('a.openHomeInfo').each(function(btn) {
			btn.observe('click',
						this.onOpenhomeInfo.bindAsEventListener(this));
		}.bind(this));
	},
	
	onOpenhomeInfo : function(e)
	{
		Event.stop(e);
		var btn   = Event.element(e);
		var input = btn.next('input.open_home_info');
		var title = 'additional information for this open home date';
		
		if (input) {
			if (btn.hasClassName('editAddButton')) {
				var options = {
					duration    : 1,
					direction   : 'top-left',
					afterFinish : function(effect) {
						btn.removeClassName('editAddButton');
						btn.addClassName('editRemoveButton');
						btn.title = 'Remove ' + title;
					}
				}
	
				new Effect.Grow(input, options);
				return;
			}
			else if (btn.hasClassName('editRemoveButton')) {
				var options = {
					duration    : 1,
					direction   : 'top-left',
					afterFinish : function(effect) {
						btn.removeClassName('editRemoveButton');
						btn.addClassName('editAddButton');
						btn.title = 'Add ' + title;
					}
				}
	
				new Effect.Shrink(input, options);
				return;
			}
		}
	}
};

