var NavigationHandler = Class.create();
NavigationHandler.prototype = {
	initialize: function(naviHandlerName)
	{
		this.name = naviHandlerName;
		this.setting = new Object();
		this.nodes = new Object();
	},
	setSetting: function(nSetObj)
	{
		this.setting = nSetObj
	},
	setNodes: function(nNodesObj)
	{
		this.nodes = nNodesObj
	},
	getSetting: function(nSetName)
	{
		try
		{
			return this.setting[nSetName];
		}
		catch(e)
		{
			return false;
		}
	},
	run: function()
	{
		nh_this = this;
		switch(this.setting.effectGroup)
		{
		case 'dropDown':
			//activator
			for(idfr in this.nodes) 
			{
				//set transport vars
				config = {
					node : {
						id			:	this.nodes[idfr].id,
						idfr		:	idfr,
						groupSize	:	$(this.nodes[idfr].id + 'Group').getDimensions()
					},
					object	:	this
				}
				//get height of elementGroup and push it in global storage
				this.nodes[idfr].groupSize = $(this.nodes[idfr].id + 'Group').getDimensions();
				//set height to zero
				$(this.nodes[idfr].id + 'Group').setStyle({height: '0px'});
				//init global call handlers
				Event.observe($(this.nodes[idfr].id).up(0), 'mouseover', nh_this.handleDropDownOver.bind(config));
				Event.observe($(this.nodes[idfr].id).up(0), 'mouseout', nh_this.handleDropDownOut.bind(config));
			}
			break;
		case 'mega-dropDown':
			for(idfr in this.nodes)
			{
				config = {
					node : {
						id			:	this.nodes[idfr].id,
						idfr		:	idfr,
						groupSize	:	$(this.nodes[idfr].id + 'Group').getDimensions()
					},
					object	:	this
				}
				//get height of elementGroup and push it in global storage
				this.nodes[idfr].groupSize = $(this.nodes[idfr].id + 'Group').getDimensions();
				//set height to zero
				$(this.nodes[idfr].id + 'Group').setStyle({height: '0px'});
				//init global call handlers
				Event.observe($(this.nodes[idfr].id), 'mouseover', nh_this.handleDropDownOver.bind(config));
				Event.observe($(this.nodes[idfr].id), 'mouseout', nh_this.handleDropDownOut.bind(config));
				Event.observe($(this.nodes[idfr].id + 'Group'), 'mouseover', nh_this.handleDropDownOver.bind(config));
				Event.observe($(this.nodes[idfr].id + 'Group'), 'mouseout', nh_this.handleDropDownOut.bind(config));
			}
			break;
		default:
			return;
		}
	},
	handleDropDownOver: function()
	{
		nh_hddor_groupLayer = this.node.id + 'Group';
		//$(nh_hddor_groupLayer).show();
		if(this.object.setting.effect != 'simple')
		{
			//clear timeout
			if(this.object.nodes[this.node.idfr].closeTimeRef) clearTimeout(this.object.nodes[this.node.idfr].closeTimeRef);
			//do not run in already open
			if(this.object.nodes[this.node.idfr].open) return;
			this.object.nodes[this.node.idfr].open = 1;
			//cancel current effect
			if(this.object.nodes[this.node.idfr].effect) this.object.nodes[this.node.idfr].effect.cancel();
			//do effectings
			this.object.nodes[this.node.idfr].effect = new Effect.Parallel(
				[
					new Effect.Opacity(this.node.id + 'Group', {sync:true,from:0,to:1}),
					new Effect.Morph(this.node.id + 'Group', 
					{
						sync:true,
						style: 'height:' + this.node.groupSize.height + 'px'
					})
				],
				{
					duration: 0.5,
					beforeStart: function()
					{

						$(nh_hddor_groupLayer).setOpacity(0);
						$(nh_hddor_groupLayer).show();
					}
				}
			);
		}
		switch(this.object.setting.effect)
		{
			case "opacityMorph":
				
				break;
			default:
				
				break;
		}
	},
	handleDropDownOut: function(input)
	{
		nh_hddot_groupLayer = this.node.id + 'Group';
		nh_hddot_this = this;
		if(!this.object.nodes[this.node.idfr].open) return;
		
		if(typeof(input) != 'object') {
			this.object.nodes[this.node.idfr].effect = new Effect.Parallel(
				[
					new Effect.Opacity(this.node.id + 'Group', {sync:true,from:1,to:0}),
					new Effect.Morph(this.node.id + 'Group', 
					{
						sync:true,
						style: 'height:0px'
					})
				],
				{
					duration: 0.2,
					afterFinish: function()
					{
						$(nh_hddor_groupLayer).hide();
						$(nh_hddor_groupLayer).setOpacity(0);
						
					}
				}
			);
			this.object.nodes[this.node.idfr].open = 0;
		} else
		{
			configForceClose = {
				node		:	{
					id	:	this.node.id,
					idfr:	this.node.idfr
				},
				object		:	this.object,
				foreClose	:	true
			}
			this.object.nodes[this.node.idfr].closeTimeRef = setTimeout(nh_hddot_this.object.handleDropDownOut.bind(this), 100);
		}
	}
}
