Ext.ns('Ext.ux');
Ext.Element.DISPLAY = 2;

// singeltion
VisitorStates = function() {
	var data; // data is private and can't be accessed from outside.
	return {
		init : function() {
			// Initialize application here
		},

		getData : function() {
			return data;
		},

		getAll : function() {

		},

		get : function(key) {
			return this.data[key];
		},

		load : function(states) {
			this.data = states;
		},

		save : function(key, value) {
			Ext.Ajax.request({
						url : '/visitors/savestates.json',
						method : 'POST',
						params : {
							key : key,
							value : value
						},
						success : function(response, opts) {
							var obj = Ext.decode(response.responseText);
						}
					});
		},

		del : function(key) {
			Ext.Ajax.request({
						url : '/visitors/del.json',
						method : 'POST',
						params : {
							key : key
						},
						success : function(response, opts) {
							var obj = Ext.decode(response.responseText);
						}
					});
		}
	};
}();

Ext.ux.Header = Ext.extend(Ext.util.Observable, {
			/* Config */
		
			open : true,
			elId : 'headercontent',
			els : {},

			constructor : function(elId, config) {
				
				
				
				config = config || {};
				Ext.apply(this, config);
				Ext.ux.Header.superclass.constructor.call(this, config);
				
				this.el = Ext.get(elId);
				this.initMarkup();
				this.initEvents();
				
				
				

			},

			initMarkup : function() {
	

				this.els.open = this.el.select('.header-open')
						.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.close = this.el.select('.header-close')
						.setVisibilityMode(Ext.Element.DISPLAY);
				
						
						
				this.els.header = this.el.select('.header-center-area-content')
						.setVisibilityMode(Ext.Element.DISPLAY);


				this.els.open.originalDisplay = 'block';
				this.els.close.originalDisplay = 'block';
				this.els.header.originalDisplay = 'block';

			},

			initEvents : function() {
				this.els.open.on('click', function(ev) {
							this.open();
						}, this);

				this.els.close.on('click', function(ev) {
							this.close();
						}, this);

				

			},

			close : function() {
		
			
				this._setVisibilityMode();	
				this.els.open.show();
				this.els.close.hide();
					
				this.els.header.scale(960, 154, {
							easing : 'easeOut',
							duration : .5
						});

				VisitorStates.save('header.open', false);
			},

			open : function(dontshowmap) {
			
				this._setVisibilityMode();
			
				this.els.open.hide();
				this.els.close.show();
					
						
				this.els.header.scale(960, 360, {
							easing : 'easeOut',
							duration : .5
						});
						
				VisitorStates.save('header.open', true);
			},
			
		

			_setVisibilityMode : function() {
				this.els.open.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.close.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.header.setVisibilityMode(Ext.Element.DISPLAY);
			}
		});

Ext.ux.Hotelauswahl = Ext.extend(Ext.util.Observable, {
			/* Config */
			
			open : true,
			elId : 'headercontent',
			els : {},

			constructor : function(elId, config) {
				config = config || {};
				Ext.apply(this, config);
				Ext.ux.Hotelauswahl.superclass.constructor.call(this, config);
				this.el = Ext.get(elId);
				this.initMarkup();
				this.initEvents();

			},

			initMarkup : function() {
			

				
				this.els.haopen = this.el.select('.ha-open')
						.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.haclose = this.el.select('.ha-close')
						.setVisibilityMode(Ext.Element.DISPLAY);

				this.els.haheader = this.el.select('.ha-content')
						.setVisibilityMode(Ext.Element.DISPLAY);

			
				this.els.haopen.originalDisplay = 'block';
				this.els.haclose.originalDisplay = 'block';
				this.els.haheader.originalDisplay = 'block';

			},

			initEvents : function() {
			

				this.els.haopen.on('click', function(ev) {
							this.haopen();
						}, this);

				this.els.haclose.on('click', function(ev) {
							this.haclose();
						}, this);

			},

		
			
			haclose : function() {
				this._setVisibilityMode();
				this.els.haopen.show();
				this.els.haclose.hide();

				 this.els.haheader.slideOut('t', {
                useDisplay: true
            });

				
			},

			haopen : function(dontshowmap) {
				
				this._setVisibilityMode();
				this.els.haclose.show();
				this.els.haopen.hide();
				 this.els.haheader.slideIn('t', {
                useDisplay: true
            });
			},

			_setVisibilityMode : function() {
				this.els.haopen.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.haclose.setVisibilityMode(Ext.Element.DISPLAY);
				this.els.haheader.setVisibilityMode(Ext.Element.DISPLAY);
			}
		});