var windows = new Array();

function openWin(name, message) {
  var exists = null;
  if ( !message ) { message = winName; }
  for ( i = 0; i < windows.length; i++ ) {
    if ( windows[i]['name'] == name ) {
      exists = i;
      $(windows[i]['id']).style.display = 'block';
    } else {
      $(windows[i]['id']).style.display = 'none';
    }
  }
  if ( exists != null ) {
    return false;
  } else {
    temp = new Window( {
      className: 'mackwin', 
      title: message,
      destroyOnClose: true,
      resizable: true,
      minimizable: false,
      maximizable: false,
      onClose:function() {
        for(i = 0; i < windows.length; i++) {
          elem = windows.pop();
          $(elem['name'] + "Win").style.display = 'none';
        }
        Windows.closeAll();
      }
    } ); 
    temp.setContent( name + "Win", true, true );
    temp.setDestroyOnClose();
    temp.showCenter(true);
    windows.push({ id:temp.getId(), name:name });
  }
  return false;
}

function logout(url) {
  openWin("loading", "Logging you out...");
  window.location.href = url;
  return false;
}

function commentSubmit() {
  alert('Thanks for your comment.');
  if ( $('album').value != "" ) {
    $('comment').value = "<!-- mackGallery:" + $('album').value + " --> " + $('comment').value;
    $('redirect_to').value = window.location.href;
  }
  Windows.closeAll();
}
