/**
 * class	P_MenuPortfolio
 * author	Paul Kruijt
 */
var P_MenuPortfolio = new Class({
	
	/**
	 * initialize
	 * @return void
	 */
	initialize: function()
	{
		// nodes
		this.filter_page_node				= $('filter_page');
		this.menu_node						= $('menu_portfolio');
		this.submenu_node					= $('submenu_portfolio');
		this.submenu_overlay_node			= $('submenu_portfolio_overlay');
		this.submenu_header_node			= $('submenu_portfolio_header');
		this.arrow_node						= $('submenu_portfolio_handler');
		this.handler_node					= this.menu_node.getElement('a');
		
		// classes
		this.active_class	= 'active';
		this.show_class		= 'show';
		this.hide_class		= 'hide';
		
		// settings
		this.alpha_duration	= 400;
	},
	
	/**
	 * start
	 * @return void
	 */
	start: function()
	{
		// position submenu
		this.positionSubMenu();
		
		// set events
		this.setEvents();
	},
	
	/**
	 * position submenu
	 * @return void
	 */
	positionSubMenu: function()
	{
		if (this.submenu_node)
		{
			var window_scroll_height = window.getScrollHeight();
			
			if (window_scroll_height > 0)
			{
				// get coordinates
				var submenu_coordinates	= this.submenu_node.getCoordinates();
				var submenu_top			= submenu_coordinates.top;
				var submenu_height		= parseInt(window_scroll_height - submenu_top);
				
				// set new height
				this.submenu_node.setStyle('height', submenu_height+'px');
			}
		}
	},
	
	/**
	 * set events
	 * @return void
	 */
	setEvents: function()
	{
		// set vars
		var _this	= this;
		
		// show submenu
		if (this.handler_node)
		{
			this.handler_node.addEvent('click', function()
			{
				// set color
				this.className = _this.active_class;
				
				_this.showSubMenu();
				
				return false;
			});
		}
		
		// hide submenu
		if (this.arrow_node)
		{
			this.arrow_node.addEvent('click', function()
			{
				// set color
				_this.handler_node.className = '';
				
				_this.hideSubMenu();
				
				return false;
			});
		}
		
		if (this.submenu_header_node)
		{
			this.submenu_header_node.addEvent('click', function()
			{
				// set color
				_this.handler_node.className = '';
				
				_this.hideSubMenu();
				
				return false;
			});
		}
	},
	
	/**
	 * set events
	 * @return void
	 */
	removeEvents: function()
	{
		if (this.handler_node)			this.handler_node.removeEvents('click');
		if (this.arrow_node)			this.arrow_node.removeEvents('click');
		if (this.submenu_header_node)	this.submenu_header_node.removeEvents('click');
	},
	
	/**
	 * show submenu
	 * @return void
	 */
	showSubMenu: function()
	{
		// set vars
		var _this = this;
		
		// show filter
		this.filter_page_node.setProperty('class', this.show_class);
		
		//**********
		// submenu *
		//**********
		this.submenu_node.setOpacity(0);
		this.submenu_node.setStyle('visibility', 'visible');
		
		// start alpha effect
		var alpha_effect = new Fx.Morph(this.submenu_node, {duration: this.alpha_duration, transition: Fx.Transitions.Quad.easeOut});
		
		alpha_effect.start({'opacity': 1}).chain(function()
		{
			// hide filter
			_this.filter_page_node.setProperty('class', _this.hide_class);
		});
		
		//******************
		// submenu overlay *
		//******************
		this.submenu_overlay_node.setOpacity(0);
		this.submenu_overlay_node.setStyle('visibility', 'visible');
		
		// start alpha effect
		var alpha_effect = new Fx.Morph(this.submenu_overlay_node, {duration: this.alpha_duration, transition: Fx.Transitions.Quad.easeOut});
		
		alpha_effect.start({'opacity': 1}).chain(function()
		{
			// hide filter
			_this.filter_page_node.setProperty('class', _this.hide_class);
		});
	},
	
	/**
	 * hide submenu
	 * @return void
	 */
	hideSubMenu: function()
	{
		// set vars
		var _this = this;
		
		// show filter
		this.filter_page_node.setProperty('class', this.show_class);
		
		//**********
		// submenu *
		//**********
		// start alpha effect
		var alpha_effect = new Fx.Morph(this.submenu_node, {duration: this.alpha_duration, transition: Fx.Transitions.Quad.easeOut});
		
		alpha_effect.start({'opacity': 0}).chain(function()
		{	
			_this.submenu_node.setStyle('visibility', 'hidden');
			
			// hide filter
			_this.filter_page_node.setProperty('class', _this.hide_class);
		});
		
		//******************
		// submenu overlay *
		//******************
		// start alpha effect
		var alpha_effect = new Fx.Morph(this.submenu_overlay_node, {duration: this.alpha_duration, transition: Fx.Transitions.Quad.easeOut});
		
		alpha_effect.start({'opacity': 0}).chain(function()
		{	
			_this.submenu_overlay_node.setStyle('visibility', 'hidden');
			
			// hide filter
			_this.filter_page_node.setProperty('class', _this.hide_class);
			
		});
	}
	
});