var SousMenu = new Class({
	
	Extends:MenuBase,
	Implements: [Options, Events],
	options:{
		container:null
	},
	
	initialize:function(options) {
		this.setOptions(options);
		debug('SousMenu.initialize');

		if(!is_home) {
			$$('.menu_cont')[0].grab(this.options.container);
		}
		
		this.initItems();
		
		//this.options.container.addEvent('mouseenter', function() {this.open()}.bind(this));
	},
	
	initItems:function() {
		this.items = new Array();
		this.options.container.getElements('> li').each(function(el, index) {
			this.items[index] = new SousMenuItem({
				container:el,
				index:index
			});
			this.items[index].addEvents({
				'SousMenuItem:open_menu': function(e) { 
					debug('SousMenu:open_menu');
					this.fireEvent('SousMenu:open_menu'); 
				}.bind(this),
				'SousMenuItem:select': function(e) {
					if(this.select_item) this.select_item.unselect();
					this.select_item = e.target;
				}.bind(this),
				'SousMenuItem:over': function(e) { 
					this.fireEvent('SousMenu:over');
				}.bind(this),
				'SousMenuItem:click': this.clickItem.bind(this)
			});
		}, this);
		if(is_home) this.options.container.setStyle('width', this.options.container.getSize().x);
		for(var i = 0; i < this.items.length; i++) {
			this.items[i].initPosition();
		}
		if(!is_home) this.options.container.setStyle('width', 0);
	},
	
	open:function() {
		for(var i = 0; i < this.items.length; i++) {
			this.items[i].open();
		}
		this.is_open = true;
	},
	
	close:function(select) {
		for(var i = 0; i < this.items.length; i++) {
			if(this.items[i].is_select && select == true) {
				this.items[i].closeItem(true);
			}
			else this.items[i].closeItem(false);
		}
		this.is_open = false;
	},
	
	setOpen:function() {
		for(var i = 0; i < this.items.length; i++) {
			this.items[i].setOpen();
		}
	},
	
	setClose:function() {
		for(var i = 0; i < this.items.length; i++) {
			this.items[i].setClose();
		}
	},
	
	clickItem:function(e) {
		var has_select = this.select_item ? true : false;
		var select_cat = has_select ? this.select_item.getGet('cat') : false;
		if((select_cat != e.cat) || is_home) {
			window.location.href = e.link;
		}
		else {
			e.old_index = this.select_item.options.index;
			delete e.link;
			this.fireEvent('SousMenu:goto', e);
		}
	},
	
	goSelect:function(e) {
		debug('SousMenu:goSelect');
		if(!this.is_open) {
			this.select_item.unselect();
			this.select_item.closeItem();
			this.select_item = this.items[e.index];
			this.select_item.select();
			this.select_item.closeItem(true);
		}
	}
	
});
