/**************************************************************

	Script	: Home menu for Stefan Vogelzang
	Version	: 1.0
	Authors	: Erik Huisman
	
**************************************************************/

var Homemenu = new Class({   
						 
	Implements: [Options,Events],
    
	options: { 
		transition: 'linear',
		duration: 	200
	},
						 
	initialize: function(options){
			
		this.setOptions(options);	
		
		this.menu	     = this.options.menu;
		this.container   = this.options.container;
		
		this.menu.getElements('div').set('opacity',0).setStyle('display','block').set('morph', {transition: this.options.transition, duration: this.options.duration })
		
		this.resize();	
		
		this.menu.getElements('li').each(function(item,i){ 
			
			item.addEvents({ 	
				'click': 	   function(e) { e.stop(); this.fireEvent('click',i+1); }.bind(this),
				'mouseenter':  function(e) { e.stop(); this.slideopen(i,item); }.bind(this),
				'mouseleave':  function(e) { e.stop(); this.slideclose(); }.bind(this)
			});
			
		}.bind(this));
		
		this.menu.addEvent('mouseleave', function(){ this.slideclose(); }.bind(this));
	
	}, 
	
	slideopen: function(id,item){
		
		this.menu.getElements('div').fade('in').set('html','');

		item.getElement('div').set('html',item.getElement('a').get('html')).setStyle('margin-left', -150).morph({'margin-left': 0 });
	
		
		this.menu.getElements('li').each(function(item,index){
			item.set('tween', {transition: this.options.transition, duration: this.options.duration })									  
			if(index<=id){ 					
				item.tween('left', (65*index) );	
			} else {
				item.tween('left', (65*(index-1)+172) );	
			}
		}.bind(this));
		
	}, 
		
	slideclose: function(){
		
		/*
		this.overlay.set('html','');
		this.overlay.setStyle('opacity',0);
		*/
		
		this.menu.getElements('div').fade('out');
		this.menu.getElements('div').set('html','');		
		
		this.menu.getElements('li').each(function(item,index){ 
				item.set('tween', { transition: this.options.transition, duration: this.options.duration })									  
				item.tween('left', (86*index) );
		}.bind(this));
		
	}, 
	
	resize: function() {
		this.bodyheight = $(document.body).getSize().y;
		this.menu.setStyle('height', this.bodyheight );
		this.container.setStyle('height', this.bodyheight );
	}

});
