var headerObject = null;
if (!headerShowLabel) {
	var headerShowLabel = null;
}
var HeaderBasic = new Class ({
	
	Implements: [Events, Options],
	
	
	
	initialize: function(headerEl) {
	
		this._disableBottomBar = false;
	
		this.headerEl = headerEl;
		
		this.headerContent = $('mood-content');
		
		this.bottomBar = this.findBottomBar();
		
		if (!this.bottomBar) {
			return;
		}
		
		this.bottomBarOver = false;
		
		this.headerEl.addEvent('mouseover', function() {
			if (this.bottomBarOver && !this._disableBottomBar) {
				this.bottomBar.setStyles({opacity: '0.8', display: 'block'});
			} else if (!this._disableBottomBar) {
				this.bottomBar.setStyles({opacity: '0.5', display: 'block'});
			} else {
				this.bottomBar.setStyles({opacity: '0.5', display: 'none'});
			}
		}.bind(this));
		this.headerEl.addEvent('mouseout', function() {
			this.bottomBar.setStyles({opacity: '0.5', display: 'none'});
		}.bind(this));
		this.bottomBar.addEvent('mouseover', function() {
			if (!this._disableBottomBar) {
				this.bottomBarOver = true;
				this.bottomBar.setStyles({opacity: '0.8', display: 'block'});
			}
		}.bind(this));
		this.bottomBar.addEvent('mouseout', function() {
			if (!this._disableBottomBar) {
				this.bottomBarOver = false;
				this.bottomBar.setStyles({opacity: '0.5', display: 'block'});
			}
		}.bind(this));
		this.hideButton = this.bottomBar.getFirst('div.hide');
		if (this.hideButton) {
			this.initHideHeaderEvent();
		}
		
		if (Cookie.read('hideHeader') == 'yes') {
			this.lastHeight = this.headerContent.getParent().getStyle('height');
			this.headerContent.getFirst().setStyles({opacity:0});
	    	this.headerContent.getFirst().setStyles({display:'none'});
	    	this.headerContent.getParent().setStyles({height:40});
	    	this.displayShowButton();
		} 
		
		
	},
	
	displayShowButton: function() {
		var showLabel = 'Header einblenden';
		if (headerShowLabel) {
			showLabel = headerShowLabel;
		}
		if ($('show-bar')) {
			$('show-bar').innerHTML = showLabel;
			$('show-bar').setStyles({display: 'block'});
			
			$('show-bar').addEvent('click', function() {
			
				$('show-bar').setStyles({display: 'none'});

				var closeFx = new Fx.Elements(this.headerContent.getParent(), {
					duration: 500,
					transition: Fx.Transitions.Expo.easeOut,
				    onComplete: function(){
				    	this.headerContent.getFirst().setStyles({display:'block'});

						var fadeOutFx = new Fx.Elements(this.headerContent.getFirst(), {
							duration: 200,
							transition: Fx.Transitions.Expo.easeOut,
						    onComplete: function(){
						    	var myCookie = Cookie.write('hideHeader', 'no', {'path':'/'});
						    }.bind(this)
						}).start({
						    '0': {
						        // 'height': 80
						        'opacity' : 1
						    }
						});
		

				    }.bind(this)
				}).start({
				    '0': {
				        'height': this.lastHeight
				        //'opacity' : 0
				    }
				});






			}.bind(this));
			
		}
		
	},
	
	initHideHeaderEvent: function() {
		this.hideButton.addEvent('click', function() {
			this.lastHeight = this.headerContent.getParent().getStyle('height');
			//this.headerEl.setStyles({'overflow': 'hidden'});
			var fadeOutFx = new Fx.Elements(this.headerContent.getFirst(), {
				duration: 200,
				transition: Fx.Transitions.Expo.easeOut,
			    onComplete: function(){
			    	this.headerContent.getFirst().setStyles({display:'none'});
					var closeFx = new Fx.Elements(this.headerContent.getParent(), {
						duration: 500,
						transition: Fx.Transitions.Expo.easeOut,
					    onComplete: function(){
					    	this.displayShowButton();
					    	var myCookie = Cookie.write('hideHeader', 'yes', {'path':'/'});
					    }.bind(this)
					}).start({
					    '0': {
					        'height': 40
					        //'opacity' : 0
					    }
					});
			    }.bind(this)
			}).start({
			    '0': {
			        // 'height': 80
			        'opacity' : 0
			    }
			});
		}.bind(this));
	},
	
	findBottomBar: function() {
		var div = $$('div.bottom-bar');
		var bDiv = null;
		if (div && div.length) {
			div.each(function(item, index) {
				var parent = item.getParent('div.mood');
				if (parent && parent == this.headerEl) {
					bDiv = item;
				}
			}.bind(this));
		}
		return bDiv;
	},
	
	disableBottomBar: function(disable) {
		this._disableBottomBar = disable;
		this.headerEl.fireEvent('mouseover');
	}
	

});

window.addEvent('domready', function() {
	var header = $$('div.mood');
	if (header.length > 0) {
		headerObject = new HeaderBasic(header[0]);
	}
});
