var HeaderMenu = new Class({
	Implements: [Events, Options],
	options : {
	},
	initialize:function(options){
		this.setOptions(options);
		if (!$chk($$('#header div.top ul.logged_actions')[0])) {
			return;
		}
		this.ul = $$('#header div.top ul.logged_actions')[0];
		this.lis = this.ul.getElements('li');
		
		this.ul.set('class', 'js_menu_ul').inject($$('body')[0], 'top');
		
		this.container = new Element('div', {
			'class' : 'js_menu_wrapper'
		}).inject($$('#header div.top')[0], 'top');
		
		var defaultValue = null;
		for (var i=0;i<this.lis.length;i++) {
			if (this.lis[i].getElements('a')[0].get('class') == 'selected') {
				defaultValue = i;
				break;
			}
		}
		if (defaultValue == null)
			defaultValue = 0;
		this.text = new Element('div', {
			'class' : 'text',
			'html' : 'Mon compte sur Ruedesnounous',
			'events' : {
				'click' : function(e) {
					this.openMenu();
					e.stop();
				}.bindWithEvent(this)
			}
		}).inject(this.container);
		
		
		
	},
	
	openMenu : function(){
		if (this.ul.getStyle('display') == 'block')
			this.ul.setStyle('display', 'none');
		else {
			this.replaceList();
			this.ul.setStyle('display', 'block');
		}
	},
	
	replaceList : function() {
		this.ul.setStyles({
			'top' : '-3000px',
			'display' : 'block'
		});
		var position = {
			'top' : Display.getY(this.text)+this.text.getSize().y,
			'left': (Display.getX(this.text)+this.text.getSize().x)-this.ul.getSize().x
		};
		this.ul.setStyles({
			'display' : 'none',
			'top' : position.top.toString()+"px",
			'left': position.left.toString()+"px"
		});
	}
});
window.addEvent('domready', function(){
	new HeaderMenu();
})
