diff --git a/bluga.info b/bluga.info
index 1dea86f..37395da 100644
--- a/bluga.info
+++ b/bluga.info
@@ -1,4 +1,7 @@
+;$Id: bluga.info,v 1.1.4.1 2009/11/01 05:27:51 hanenkamp Exp $
 
-core = 6.x
+core = 7.x
 name = Bluga Webthumb
 description = Access the Bluga webthumb API from Drupal
+configure = admin/config/media/bluga
+
diff --git a/bluga.install b/bluga.install
index e7894ef..05dbe88 100644
--- a/bluga.install
+++ b/bluga.install
@@ -1,4 +1,5 @@
 <?php
+// $Id: bluga.install,v 1.1.4.2 2009/11/07 21:47:01 hanenkamp Exp $
 
 /**
  * @file
diff --git a/bluga.module b/bluga.module
index a99baf1..db3e064 100644
--- a/bluga.module
+++ b/bluga.module
@@ -1,4 +1,5 @@
 <?php
+// $Id: bluga.module,v 1.7.2.5 2009/11/02 07:06:54 hanenkamp Exp $
 
 /**
  * @file
@@ -34,7 +35,7 @@ function bluga_settings() {
     '#type' => 'textfield',
     '#title' => t('Directory to Cache Webthumbs'),
     '#description' => t('This is where the thumbs will be served from locally after they have been generated by bluga.net.'),
-    '#field_prefix' => file_directory_path() . '/',
+    '#field_prefix' => variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files') . '/',
     '#default_value' => variable_get('bluga_webthumb_cache', ''),
     '#required' => TRUE,
     '#maxlength' => 100,
@@ -45,14 +46,30 @@ function bluga_settings() {
     $status = bluga_credit_status();
 
     $markup = '<h3>' . t('Bluga Credit Status') . '</h3>';
-
-    $rows[] = array( t('Used this month'), $status['used'] );
-    $rows[] = array( t('Cached Easythumbs this month'), $status['cached'] );
-    $rows[] = array( t('Subscription credits'), $status['subscription'] );
-    $rows[] = array( t('Reserve credits'), $status['reserve'] );
-    $markup .= theme_table( array( t('Statistic'), t('Tokens') ), $rows );
+    
+		$header = array( 
+	    array('data' => t('Statistic')),
+			array('data' => t('Tokens')),
+		);
+    $rows[] = array( 
+		  array('data' => t('Used this month')),
+			array('data' => $status['used']),
+		);
+    $rows[] = array( 
+		  array('data' => t('Cached Easythumbs this month')),
+			array('data' => $status['cached']),
+		);
+    $rows[] = array( 
+		  array('data' => t('Subscription credits')),
+			array('data' => $status['subscription']),
+		);
+    $rows[] = array( 
+		  array('data' => t('Reserve credits')),
+			array('data' => $status['reserve']),
+		);
+    $markup .= theme('table', array('header' => $header, 'rows' => $rows));
   
-    $form['credit_status'] = array( '#value' => $markup );
+    $form['credit_status'] = array( '#markup' => $markup );
   }
 
   return system_settings_form($form);
@@ -62,9 +79,11 @@ function bluga_settings() {
  * This makes sure that the given cache directory exists.
  */
 function bluga_settings_validate($form, &$form_state) {
-  $files_dir = file_directory_path();
+  $files_dir = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');
   $cache_dir = $files_dir . '/' . $form_state['values']['bluga_webthumb_cache'];
-  file_check_directory($cache_dir, TRUE, 'bluga_webthumb_cache');
+  if (!file_prepare_directory($cache_dir, TRUE)) {
+	  form_set_error('bluga_webthumb_cache', 'The webthumb cache directory could not be created.');
+	}
 }
 
 /**
@@ -73,7 +92,7 @@ function bluga_settings_validate($form, &$form_state) {
 function bluga_menu() {
   $items = array();
 
-  $items['admin/settings/bluga'] = array(
+  $items['admin/config/media/bluga'] = array(
     'title' => 'Bluga API settings',
     'description' => 'Setup your API key and other basic settings.',
     'page callback' => 'drupal_get_form',
@@ -96,23 +115,22 @@ function _bluga_webthumb_check($url, $size, $refetch, $options) {
     return NULL;
   }
   elseif ($refetch == 'never') {
-    $result = db_query("SELECT * FROM {bluga_request} WHERE url = '%s'", $url);
+    $result = db_query("SELECT * FROM {bluga_request} WHERE url = :url", array(':url' => $url))->fetchAllAssoc('rid');
   }
   else {
     $time = strftime('%Y-%m-%d %H:%M:%S', strtotime($refetch));
     $result = db_query("
       SELECT * 
       FROM {bluga_request} 
-      WHERE url = '%s' AND submission_time > '%s'
+      WHERE url = :url AND submission_time > :time
       ORDER BY submission_time DESC
-    ", $url);
+    ", array(':url' => $url, ':time' => $time))->fetchAllAssoc('rid');
   }
-
-  while ($request = db_fetch_object($result)) {
+	foreach ($result as $request) {
     if (isset($options['browser']) && ($options['browser']['width'] != $request->browser_width || $options['browser']['height'] != $request->browser_height)) {
       continue;
     }
-    if ($options['fullthumb'] && !$request->fullthumb) {
+    if (isset($options['fullthumb']) && !$request->fullthumb) {
       continue;
     }
     if (isset($options['custom']) && ($options['custom']['width'] != $request->custom_width || $options['custom']['height'] != $request->custom_height)) {
@@ -195,6 +213,8 @@ function _bluga_webthumb_request($options) {
       return FALSE;
     }
 
+		// not needed in d7
+		/*
     $fields = implode(',', array_keys($args));
     $places = implode(',', array_fill(0, count($args), "'%s'"));
     $values = array_values($args);
@@ -202,13 +222,16 @@ function _bluga_webthumb_request($options) {
     $insert_result = db_query(
       'INSERT INTO {bluga_request}(' . $fields . ') VALUES (' . $places . ')', $values
     );
+		*/
+		
+		$insert_result = db_insert('bluga_request')->fields($args)->execute();
 
     if ($insert_result) {
       $result = db_query(
-        "SELECT * FROM {bluga_request} WHERE job_id = '%s'", $job['id']
+        "SELECT * FROM {bluga_request} WHERE job_id = :job", array(':job' => $job['id'])
       );
 
-      return db_fetch_object($result);
+      return $result->fetchAssoc();
     }
     else {
       watchdog('content', 'unable to store Bluga WebThumb request for job %job_id',
@@ -224,14 +247,14 @@ function _bluga_webthumb_request($options) {
 }
 
 function _bluga_webthumb_directory() {
-  $files_dir = file_directory_path();
+  $files_dir = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');
   return $files_dir . '/' . variable_get('bluga_webthumb_cache', '');
 }
 
 function _bluga_webthumb_pickup_fetch($request, $state, $size) {
   $response = bluga_fetch($request->job_id, $size);
 
-  if ($response->error) {
+  if (isset($response->error)) {
     watchdog('content', 'unable to download %size thumbnail from job %job_id for Bluga WebThumb request',
       array('%size' => $size, '%job_id' => $request->job_id), WATCHDOG_ERROR);
     return FALSE;
@@ -306,11 +329,21 @@ function _bluga_webthumb_pickup($request, $size) {
         $state = $status[$request->job_id];
         if ($state['completionTime']) {
           $filename = _bluga_webthumb_pickup_fetch($request, $state, $size);
-          db_query("
+          // Changed to db_update in d7
+					/*
+					db_query("
             UPDATE {bluga_request} 
             SET pickup_url = '%s', completion_time = '%s', filename_$size = '%s'
             WHERE job_id = '%s'
           ", $state['pickup'], $state['completionTime'], $filename, $request->job_id);
+					*/
+					db_update('bluga_request')
+						->fields(array(
+						  'pickup_url' => $state['pickup'],
+							'completion_time' => $state['completionTime'],
+							'filename_' . $size => $filename))
+						->condition('job_id', $request->job_id)
+					  ->execute();
 
           $request->pickup_url = $state['pickup'];
           $request->completion_time = $state['completionTime'];
@@ -475,10 +508,10 @@ function _bluga_webthumb_pickup($request, $size) {
  */
 function bluga_webthumb($url, $size = 'medium', $refetch = 'never', $options = array()) {
   $css_file = drupal_get_path('module', 'bluga') . '/bluga.css';
-  drupal_add_css($css_file);
+  drupal_add_css($css_file, array('group' => CSS_DEFAULT));
 
   $js_file = drupal_get_path('module', 'bluga') . '/bluga.js';
-  drupal_add_js($js_file);
+  drupal_add_js($js_file, 'file');
 
   $options['url'] = $url;
 
@@ -511,9 +544,9 @@ function bluga_ajax_fetch() {
   }
 
   $result = db_query(
-    "SELECT * FROM {bluga_request} WHERE rid = '%s'", $rid
+    "SELECT * FROM {bluga_request} WHERE rid = :rid", array(':rid' => $rid)
   );
-  $request = db_fetch_object($result);
+  $request = $result->fetchAssoc();
   if (!$request) {
       watchdog('content', 'cannot locate a Bluga WebThumb request for request ID %rid',
         array( '%rid' => $rid ), WATCHDOG_ERROR);
diff --git a/bluga_api.inc b/bluga_api.inc
index 9dde6d0..ecc224f 100644
--- a/bluga_api.inc
+++ b/bluga_api.inc
@@ -1,4 +1,5 @@
 <?php
+// $Id: bluga_api.inc,v 1.4.2.2 2009/11/02 07:07:18 hanenkamp Exp $
 
 /**
  * @file
@@ -26,7 +27,12 @@ function _bluga_post($payload) {
   $headers = array('Content-Type' => 'text/xml');
   $message = '<webthumb><apikey>' . variable_get('bluga_api_key', '') . '</apikey>';
   $message .= $payload . "</webthumb>";
-  return drupal_http_request(BLUGA_API_END_POINT, $headers, 'POST', $message);
+	$options = array(
+		'headers' => $headers,
+		'method' => 'POST',
+		'data' => $message,
+	);
+  return drupal_http_request(BLUGA_API_END_POINT, $options);
 }
 
 function _bluga_parse_request($response) {
@@ -134,7 +140,7 @@ function _bluga_parse_request($response) {
  * </ul>
  */
 function bluga_request($options) {
-  $payload .= "<request>";
+  $payload = "<request>";
   foreach ($options as $option => $value) {
     switch ($option) {
       case 'custom':
@@ -165,7 +171,7 @@ function bluga_request($options) {
   
   $response = _bluga_post($payload);
 
-  if ($response->error) {
+  if (isset($response->error)) {
     return $response->data;
   }
   else {
@@ -249,7 +255,7 @@ function bluga_status($jobs_urls = array(), $type = 'job') {
 
   $response = _bluga_post($payload);
 
-  if ($response->error) {
+  if (isset($response->error)) {
     return $response->data;
   }
   else {
@@ -334,7 +340,7 @@ function bluga_credit_status() {
 
   $response = _bluga_post($payload);
 
-  if ($response->error) {
+  if (isset($response->error)) {
     return $response->data;
   }
   else {
