.onLoad <- function(lib, pkg)
{
  ## Load the rjags wrapper ...
  libdir <- "@JAGS_LIB@"
  if (is.null(getOption("jags.libdir"))) {
      options("jags.libdir" = libdir)
  }
  jagsLib <- file.path(libdir, 'libjags.so')
  if (file.exists(jagsLib)) {
    dyn.load(jagsLib)
  } else {
    warning(sprintf('Could not find library %s.  CoGAPS may not run properly.',
                    jagsLib)) 
  }
 
  library.dynam("CoGAPS", pkg, lib, local=FALSE)

  ## ... and the modules
  moddir <- "@JAGS_MODULES@"
  if (is.null(getOption("jags.moddir"))) {
      options("jags.moddir" = moddir)
  }
  load.module("basemod")
  load.module("gaps")

  .Call("init_jags_console", PACKAGE="CoGAPS")

  ## Set progress bar type
  if (is.null(getOption("jags.pb"))) {
      options("jags.pb"="text")
  }
}