diff --git a/languageinterface.info b/languageinterface.info
index 7420c6d..bbfb938 100644
--- a/languageinterface.info
+++ b/languageinterface.info
@@ -3,17 +3,8 @@ description = Creates an independent language interface block.
 dependencies[] = locale
 package = Multilanguage
 version = 1.0
-core = 6.x
-; Information added by drupal.org packaging script on 2008-12-09
-version = "6.x-1.2"
-core = "6.x"
+core = 7.x
 project = "languageinterface"
-datestamp = "1228842629"
 
-
-; Information added by drupal.org packaging script on 2009-02-19
-version = "6.x-2.1"
-core = "6.x"
-project = "languageinterface"
-datestamp = "1235080854"
+files[] = languageinterface.module
 
diff --git a/languageinterface.module b/languageinterface.module
index a3e409f..345e609 100644
--- a/languageinterface.module
+++ b/languageinterface.module
@@ -15,7 +15,7 @@ if (variable_get('language_redirect', 0) == 1) {
   global $base_url;
   $fullurl = $_SERVER['QUERY_STRING'];
   $fullurl = str_replace('q=', '', $fullurl);
-  $lastviewed = $_SESSION['cli']['source'];     
+  $lastviewed = $_SESSION['cli']['source'];
   if (is_numeric(strpos($referrer, $base_url)) || $lastviewed == 'goto') {
     $internalref = TRUE;
   }
@@ -28,7 +28,7 @@ if (variable_get('language_redirect', 0) == 1) {
     if (!empty($lastlanguage) && $lastviewed != 'goto') {
       $languagepath = languagepath($lastlanguage);
       if (empty($languagepath['domain'])) {
-        $languagepath = $base_url.'/'.$languagepath['path'];
+        $languagepath = $base_url . '/' . $languagepath['path'];
       }
       else {
         $languagepath = $languagepath['path'];
@@ -53,134 +53,85 @@ if (variable_get('language_redirect', 0) == 1) {
  * Implementation of hook_menu().
  */
 function languageinterface_menu() {
-  $items['admin/settings/language-interface'] = array(
-    'title' => t('Consistent Language Interface Options'),
-    'description' => t('Language Interface Options'),
+  $items['admin/config/regional/language-interface'] = array(
+    'title' => 'Consistent Language Interface Options',
+    'description' => 'Language Interface Options',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('languageinterface_options'),
     'access arguments' => array('administer languages'),
-    'type' => MENU_NORMAL_ITEM,  
+    'type' => MENU_NORMAL_ITEM,
   );
   return $items;
 }
 
 /**
+ * Implementation of hook_block_info().
+ */
+function languageinterface_block_info() {
+
+  $blocks[0]['info'] = t('Consistent Language Interface block');
+  $blocks[0]['cache'] = DRUPAL_NO_CACHE;
+  return $blocks;
+}
+
+/**
  * Implementation of hook_block().
  */
 
-function languageinterface_block($op = 'list', $delta = 0, $edit = array()) {
-  switch ($op) {
-    case 'list':
-      $blocks[0]['info'] = t('Consistent Language Interface block');
-      $blocks[0]['cache'] = BLOCK_NO_CACHE;
-    return $blocks;
-    
-    case 'view':
-      $block['subject'] = t('Language'); 
-      $block['content'] = language_link_creation();
-  }
-  //end switch ($op)
+function languageinterface_block_view($delta = 0) {
+  $block['subject'] = t('Language');
+  $block['content'] = language_link_creation();
+
   return $block;
 }
-
+/**
+ * This function returns link to content int target language.
+ *
+ * For nodes, this function checks whether the node has translation  to given language.
+ * If yes, it returns such a link. If not, it returns link to current translation with menus translated to the other.
+ *
+ * For other content, this function returns link to translation.
+ *
+ * @param $lang language code to use
+ */
 function languagepath($lang) {
-  $new_path_array = array();
-  $new_path_options['language'] = $lang;
-  
-  
-  //We get the full url of the page.
-  $fullurl = $_SERVER['QUERY_STRING'];
-  
-  $fullurl = str_replace('q=', '', $fullurl);
-    
-  // We convert the url into an array.
-  $urlarray = explode('/', $fullurl);
+  $link = drupal_parse_url($_GET['q']);
+  $link['absolute'] = TRUE;
 
-  
-  global $language;
-  // We check to see if there is an empty space in the url and remove it if so.
-  if ($urlarray[0] == "") {
-    array_shift($urlarray);
-  }
-  // We check to see if there is a language string in the url and remove it if so.
-  if ($urlarray[0] == $language->prefix) {
-    array_shift($urlarray);
-  }
-  
-  $thislang = db_fetch_object(db_query("SELECT * FROM {languages} WHERE language = '%s'", $lang));
-  
-  $prefix = $thislang->prefix;
-  // We determine if we are looking at a node or some other kind of page.
-  if ((arg(0) == 'node') && (is_numeric(arg(1)))) {
-    $areatype = 'node';
-    $node_nid = arg(1);
-    array_shift($urlarray);
-    array_shift($urlarray);
-  
-    //Since the page is a node we remove two more items from the array
-    //so that the "node/" and the nid are left out.
-    // Since we have determined this to be a node we get the tnid to work with later.
-    
-    $tnid = db_result(db_query("SELECT tnid FROM {node} WHERE nid = %d", $node_nid));
-    if ($tnid) {
-      $translation_nid = specific_translation_exist($tnid, $lang);
-      $destination_nid = $translation_nid;
-    }
-    else {
-      $destination_nid = $node_nid;
-    }
-    $new_path_array['node_path'] = 'node/'.$destination_nid;    
+  $languages = language_list();
+  $link['language'] = $languages[$lang];
+
+  if (!empty($url['language']->domain)) {
+    $link['base_url']  = $url['language']->domain;
   }
-  // Endif (current page is node)
-
-  $remaining = implode("/", $urlarray);
-  if ($remaining) {
-    if (strpos('?',$remaining)) {
-      //Some querystrings start with a question mark others start with an &
-      $pre_query = explode('?', $remaining);
-      $new_path_array['remaining'] = $pre_query[0];
-      $query = $pre_query[1];
-    }
-    else {
-      $remaining = explode('&', $remaining);
-      $remaining_pre = $remaining[0];
-      array_shift($remaining);
-      $query = implode('&',$remaining);
-      $remaining = $remaining_pre;     
-    }
-    if ($query) {
-      $link['query'] = $query;
-    }
-    if (!empty($remaining)) {
-      $new_path_array['remaining'] = $remaining;
-    }
+
+  if (!empty($url['language']->prefix)) {
+    $link['prefix']  = $url['language']->prefix;
   }
-  $link['path'] = implode('/',$new_path_array);
-  $alias = FALSE;
-  // We look up the alias without the prefix. Otherwise it doesn't work.
-  if ($translation_nid || $destination_nid == $node_nid) {
-    $alias = drupal_lookup_path('alias', $link['path'], $lang);
-    if ($alias != FAlSE) {
-      $link['path'] = $alias;
+
+  if (arg(0) == 'node' && arg(1)) {
+    $args = arg();
+    array_shift($args); // remove "node" text
+    $nid = array_shift($args);
+    $rest = implode("/", $args);
+
+    // find translation
+    $node = node_load($nid);
+    if ($node->tnid) {
+      $nid = $node->tnid;
     }
+
+    $nid = specific_translation_exist($nid, $lang);
+
+    $link['path'] = 'node/' . $nid . '/' . $rest;
   }
-  
-  if (!empty($prefix)) {
-    // If no alias is returned we add the prefix so that the interface will be translated
-    // If there is no tranlation existing then we 
-    $link['path'] = $prefix.'/'.$link['path'];
-  }
-  if (!empty($thislang->domain)) {
-    // If we are using a domain we put the domain in front of the path.
-    $link['path']     = 'http://'.$thislang->domain.'/'.$link['path'];
-    $link['absolute'] = TRUE;
-    $link['domain']   = $thislang->domain; 
-  }
+
   return $link;
 }
 
 function specific_translation_exist($tnid = NULL, $lang) {
-  $lang_nid = db_result(db_query("SELECT nid FROM {node} WHERE language = '%s' AND tnid = %d ",$lang, $tnid));
+  $result = db_query("SELECT nid FROM {node} n WHERE language = :lang AND tnid = :tnid ", array(":lang" => $lang, ":tnid" => $tnid));
+  $lang_nid = $result->fetchField();
   if (!$lang_nid) {
     $lang_nid = $tnid;
   }
@@ -190,21 +141,21 @@ function specific_translation_exist($tnid = NULL, $lang) {
 /**
  * Return an array of enabled languages ordered by weight so that the order of the flags can be customized
  */
-function get_enabled_languages(){
-  $result = db_query('SELECT language FROM {languages} WHERE enabled = 1 ORDER BY weight ASC');
-  while ($enabled_languages = db_fetch_object($result)) {
-    $languages[] = $enabled_languages->language; 
+function get_enabled_languages() {
+  $result = db_query('SELECT language FROM {languages} languages WHERE enabled = 1 ORDER BY weight ASC');
+  while ($enabled_languages = $result->fetchObject()) {
+    $languages[] = $enabled_languages->language;
   }
   return $languages;
 }
 
 function language_link_creation() {
-  
+
   $customdimensions = variable_get('custom_flag_dimensions', '16x12');
   $customdimensions = explode('x', $customdimensions);
-  $flagwidth        = $customdimensions[0]; 
+  $flagwidth        = $customdimensions[0];
   $flagheight       = $customdimensions[1];
-  $defaultflagpath  = drupal_get_path('module', 'languageinterface') .'/flags/*.png' ;
+  $defaultflagpath  = drupal_get_path('module', 'languageinterface') . '/flags/*.png' ;
   $flagpath         = variable_get('custom_flag_path', $defaultflagpath);
   if ($flagpath == '') {
     $flagpath = $defaultflagpath;
@@ -212,7 +163,7 @@ function language_link_creation() {
   $textoptions      = variable_get('languageinterface_text', 'post');
   $languages = get_enabled_languages();
   $languagetext = variable_get('tl', '');
-  
+
   $tbl = variable_get('tbl', '');
   $tal = variable_get('tal', '');
   //$tbl = Text before language icon
@@ -226,42 +177,43 @@ function language_link_creation() {
     else {
       $activeclass = FALSE;
     }
-    
-    $src = $base_url .'/'. str_replace('*', $lang, $flagpath);
+
+    $src = $base_url . '/' . str_replace('*', $lang, $flagpath);
     $text = '';
-    
-    $defaulttext = db_result(db_query("SELECT native FROM {languages} WHERE language = '%s'", $lang));
-   
+
+    $defaulttext = db_query("SELECT native FROM {languages} WHERE language = :lang", array(':lang' => $lang))->fetchField();
+     
     if (!empty($languagetext[$lang])) {
       $ltext = $languagetext[$lang];
     }
     else {
       $ltext = $defaulttext;
     }
-    
+
     if (!empty($tbl[$lang]) && empty($tal[$lang])) {
-      $text = $tbl[$lang] .' '. $ltext;
+      $text = $tbl[$lang] . ' ' . $ltext;
     }
     if (!empty($tal[$lang]) && empty($tbl[$lang])) {
-      $text = $ltext .' '. $tal[$lang];
+      $text = $ltext . ' ' . $tal[$lang];
     }
     if (!empty($tal[$lang]) && !empty($tbl[$lang])) {
-      $text = $tbl[$lang] .' '. $ltext .' '. $tal[$lang];
+      $text = $tbl[$lang] . ' ' . $ltext . ' ' . $tal[$lang];
     }
-     if (empty($tal[$lang]) && empty($tbl[$lang])) {
+    if (empty($tal[$lang]) && empty($tbl[$lang])) {
       $text = $ltext;
     }
-   
+     
+    $links[$lang] = $path_array;
     $links[$lang]['text']       = $text;
     $links[$lang]['src']        = $src;
     $links[$lang]['flagheight'] = $flagheight;
     $links[$lang]['flagwidth']  = $flagwidth;
     $links[$lang]['position']   = $textoptions;
-    $links[$lang]['path']       = $path_array['path'];
-    $links[$lang]['absolute']   = $path_array['absolute'];
-    $links[$lang]['query']      = $path_array['query'];
+    //$links[$lang]['path']       = $path_array['path'];
+    //$links[$lang]['absolute']   = (empty($path_array['absolute']) ? FALSE : $path_array['absolute']);
+    //$links[$lang]['query']      = $path_array['query'];
     $links[$lang]['active']     = $activeclass;
-    $links[$lang]['language']   = $lang; 
+    //$links[$lang]['language']   = $lang;
   }
   //End foreach.
   return theme('languageswitcher', $links);
@@ -274,7 +226,7 @@ function languageinterface_theme() {
   return array(
     'languageswitcher' => array(
       'arguments' => array('links' => NULL ),
-    ),
+  ),
   );
 }
 /**
@@ -285,47 +237,49 @@ function theme_languageswitcher($links) {
    Here we are manually creating a unordered list due to the fact that
    theme('item_list') does not assign language specific active classes correctly.
    The $classes variable is also directly fed to the l() function for the same reason.
-  */
+   */
   $output = '<ul id="language-interface">';
   foreach ($links as $link) {
-    $classes = '';
+    $classes = array();
     if ($link['active'] == TRUE) {
-      $classes = 'active'.' '. $link['language'] ;
+      $classes[] = 'active';
+      $classes[] = $link['language']->language;
     }
     else {
-      $classes = $link['language'] ;
+      $classes[] = $link['language']->language;
     }
     if ($link['position'] != 'no_image') {
-      $flag = '<img src="'. $link['src'] .'" width = "'. $link['flagwidth'] .'" height = "'. $link['flagheight'] .'" class="'. $classes .'" alt="'. $link['text'] .'"/>';
+      $flag = '<img src="' . $link['src'] . '" width = "' . $link['flagwidth'] . '" height = "' . $link['flagheight'] . '" class="' . $classes . '" alt="' . $link['text'] . '"/>';
     }
     if ($link['position'] != 'no_text') {
       $text = $link['text'];
     }
     switch ($link['position']) {
       case 'pre':
-      $display = $text.' '.$flag;
-      break;
-        
+        $display = $text . ' ' . $flag;
+        break;
+
       case 'post';
-      $display = $flag.' '.$text;
-      break;  
-        
+      $display = $flag . ' ' . $text;
+      break;
+
       case 'no_text';
       $display = $flag;
-      break;    
-        
+      break;
+
       case 'no_image';
       $display = $text;
-      break;    
+      break;
     }
+
     // end switch
+    $languages = language_list();
+    $options = $link;
+    //$options ['language'] = $languages[$link['language']];
     $options['html']                = TRUE;
-    $options['attributes']['class'] = $classes;      
-    $options['language']            = $link['language'];
-    $options['query']               = $link['query'];
-    $options['absolute']            = $link['absolute'];
-    $options['external']            = $link['absolute'];
-    $output .= '<li class="'. $classes .'">'. l($display, $link['path'], $options) .'</li>';
+    $options['attributes']['class'] = $classes;
+
+    $output .= '<li class="' . implode(" ", $classes) . '">' . l($display, $link['path'], $options) . '</li>';
   }
   $output .= '</ul>';
   return $output;
@@ -334,11 +288,14 @@ function theme_languageswitcher($links) {
 function languageinterface_options() {
   $customdimensions = variable_get('custom_flag_dimensions', '16x12');
   $customdimensions = explode('x', $customdimensions);
-  $flagwidth = $customdimensions[0]; 
+  $flagwidth = $customdimensions[0];
   $flagheight = $customdimensions[1];
-  $langsettings = variable_get('language_negotiation', '0');
-  if ($langsettings == '0' || $langsettings == '3') {
-    drupal_set_message(t('Language Negotiation must be set to "Path Prefix" or "Path Prefix with language fallback" for the language swithcher to work. <br /> To change this setting please go to: ').l('admin/settings/language/configure', 'admin/settings/language/configure'), $type = 'error', $repeat = FALSE);
+
+  // @todo we don't take into account weights.
+  $langsettings = language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_URL);
+  //drupal_set_message(print_r($langsettings,true));
+  if ($langsettings != TRUE) {
+    drupal_set_message(t('Language Negotiation URL method must  be enabled and set up for the language switcher to work. <br /> To change this setting please go to:') . ' ' . l('admin/config/regional/language/configure', 'admin/config/regional/language/configure'), $type = 'error', $repeat = FALSE);
   }
   $form['flag_text_config'] = array(
     '#type' => 'radios',
@@ -372,47 +329,51 @@ function languageinterface_options() {
   $tbl = variable_get('tbl', '');
   $tl  = variable_get('tl', '');
   foreach ($enabled as $lang) {
-    $text = db_result(db_query('SELECT native FROM {languages} WHERE language = "%s"', $lang));
+    $result = db_query('SELECT native, weight FROM {languages} l WHERE language = :lang', array(':lang' => $lang));
+    $result = $result->fetchAssoc();
+    $text = $result['native'];
+
     if (!empty($tl[$lang])) {
       $tldef = $tl[$lang];
     }
     else {
       $tldef = $text;
     }
-    $currentweight = db_result(db_query('SELECT weight FROM {languages} WHERE language = "%s"', $lang));
+
+    $currentweight = $result['weight'];
     $form['language_order']['lang_weight'][$lang] = array(
       '#type' => 'weight',
       '#title' => $text,
       '#delta' => 10, 
       '#default_value' => $currentweight,
     );
-  $form['language_text']['text'][$lang] = array(
+    $form['language_text']['text'][$lang] = array(
       '#type' => 'textfield',
-      '#title' => t('Language display for') .' '. $text,
+      '#title' => t('Language display for') . ' ' . $text,
       '#default_value' => $tldef,
       '#size' => 80,
       '#description' => t('How the language will display in the link. Useful in situations where the language name should change in the context of the text before it or after it. Example: "Version Fran&ccedil;aise" where the "e" is needed because "version" is feminine.'),
     );
-   $form['language_text']['pretext'][$lang] = array(
+    $form['language_text']['pretext'][$lang] = array(
       '#type' => 'textfield',
-      '#title' => t('Text before language for') .' '. $text,
+      '#title' => t('Text before language for') . ' ' . $text,
       '#default_value' => $tbl[$lang],
       '#size' => 80,
       '#description' => t('Text before language. Example: to show "View page in English" Rather than just "English" enter "View page in".'),
     );
     $form['language_text']['posttext'][$lang] = array(
       '#type' => 'textfield',
-      '#title' => t('Text after language for') .' '. $text,
+      '#title' => t('Text after language for') . ' ' . $text,
       '#default_value' => $tal[$lang],
       '#size' => 80,
       '#description' => t('Text after language. Example: to show "English version" Rather than just "English" enter "version"'),
     );
   }
-    
-   // end foreach
-  $default_flagpath = variable_get('custom_flag_path', drupal_get_path('module', 'languageinterface').'/flags/*.png');
+
+  // end foreach
+  $default_flagpath = variable_get('custom_flag_path', drupal_get_path('module', 'languageinterface') . '/flags/*.png');
   if ($default_flagpath == "") {
-    $default_flagpath = drupal_get_path('module', 'languageinterface').'/flags/*.png';
+    $default_flagpath = drupal_get_path('module', 'languageinterface') . '/flags/*.png';
   }
   $form['custom_flag_path'] = array(
     '#type' => 'textfield',
@@ -435,13 +396,13 @@ function languageinterface_options() {
     '#title' => t('Width'),
     '#tree' => TRUE,
     '#default_value' => $flagwidth,
-     );
+  );
   $form['custom_dimensions']['flagheight'] = array(
     '#type' => 'textfield',
     '#title' => t('Height'),
     '#tree' => TRUE,
     '#default_value' => $flagheight,
-     );
+  );
   $form['redirect'] = array(
     '#type' => 'checkbox',
     '#title' => t('Redirect returning visitors to last viewed language'),
@@ -464,23 +425,24 @@ function languageinterface_options_submit($form, &$form_state) {
     variable_set('language_redirect', $form_state['values']['redirect']);
 
     $enabledlanguages = get_enabled_languages();
-    foreach($enabledlanguages as $lang) {
+    foreach ($enabledlanguages as $lang) {
       $pretext[$lang]  = $form_state['values']['language_text']['pretext'][$lang];
       $text[$lang] = $form_state['values']['language_text']['text'][$lang];
       $posttext[$lang] = $form_state['values']['language_text']['posttext'][$lang];
-      
-      
+
+
       $weight = $form_state['values']['language_order']['lang_weight'][$lang];
-      db_query('UPDATE {languages} SET weight = %d WHERE language = "%s"', $weight, $lang);
+      db_update('languages')->fields(array('weight' => $weight))->condition('language', $lang)->execute();
+
     }
-   
+     
     if (!empty($pretext)) {
       variable_set('tbl', $pretext);
     }
     else {
       variable_del('tbl');
     }
-     if (!empty($text)) {
+    if (!empty($text)) {
       variable_set('tl', $text);
     }
     else {
@@ -493,19 +455,19 @@ function languageinterface_options_submit($form, &$form_state) {
       variable_del('tal');
     }
     if (!empty($form_state['values']['custom_dimensions']['flagwidth']) && !empty($form_state['values']['custom_dimensions']['flagheight'])) {
-      $dimensions = check_plain($form_state['values']['custom_dimensions']['flagwidth']) .'x'. check_plain($form_state['values']['custom_dimensions']['flagheight']) ;
+      $dimensions = check_plain($form_state['values']['custom_dimensions']['flagwidth']) . 'x' . check_plain($form_state['values']['custom_dimensions']['flagheight']) ;
       variable_set('custom_flag_dimensions', $dimensions);
     }
     else {
       $dimensions = '16x12';
       variable_set('custom_flag_dimensions', $dimensions);
     }
-    variable_set('languageinterface_text',$form_state['values']['flag_text_config']);
+    variable_set('languageinterface_text', $form_state['values']['flag_text_config']);
     variable_set('custom_flag_path', check_plain($form_state['values']['custom_flag_path']));
   }
   if ($form_state['values']['reset_all'] == 1) {
     variable_set('languageinterface_text', 'post');
-    variable_set('custom_flag_path',  drupal_get_path('module', 'languageinterface') .'/flags/*.png');
+    variable_set('custom_flag_path',  drupal_get_path('module', 'languageinterface') . '/flags/*.png');
     variable_set('custom_flag_dimensions', '16x12');
     variable_del('tbl');
     variable_del('tal');
@@ -514,7 +476,7 @@ function languageinterface_options_submit($form, &$form_state) {
   drupal_set_message(t('Your configuration settings have been saved'), $type = 'status', $repeat = FALSE);
 }
 
-function currentlanguage(){
+function currentlanguage() {
   global $language;
   return $language->language;
 }
\ No newline at end of file
