function FileBrowser() {

  this.id = 'fileBrowserDialog';
  this.startDelay = 1000;
  this.stepDelay = 500;
  this.finishDelay = 3000;
  this.dialogDiv = '<div class="ui-corner-all" id="fileBrowserDialog"></div>';

  this.start = function() {
    this.initDialogDiv();
    this.getLoader();
    var t = setTimeout('fileBrowser.show()', this.startDelay);
  }

  this.initDialogDiv = function() {
    if (undefined == $('#'+this.id) || null == $('#'+this.id).html()) {
      $('body').append(this.dialogDiv);
    }
  }

  this.show = function() {
    $.get('/fileBrowser.jsp', function(data){
      $('#'+fileBrowser.id).html($.trim(data));
    });  
  }

  this.submit = function() {
    this.getLoader();
    this.processRequest();
  }
  
  this.processRequest = function() {
  }

  this.submitExec = function() {
    var t = setTimeout('fileBrowser.closeDialog()', this.finishDelay);
  }
  
  this.closeDialog = function() {
    $('#'+fileBrowser.id).hide();
    $('#'+fileBrowser.id).dialog('close');
  }
  
  this.getLoader = function() {
    $.get('/loader.jsp', function(data){
	  $('#'+fileBrowser.id).html($.trim(data));
      fileBrowser.getDialog();
	});
  }

  this.getDialog = function() {
    $('#'+fileBrowser.id).dialog({
      autoOpen: true,
	  bgiframe: true,
	  height: 440,
	  width: 780,
	  resizable: false,
	  draggable: false,
	  modal: true,
	  closeOnEscape: false,
	  title: 'Image File Browser',
	  zIndex: 9999 
	});
	$('#'+fileBrowser.id).show();
	$('#'+fileBrowser.id).dialog('open');    
  }
  
  this.deleteFile = function(file) {
    if (file.length > 0) {
	  $.get('/fileDelete.jsp?file='+file, function() {
	    fileBrowser.start();
	  });
    }
  }
  
}

var fileBrowser = new FileBrowser();