var MenuBar = Class.create();
MenuBar.prototype = {
	initialize: function (element) {
		this.element = $(element);

		this.videos_head = $('videos_head');
		this.videos_container = $('videos_menu_dropdown');
		this.videos_head.onclick = this.showHideVideos.bindAsEventListener(this);
		this.videos_head.onmouseover = this.mouseOver_handler.bindAsEventListener(this);
		this.videos_head.onmouseout = this.mouseOut_handler.bindAsEventListener(this);
		this.videos_container.style.left = (1 + this.videos_head.offsetLeft) + 'px';
		this.videos_visible = false;

		this.playlists_head = $('playlists_head');// document.createElement('div');
		this.playlists_head.onclick = this.showHidePlaylists.bindAsEventListener(this);

		this.themes_head = $('themes_head');

		this.embed_players_header = $('embed_players_head');
		this.embed_players_header.style.display = 'none';

		this.login_head = $('login_head');// document.createElement('div');
		this.login_head.onmouseover = this.mouseOver_handler.bindAsEventListener(this);
		this.login_head.onmouseout = this.mouseOut_handler.bindAsEventListener(this);

		this.register_head = $('register_head');// document.createElement('div');
		this.register_head.onmouseover = this.mouseOver_handler.bindAsEventListener(this);
		this.register_head.onmouseout = this.mouseOut_handler.bindAsEventListener(this);

		this.logout_head = $('logout_head'); // document.createElement('div');
		this.logout_head.onmouseover = this.mouseOver_handler.bindAsEventListener(this);
		this.logout_head.onmouseout = this.mouseOut_handler.bindAsEventListener(this);
		this.logout_head.style.display = 'none';

		this.upgrade_head = $('upgrade_head');

		this.welcome_head = $('welcome_head'); // document.createElement('div');
		this.welcome_head.style.display = 'none';
		/*this.welcome_head.onmouseover = UserLimits.showUserInfoBox.bindAsEventListener(UserLimits);
		this.welcome_head.onmouseout = UserLimits.hideUserInfoBox.bindAsEventListener(UserLimits);*/
		this.welcome_head.onclick = UserLimits.switchUserInfoBox.bindAsEventListener(UserLimits);

		this.hovered_head = null;
		if (!user_name || user_name == '') this.playlists_head.style.display = 'none';
	},

	hideAll: function (event) {
		if (this.videos_visible) this.videos_container.style.display = 'none';
		this.videos_visible = false;
	},

	showHideVideos: function (event) {
		this.videos_container.style.left = (1 + this.videos_head.offsetLeft + this.element.offsetLeft) + 'px';
		if (!this.videos_visible) {
			this.hideAll();
			this.videos_container.style.display = 'block';
			this.videos_visible = true;
		} else {
			this.videos_container.style.display = 'none';
			this.videos_visible = false;
		}
	},

	showHidePlaylists: function (event) {
		SavedPlaylists.openList();
	},

	mouseOut_handler: function (event) {
		this.hovered_head = null;
	},

	mouseOver_handler: function (event) {
		var e = Event.element(event);
		if (e != this.playlists_head &&
			e != this.videos_head &&
			e != this.login_head &&
			e != this.logout_head &&
			e != this.register_head) return;
		Event.stop (event);
		this.hovered_head = e;
		if (!this.videos_visible) return;
		if (e == this.videos_head && !this.videos_visible) this.showHideVideos();
	},

	dragHoverMenu: function (event, draggedObj) {
		var menu = Event.element(event);
	},

	dragUnhoverMenu: function (event, draggedObj, menu) {},

	userHasLoggedIn: function () {
		this.hideAll();
		this.login_head.style.display = 'none';
		this.register_head.style.display = 'none';
		this.welcome_head.innerHTML = user_name.toUpperCase();
		this.welcome_head.style.display = 'inline';
		this.logout_head.style.display = 'inline';
		//this.upgrade_head.style.display = 'inline';
		this.playlists_head.style.display = 'inline';
		this.embed_players_header.style.display = 'inline';
	},

	userHasLoggedOut: function () {
		this.hideAll();
		this.welcome_head.style.display = 'none';
		this.logout_head.style.display = 'none';
		this.login_head.style.display = 'inline';
		this.register_head.style.display = 'inline';
		this.playlists_head.style.display = 'none';
		this.embed_players_header.style.display = 'none';
		//this.upgrade_head.style.display = 'none';
	},

	closeAllMenus: function () {
		this.hideAll();
	}
}