var MachimaStartMenu = new Class({
	initialize: function(){
		this.backgroundBrightness = 'dark';
		this.startMenu = $('startMenu');
		this.startBar = $('startBar');
		this.startLogo = $('startLogo');
		this.startLogoWhite = $('startLogoWhite');
		this.startLogoBlack = $('startLogoBlack');
		this.outside = $('MachimaRotationArea');
		this.menuState = 'in';
		this.windowSize = $(window).getSize();
		this.opacityMin = .2;
		this.opacityMax = .8;

		this.startLogo.addEvent('mouseenter', (function(){
			this.slideIn();
		}).bind(this));
		this.startLogo.addEvent('click', (function(){
			this.slideIn(true);
		}).bind(this));
		this.startMenu.addEvent('mouseenter', (function(){
			if(this.menuState!='to-in' && this.menuState!='to-out') this.startMenu.set('tween',{'duration':200}).tween('opacity', this.opacityMax);
		}).bind(this));
		this.outside.addEvent('mouseenter', (function(){
			if(this.menuState == 'in') this.startMenu.set('tween',{'duration':1000}).tween('opacity', this.opacityMin);
		}).bind(this));

		this.startLogoBlack.setStyles({opacity:1,display:'block'}).set('tween',{duration:300});
		this.startLogoWhite.setStyles({opacity:0,display:'block'}).set('tween',{duration:300});
		this.startMenu.setStyle('opacity', this.opacityMin);
		
		$(window).addEvent('resize', (function(){ this.fitScreen(); }).bind(this));
		this.fitScreen();
	},
	
	setBackgroundBrightness: function(backgroundBrightness){
		this.backgroundBrightness=backgroundBrightness;
		if(this.menuState!='in') this.switchLogo();
	},
	
	switchLogo: function(){
		if(this.backgroundBrightness=='dark'){
			this.startLogoBlack.tween('opacity',0);
			this.startLogoWhite.tween('opacity',1);
		} else {
			this.startLogoBlack.tween('opacity',1);
			this.startLogoWhite.tween('opacity',0);
		}		
	},
	
	fitScreen: function(){
		this.windowSize = $(window).getSize();
		this.startBar.setStyle('height', this.windowSize.y);
		this.resizeStartMenu();
	},
	
	slideOut: function(){
		if(this.menuState=='to-out') return false;
		this.menuState = 'to-out';
		this.startMenu.setStyle('opacity',this.opacityMax).set('tween',{duration:1000, transition:Fx.Transitions.Expo.easeInOut}).tween('top',-this.windowSize.y);
		this.switchLogo();
		(function(){ this.startBar.setStyle('height',80); this.menuState='out'; }).bind(this).delay(1000);
	},
	
	slideIn: function(force){
		if(this.menuState!='out' && !force) return false;
		this.menuState = 'to-in';
		this.startBar.setStyle('height', this.windowSize.y);
		this.startMenu.setStyle('opacity',this.opacityMax).set('tween',{duration:500, transition:Fx.Transitions.Expo.easeInOut}).tween('top',0);
		this.startLogoWhite.tween('opacity',0);
		this.startLogoBlack.tween('opacity',1);
		(function(){ this.menuState='in'; }).bind(this).delay(500);
		return true;
	},
	
	resizeStartMenu: function(){
		// if menu bar is not visible, make sure that it stays invisible
		if(this.menuState=='out') this.startMenu.setStyle('top', -this.windowSize.y);
		this.startMenu.setStyle('height',this.windowSize.y);
	}
		
});