FR.initToolbar = function() {
	FR.UI.actions = {
		changePass: new Ext.Action({
			text: FR.T('Change password'), icon: FR.iconsURL+'/textfield_key.gif',
			handler: FR.actions.changePassword,
			hidden: !Settings.allowUserToChangePass
		}),
		cpanel: new Ext.Action({
			text: FR.T('Control Panel'), icon: FR.iconsURL+'/monitor.gif',
			handler:function(){
				FR.UI.popup({
					src: FR.baseURL+'/?module=admin&page=index',
					width: 680, height: 540, constrain: true, maximizable: true, autoDestroy: true
				});
			}
		})
	}
	FR.UI.actions.logout = {
		text: FR.T('Logout'), icon: FR.iconsURL+'/door_out.gif',
		handler:function(){document.location.href = FR.logoutURL;}
	}
	if (Settings.allowUserToChangePass) {
		FR.UI.actions.logout.xtype = 'tbsplit';
		FR.UI.actions.logout.menu = {items: [FR.UI.actions.changePass]};
	}
	
	FR.UI.grid.actions = {
		download: new Ext.Action({
			text: FR.T('Download'),
			icon: FR.iconsURL+'/download.gif',
			handler: function() {return FR.actions.downloadSelected();}
		}),
		download2: new Ext.Action({
			text: FR.T('Download'), icon: FR.iconsURL+'/download.gif',
			handler: function() {return FR.actions.downloadSelected();}
//,
//			menu: {
//				items: [
//					{
//						text: FR.T('..in one zip file'),
//						icon: FR.iconsURL+'/disk_zip.gif',
//						handler: FR.actions.downloadZipped
//					}
//				]
//			}
		}),
		preview: new Ext.Action({
			text: FR.T('Preview'), icon: FR.iconsURL+'/page_white_magnify.gif',
			handler: function() {/*return FR.UI.showPreview();*/return FR.actions.downloadSelected(false, true);}
		})
	}
	
	var openWithItems = [];
	var i=0;
	Ext.each(customActions, function(ca) {
		i++;
		var name = 'custom'+i;
		if (ca.replaceDoubleClickAction) {
			Ext.each(ca.extensions, function(ext) {
				FR.ext[ext] = name;
			});
		}
		FR.UI.grid.actions[name] = new Ext.Action({
			text: FR.T(ca.title), icon: FR.baseURL+ca.icon,
			handler: function() {return FR.actions.customAction(ca);}
		});
		FR.UI.grid.actions[name].settings = ca;
		openWithItems.push(FR.UI.grid.actions[name]);
	});
	FR.UI.grid.actions.openWith = new Ext.Action({
		text: FR.T('Open with..'), icon: FR.iconsURL+'/application.gif',
		handler: function() {return false},
		menu: {items: openWithItems}
	})
	
	FR.UI.grid.actions.email = new Ext.Action({
		text: FR.T('E-mail'), icon: FR.iconsURL+'/email_attach.gif',
		handler: function() {return FR.actions.emailSelectedFiles();}
	});
	FR.UI.grid.actions.weblink = new Ext.Action({
		text: FR.T('Web Link'), icon: FR.iconsURL+'/world_link.gif',
		handler: function() {return FR.actions.WebLink('file');}
	});
	FR.UI.grid.actions.versioning = new Ext.Action({
		text: FR.T('Versioning'), icon: FR.iconsURL+'/page_white_stack.gif',
		handler: function() {return false;},
		menu: new Ext.menu.Menu({
		    id: 'myfiles-contextmenu-versioning',
		    items: [
				new Ext.menu.Item({
					text: FR.T('Previous Versions'),
					icon: FR.iconsURL+'/page_white_stack.gif',
					handler: function() {return FR.actions.openVersions();}
				}),
				new Ext.menu.Item({
					text: FR.T('Lock'),
					icon: FR.iconsURL+'/lock.gif',
					handler: function() {return FR.actions.changeLocking(true);},
					hidden: User.perms.read_only ? true : false
				}),
				new Ext.menu.Item({
					text: FR.T('Unlock'),
					icon: FR.iconsURL+'/lock_open.gif',
					handler: function() {return FR.actions.changeLocking(false);},
					hidden: User.perms.read_only ? true : false
				})
			]
		})
	});
	FR.UI.grid.actions.metadata = new Ext.Action({
		text: FR.T('Metadata'), icon: FR.iconsURL+'/tag_blue.gif',
		handler: function() {return FR.actions.openMetadata()}
	});
	FR.UI.grid.actions.comment = new Ext.Action({
		text: FR.T('Comment'), icon: FR.iconsURL+'/comments.gif',
		handler: function() {return FR.actions.comments();}
	});
	FR.UI.grid.actions.zip = new Ext.Action({
		text: FR.T('Add to zip'), icon: FR.iconsURL+'/page_white_compressed.gif',
		handler: function() {return FR.actions.zipSelected();}
	});
	FR.UI.grid.actions.unzip = new Ext.Action({
		text: FR.T('Unzip'), icon: FR.iconsURL+'/page_white_compressed.gif',
		handler: function() {return FR.actions.unzipSelected();}
	});
	FR.UI.grid.actions.copy = new Ext.Action({
		text: FR.T('Copy'), icon: FR.iconsURL+'/page_copy.gif',
		handler: function() {return FR.actions.copySelected();}
	});
	FR.UI.grid.actions.rename = new Ext.Action({
		text: FR.T('Rename'), icon: FR.iconsURL+'/textfield_rename.gif',
		handler: function() {window.setTimeout(function(){FR.UI.grid.rename();}, 200); return true;}
	});
	FR.UI.grid.actions.restore = new Ext.Action({
		text: FR.T('Restore'), icon: FR.iconsURL+'/thumb_up.gif',
		handler: function() {return FR.actions.restoreSelectedFromTrash();}
	});
	FR.UI.grid.actions.deleteFile = new Ext.Action({
		text: FR.T('Delete'), icon: FR.iconsURL+'/cross.gif',
		handler: function() {return FR.actions.deleteSelected();}
	});
	
	FR.UI.grid.arrayActions = [];
	Ext.iterate(FR.UI.grid.actions, function(k, action) {
		if (action != false && !action.settings) {FR.UI.grid.arrayActions.push(action);}
	});
	
	/* Files toolbar */
	var tbar = [];
	tbar.push({
		text: FR.T('Upload'), icon: FR.iconsURL+'/upload_large.gif',
		id: 'upload', scale: 'medium', handler: FR.UI.showUploadForm,
		disabled: ((!User.perms.upload) ? true : false)
	});
	tbar.push('-');
	tbar.push({
		text: FR.T('File'), icon: FR.iconsURL+'/context_menu.gif',
		overflowText: FR.T('File'),
		id: 'fileSplitBtn', scale: 'medium',
		handler: function() {return false;},
		menu: new Ext.menu.Menu({
			listeners: {beforeshow: function() {FR.UI.grid.prepareFileMenu();}},
			items: FR.UI.grid.arrayActions
		})
	});
	tbar.push('->');
	tbar.push({
		tooltip: FR.T('Select'), icon: FR.iconsURL+'/selection.gif',
		overflowText: FR.T('Select'), cls: 'x-btn-icon',
		menu: new Ext.menu.Menu({
	    	id: 'select',
	    	items: [
				{
					text: FR.T('Select All'),
					handler: function() {FR.UI.grid.panel.selModel.selectAll();}
				},
				{
					text: FR.T('Deselect All'),
					handler: function() {
						FR.UI.grid.panel.selModel.clearSelections();
					}
				}]
		})
	});
	tbar.push('-');
	tbar.push({
		tooltip: FR.T('Thumbnail view'), icon: FR.iconsURL+'/application_view_icons.gif',
		overflowText: FR.T('Thumbnail view'),
		id: 'tbarView-thumbnails', cls: 'x-btn-icon',
		toggleGroup: 'view', enableToggle: true,
		toggleHandler: function() {if (FR.currentSection != 'trash') {FR.UI.changeView('thumbnails');}}
	});
	tbar.push({
		tooltip: FR.T('Detailed view'), icon: FR.iconsURL+'/application_view_list.gif',
		overflowText: FR.T('Detailed view'),
		id: 'tbarView-list', cls: 'x-btn-icon',
		toggleGroup: 'view', enableToggle: true,
		toggleHandler: function() {FR.UI.changeView('list');}
	});
	tbar.push('-');
	tbar.push({
		text: FR.T('Refresh'), icon: FR.iconsURL+'/arrow_refresh_small.gif',
		overflowText: FR.T('Refresh'),
		handler: function() {
			FR.UI.grid.load(FR.currentPath);
			if (FR.currentSection != 'trash') {
				if (FR.UI.tree.currentSelectedNode.loading == false && FR.UI.tree.currentSelectedNode.loaded == true) {
					FR.UI.tree.reloadNode(FR.UI.tree.currentSelectedNode);
				}
			}
		}
	});
	FR.UI.gridToolbar.config = tbar;
	
	
	FR.UI.tree.actions = {
		search: new Ext.Action({
			text: FR.T('Search'), icon: FR.iconsURL+'/folder_find.gif', cls: 'x-btn-text-icon',
			handler: function() {return FR.actions.search();}
		}),
		download: new Ext.Action({
			text: FR.T('Download'), icon: FR.iconsURL+'/disk_zip.gif',
			handler: function() {return FR.actions.downloadSelectedFolder();}
		}),
		share: new Ext.Action({
			text: FR.T('Share'), icon: FR.iconsURL+'/folder_share.gif',
			handler: function() {return FR.actions.share();}
		}),
		weblink: new Ext.Action({
			text: FR.T('Web Link'), icon: FR.iconsURL+'/world_link.gif',
			handler: function() {return FR.actions.WebLink('folder');}
		}),
		zip: new Ext.Action({
			text: FR.T('Add to zip'), icon: FR.iconsURL+'/page_white_compressed.gif',
			handler: function() {return FR.actions.zipSelectedFolder();}
		}),
		newFolder: new Ext.Action({
			text: FR.T('New sub-folder'), icon: FR.iconsURL+'/folder_add.gif',
			handler: function() {return FR.actions.newFolder(0);}
		}),
		copy: new Ext.Action({
			text: FR.T('Copy'), icon: FR.iconsURL+'/copy_folder.gif',
			handler: function() {return FR.actions.copySelected(true);}
		}),
		pasteFolder: new Ext.Action({
			text: FR.T('Paste copied folder'), icon: FR.iconsURL+'/page_paste.gif',
			handler: function() {return FR.actions.pasteCopied(false, true);}
		}),
		pasteFiles: new Ext.Action({
			text: FR.T('Paste copied files'), icon: FR.iconsURL+'/page_paste.gif',
			handler: function() {return FR.actions.pasteCopied();}
		}),
		rename: new Ext.Action({
			text: FR.T('Rename'), icon: FR.iconsURL+'/textfield_rename.gif',
			handler: function() {
				if (FR.UI.tree.contextMenuVisible) {
					var treeNode = FR.UI.tree.contextMenuSelectedNode;
				} else {
					var treeNode = FR.UI.tree.currentSelectedNode;
				}
				FR.UI.tree.treeEditor.triggerEdit(treeNode);
				return true;
			}
		}),
		deleteFolder: new Ext.Action({
			text: FR.T('Delete'), icon: FR.iconsURL+'/cross.gif',
			handler: function() {return FR.actions.deleteFolder();}
		}),
		properties: new Ext.Action({
			text: FR.T('Properties'), icon: FR.iconsURL+'/folder_options.gif',
			handler: function() {return FR.actions.folderOptions();}
		})
	};

	FR.UI.tree.arrayActions = [];
	Ext.iterate(FR.UI.tree.actions, function(k, action) {
		if (action != false && !action.settings) {FR.UI.tree.arrayActions.push(action);}
	});
	
	/* Folders toolbar */
	var tbar = [];
	tbar.push(FR.UI.folderToolbarSearch = new Ext.Action({
		text: FR.T('Search'), icon: FR.iconsURL+'/search_folder.gif', scale: 'medium',
		handler: function() {return FR.actions.search();}
	}));
	if (!User.perms.read_only) {
		tbar.push('-');
	}
	tbar.push({
		text: FR.T('New folder'), icon: FR.iconsURL+'/add_folder.gif',
		id: 'folderMenu', xtype: 'tbsplit', scale: 'medium',
		hidden: ((User.perms.read_only) ? true : false),
		handler: function(){ FR.actions.newFolder(1);},
		menu: new Ext.menu.Menu({
			listeners: {
				beforeshow: function() {FR.UI.tree.updateActions(FR.UI.tree.currentSelectedNode);}
			},
			items: [FR.UI.tree.actions.download, FR.UI.tree.actions.share, FR.UI.tree.actions.weblink, FR.UI.tree.actions.zip, FR.UI.tree.actions.copy, FR.UI.tree.actions.pasteFolder, FR.UI.tree.actions.pasteFiles, FR.UI.tree.actions.rename, FR.UI.tree.actions.deleteFolder, FR.UI.tree.actions.properties]
		})
	});
	FR.UI.treeToolbar.config = tbar;
	
	/* Bottom toolbar */
	FR.UI.bottomToolbar.config = [FR.UI.actions.logout];
	if (User.isAdmin) {
		FR.UI.bottomToolbar.config.push('-');
		FR.UI.bottomToolbar.config.push(FR.UI.actions.cpanel);
	}
	FR.UI.bottomToolbar.config.push('->');	
}

FR.UI.treeToolbar.getItem = function(itemId) {
	return Ext.getCmp('FR-Grid-Panel').getTopToolbar().items.map[itemId];
}
