diff --git a/admin-message-node.tpl.php b/admin-message-node.tpl.php
index cae65a4..fe27f71 100644
--- a/admin-message-node.tpl.php
+++ b/admin-message-node.tpl.php
@@ -1,8 +1,23 @@
 <div class="admin-message sticky">
 
   <?php // Changing the class on the link will make the javascript no longer function. ?>
-  <?php print l(t('Close'), 'admin_message/close/'. $node->nid, array('attributes'=>array('class' => 'admin-message-close', 'title' => t('Close this message')))); ?>
+  <?php
+  if (user_access('close admin messages')) {
+    print l(
+      'x',
+      'admin_message/close/'. $node->nid,
+      array(
+        'attributes' => array(
+          'class' => array(
+            'admin-message-close',
+          ),
+          'title' => t('Close this message')
+        )
+      )
+    );
+  }
+  ?>
 
-  <?php print node_view($node); ?>
+  <?php print drupal_render(node_view($node)); ?>
 
 </div>
\ No newline at end of file
diff --git a/admin_message.css b/admin_message.css
index c080235..2c90c6e 100644
--- a/admin_message.css
+++ b/admin_message.css
@@ -1,4 +1,10 @@
 
-.admin-message .close {
+.admin-message-close {
   float: right;
+  margin: 15px;
+  font-family: Helvetica;
+}
+
+a.admin-message-close:hover {
+  text-decoration:none;
 }
diff --git a/admin_message.info b/admin_message.info
index 45cca5d..ea0bb9f 100644
--- a/admin_message.info
+++ b/admin_message.info
@@ -1,10 +1,10 @@
 
 name = Admin message
 description = Display messages that can be individually closed by logged in users.
-core = 6.x
-; Information added by drupal.org packaging script on 2011-02-25
-version = "6.x-1.x-dev"
-core = "6.x"
-project = "admin_message"
-datestamp = "1298618807"
-
+core = 7.x
+files[] = admin-message-node.tpl.php
+files[] = admin_message.css
+files[] = admin_message.install
+files[] = admin_message.js
+files[] = admin_message.module
+files[] = admin_message_form.js
diff --git a/admin_message.install b/admin_message.install
index d1514f9..e674acb 100644
--- a/admin_message.install
+++ b/admin_message.install
@@ -9,24 +9,24 @@
  */
 function admin_message_schema() {
   $schema['admin_message'] = array(
-    'description' => t('TODO'),
+    'description' => 'TODO',
     'fields' => array(
       'nid' => array(
-        'description' => t('TODO'),
+        'description' => 'TODO',
         'type' => 'int',
         'size' => 'small',
         'not null' => TRUE,
         'default' => 0,
       ),
       'keep_new' => array(
-        'description' => t('TODO'),
+        'description' => 'TODO',
         'type' => 'int',
         'size' => 'tiny',
         'not null' => TRUE,
         'default' => 0,
       ),
       'php_visibility' => array(
-        'description' => t('TODO'),
+        'description' => 'TODO',
         'type' => 'text',
         'size' => 'small',
         'not null' => TRUE,
@@ -35,24 +35,24 @@ function admin_message_schema() {
     'primary key' => array('nid'),
   );
   $schema['admin_message_close'] = array(
-    'description' => t('TODO'),
+    'description' => 'TODO',
     'fields' => array(
       'nid' => array(
-        'description' => t('TODO'),
+        'description' => 'TODO',
         'type' => 'int',
         'size' => 'small',
         'not null' => TRUE,
         'default' => 0,
       ),
       'uid' => array(
-        'description' => t('TODO'),
+        'description' => 'TODO',
         'type' => 'int',
         'size' => 'small',
         'not null' => TRUE,
         'default' => 0,
       ),
     ),
-    'primary key' => array('nid, uid'),
+    'primary key' => array('nid', 'uid'),
   );
   return $schema;
 }
@@ -61,13 +61,14 @@ function admin_message_schema() {
  * Implementation of hook_install().
  */
 function admin_message_install() {
-  drupal_install_schema('admin_message');
-
   // Set to published and sticky as default for content type.
   variable_set('node_options_admin_message' , array('status', 'sticky'));
   // Disable comments for this content type.
   variable_set('comment_admin_message', '0');
 
+  node_types_rebuild();
+  $types = node_type_get_types();
+  node_add_body_field($types['admin_message'], t('Message'));
   drupal_set_message(t('<em>Admin message</em> was installed. Enable the block "Admin messages" to display messages to users.'));
 }
 
@@ -75,6 +76,5 @@ function admin_message_install() {
  * Implementation of hook_uninstall().
  */
 function admin_message_uninstall() {
-  drupal_uninstall_schema('admin_message');
 
 }
diff --git a/admin_message.js b/admin_message.js
index a087deb..a4c60b7 100644
--- a/admin_message.js
+++ b/admin_message.js
@@ -1,13 +1,11 @@
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
+(function ($) {
   $(document).ready(function() {  
     // Close
-    $("#block-admin_message-admin_message a.admin-message-close").click(function() {
+    $("#block-admin-message-admin-message a.admin-message-close").click(function(event) {
       var href = $(this).attr("href");
       $.get(href);
       $(this).parent().slideUp('fast');
-      return false;
+      event.preventDefault();
     });
   });
-}
+})(jQuery)
\ No newline at end of file
diff --git a/admin_message.module b/admin_message.module
index 90c9a56..df37752 100644
--- a/admin_message.module
+++ b/admin_message.module
@@ -9,92 +9,100 @@
  * Implementation of hook_menu().
  */
 function admin_message_menu() {
- $items = array();
+  $items = array();
 
- $items['admin_message/close/%'] = array(
+  $items['admin_message/close/%'] = array(
     'page callback' => 'admin_message_close',
     'page arguments' => array(2),
     'access arguments' => array('close admin messages'),
     'type' => MENU_CALLBACK,
   );
-  
+
   return $items;
 }
 
 /**
- * Implementation of hook_nodeapi().
+ * Implements hook_node_load().
  */
-function admin_message_nodeapi(&$node, $op, $teaser, $page) {
-  switch ($op) {
-    case 'load':
-      if ($node->type == 'admin_message') {
-        $object = db_fetch_object(db_query('SELECT keep_new FROM {admin_message} WHERE nid = %d', $node->nid));
-        return array('admin_message_keep_new' => $object->keep_new);
-      }
-      break;
-
-    case 'insert':
-      if ($node->type == 'admin_message') {
-        db_query("INSERT INTO {admin_message} (nid, keep_new, php_visibility) VALUES (%d, %d, '%s')", $node->nid, $node->admin_message_keep_new, trim($node->php_visibility));
-      }
-      break;
-
-    case 'update':
-      if ($node->type == 'admin_message') {
-        db_query('DELETE FROM {admin_message} WHERE nid = %d', $node->nid);
-        db_query("INSERT INTO {admin_message} (nid, keep_new, php_visibility) VALUES (%d, %d, '%s')", $node->nid, $node->admin_message_keep_new, trim($node->php_visibility));
-      }
-      break;
+function admin_message_node_load($nodes, $types) {
+  if (!in_array('admin_message', $types)) {
+    return;
+  }
+  foreach ($nodes as $node) {
+    if ($node->type == 'admin_message') {
+      $object = db_query('SELECT keep_new FROM {admin_message} WHERE nid = :nid', array(':nid' => $node->nid))->fetchObject();
+      $node->admin_message_keep_new = $object->keep_new;
+    }
+  }
+}
 
-    case 'delete':
-      if ($node->type == 'admin_message') {
-        db_query('DELETE FROM {admin_message} WHERE nid = %d', $node->nid);
-        db_query('DELETE FROM {admin_message_close} WHERE nid = %d', $node->nid);
-      }
-      break;
+/**
+ * Implements hook_node_insert().
+ */
+function admin_message_node_insert($node) {
+  if ($node->type == 'admin_message') {
+    $php_visibility = trim($node->php_visibility);
+    db_insert('admin_message')
+    ->fields(
+      array(
+        'nid' => $node->nid,
+        'keep_new' => $node->admin_message_keep_new,
+        'php_visibility' => empty($php_visibility) ? '' : trim($node->php_visibility),
+      )
+    )
+    ->execute();
+  }
+}
 
-    case 'view':
-      break;
+/**
+ * Implements hook_node_update().
+ */
+function admin_message_node_update($node) {
+  if ($node->type == 'admin_message') {
+    db_query('DELETE FROM {admin_message} WHERE nid = :nid', array(':nid' => $node->nid));
+    db_query("INSERT INTO {admin_message} (nid, keep_new, php_visibility) VALUES (:nid, :keep_new, ':php')",
+      array(
+        ':nid' => $node->nid,
+        ':keep_new' => $node->admin_message_keep_new,
+        ':php' => trim($node->php_visibility)
+      )
+    );
   }
 }
 
 function admin_message_close($nid) {
   global $user;
-  db_query('DELETE FROM {admin_message_close} WHERE nid = %d AND uid = %d', $nid, $user->uid);
-  db_query('INSERT INTO {admin_message_close} (nid, uid) VALUES (%d, %d)', $nid, $user->uid);
+  db_query('DELETE FROM {admin_message_close} WHERE nid = :nid AND uid = :uid', array(':nid' => $nid, ':uid' => $user->uid));
+  db_query('INSERT INTO {admin_message_close} (nid, uid) VALUES (:nid, :uid)', array(':nid' => $nid, ':uid' => $user->uid));
   drupal_goto();
 }
 
 /**
- * Implementation of hook_user.
+ * Implementation of hook_user_delete.
  */
-function admin_message_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
-    db_query('DELETE FROM {admin_message_close} WHERE uid = %d', $user->uid);
-  }
+function admin_message_user_delete($account) {
+  db_query('DELETE FROM {admin_message_close} WHERE uid = :uid', array(':uid' => $user->uid));
+}
+
+/**
+ * Implements hook_block_info
+ */
+function admin_message_block_info() {
+  $blocks['admin_message']['info'] = t('Admin messages');
+  return $blocks;
 }
 
 /**
- * Implementation of hook_block().
- *
- * op: admin_message 
- * 
+ * Implements hook_block_view().
  */
-function admin_message_block($op = 'list', $delta = 0) {
-  switch ($op) {
-    case 'list':
-      $blocks['admin_message']['info'] = t('Admin messages');
-      return $blocks;
-
-    case 'view':
-      switch ($delta) {
-        case 'admin_message':
-          $block['subject'] = '';
-          $block['content'] = admin_message_list_messages();
-          break;
-      }
-      return $block;
+function admin_message_block_view($delta = "") {
+  switch ($delta) {
+    case 'admin_message':
+      $block['subject'] = '';
+      $block['content'] = admin_message_list_messages();
+      break;
   }
+  return $block;
 }
 
 /**
@@ -102,16 +110,29 @@ function admin_message_block($op = 'list', $delta = 0) {
  */
 function admin_message_list_messages() {
   global $user;
+  if (!$user->uid) {
+    return ''; //not for anonymous users
+  }
   $output = '';
-  $result = db_query(db_rewrite_sql("SELECT n.nid, n.created, a.keep_new, a.php_visibility FROM {node} n LEFT JOIN {admin_message} a ON n.nid = a.nid WHERE n.sticky = 1 AND n.status = 1 AND n.type = 'admin_message' ORDER BY n.created DESC"));
+  //$result = db_query(db_rewrite_sql("SELECT n.nid, n.created, a.keep_new, a.php_visibility FROM {node} n LEFT JOIN {admin_message} a ON n.nid = a.nid WHERE n.sticky = 1 AND n.status = 1 AND n.type = 'admin_message' ORDER BY n.created DESC"));
+  $q = db_select('node', 'n');
+  $q->join('admin_message', 'a', 'n.nid = a.nid');
+  $q->fields('n', array('nid', 'created'));
+  $q->fields('a', array('keep_new', 'php_visibility'));
+  $q->condition('n.sticky', 1, '=');
+  $q->condition('n.status', 1, '=');
+  $q->condition('n.type', 'admin_message', '=');
+  $q->orderBy('n.created', 'DESC');
+  $result = $q->execute();
   $messages = FALSE;
-  while ($item = db_fetch_object($result)) {
-    $php_visibility = empty($item->php_visibility) ? TRUE : drupal_eval($item->php_visibility);
-    $closed_by_user = db_fetch_object(db_query("SELECT a.nid FROM {admin_message_close} a WHERE a.nid = %d AND a.uid = %d", $item->nid, $user->uid));
-
+  while ($item = $result->fetchObject()) {
+    $php_visibility = TRUE;
+    if (module_exists('php')) {
+      $php_visibility = empty($item->php_visibility) ? TRUE : php_eval($item->php_visibility);
+    }
+    $closed_by_user = db_query("SELECT a.nid FROM {admin_message_close} a WHERE a.nid = :nid AND a.uid = :uid", array(':nid' => $item->nid, ':uid' => $user->uid))->fetchObject();
     if (empty($closed_by_user) && ($item->created >= $user->created || $item->keep_new) && $php_visibility) {
-      $node = node_build_content(node_load($item->nid));
-      $output .= theme('admin_message_message', $node);
+      $output .= theme('admin_message_message', array('node' => node_load($item->nid)));
     }
 
     $messages = TRUE;
@@ -119,8 +140,8 @@ function admin_message_list_messages() {
 
   if ($messages) {
     // Insert JavaScript and CSS if messages are displayed.
-    drupal_add_js(drupal_get_path('module', 'admin_message') .'/admin_message.js', 'module');
-    drupal_add_css(drupal_get_path('module', 'admin_message') .'/admin_message.css', 'module');
+    drupal_add_js(drupal_get_path('module', 'admin_message') . '/admin_message.js', 'module');
+    drupal_add_css(drupal_get_path('module', 'admin_message') . '/admin_message.css', 'module');
   }
   return $output;
 }
@@ -139,34 +160,45 @@ function admin_message_form_alter(&$form, &$form_state, $form_id) {
     // "Hijack" the sticky option.
     $sticky_field = $form['options']['sticky'];
     unset($form['options']['sticky']);
-    $form['admin_message']['sticky'] =  $sticky_field;
+    $form['admin_message']['sticky'] = $sticky_field;
     $form['admin_message']['sticky']['#title'] = t('Show message (sticky)');
 
     // Keep new.
     $form['admin_message']['admin_message_keep_new'] = array(
       '#type' => 'checkbox',
       '#title' => t('Always show this message to new users'),
-      '#default_value' => isset($form['#node']->admin_message_keep_new) ? $form['#node']->admin_message_keep_new : variable_get('admin_message_keep_new_'. $type, 0),
-      '#prefix' => '<div id="admin-message-toggle">',
+      '#default_value' => isset($form['#node']->admin_message_keep_new) ? $form['#node']->admin_message_keep_new : 0,
+      '#states' => array(
+        'visible' => array(
+          'input[name="sticky"]' => array('checked' => TRUE),
+        ),
+      ),
     );
 
     // PHP visibility form.
-    $result = db_fetch_object(db_query('SELECT php_visibility FROM {admin_message} WHERE nid = %d', $form['nid']['#value']));
-    $php_visibility_code = $result->php_visibility;
-    if (user_access('use PHP for block visibility')) {
+    $result = db_query('SELECT php_visibility FROM {admin_message} WHERE nid = :nid', array(':nid' => $form['nid']['#value']))->fetchObject();
+    $php_visibility_code = $result ? $result->php_visibility : '';
+    if (user_access('use PHP for setting') && module_exists('php')) {
       $form['admin_message']['php_visibility'] = array(
         '#type' => 'textarea',
         '#title' => t('Show if the following PHP code returns <code>true</code> (PHP-mode, experts only)'),
         '#description' => t('Enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '<?php ?>')),
         '#default_value' => $php_visibility_code,
-        '#suffix' => '</div>',
-     );
+        '#states' => array(
+        'visible' => array(
+          'input[name="sticky"]' => array('checked' => TRUE),
+        ),
+      ),
+      );
     }
     else {
-      $form['admin_message']['admin_message_keep_new']['#suffix'] = '</div>';
+      $form['admin_message']['php_visibility'] = array(
+        '#type' => 'value',
+        '#value' => '',
+      );
     }
 
-    drupal_add_js(drupal_get_path('module', 'admin_message') .'/admin_message_form.js', 'module');
+    drupal_add_js(drupal_get_path('module', 'admin_message') . '/admin_message_form.js', 'module');
   }
 }
 
@@ -186,7 +218,7 @@ function admin_message_node_info() {
   $items = array(
     "admin_message" => array(
       "name" => t("Admin message"),
-      "module" => "admin_message",
+      "base" => "admin_message",
       "description" => t("Use admin messages to display messages, usually status messages or similar to logged in users."),
       "has_title" => "1",
       "title_label" => t("Title"),
@@ -198,10 +230,10 @@ function admin_message_node_info() {
 }
 
 /**
- * Implementation of hook_access().
+ * Implementation of hook_node_access().
  */
-function admin_message_access($op, $node, $account) {
-  return node_content_access($op, $node, $account);
+function admin_message_node_access($op, $node, $account) {
+  return node_node_access($op, $node, $account);
 }
 
 /**
@@ -212,15 +244,13 @@ function admin_message_form($node, $form_state) {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function admin_message_perm() {
-  $name = 'admin_message';
-  $perms = array();
-  $perms[] = 'create '. $name .' content';
-  $perms[] = 'delete own '. $name .' content';
-  $perms[] = 'delete any '. $name .' content';
-  $perms[] = 'edit own '. $name .' content';
-  $perms[] = 'edit any '. $name .' content';
-  return $perms;
+function admin_message_permission() {
+  return array(
+    'close admin messages' => array(
+      'title' => t('Close admin messages'),
+      'description' => t('Give user access to closing admin messages'),
+    ),
+  );
 }
diff --git a/admin_message_form.js b/admin_message_form.js
deleted file mode 100644
index 17da3dc..0000000
--- a/admin_message_form.js
+++ /dev/null
@@ -1,12 +0,0 @@
-
-// Global Killswitch
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {  
-    // Hide the other options if "Show message (sticky)" is not checked.    
-    $("#admin-message-toggle")[['hide', 'show'][Number($("#edit-sticky")[0].checked)]]();
-    
-    $("#edit-sticky").click(function() {
-      $("#admin-message-toggle")[['hide', 'show'][Number(this.checked)]]();
-    });
-  });
-}
