--- menu_icons_original.module	2012-02-22 04:07:58.000000000 +0100
+++ menu_icons.module	2012-02-24 15:14:44.053382000 +0100
@@ -89,6 +89,30 @@ function menu_icons_form_alter(&$form, $
       '#maxlength' => 40,
       '#description' => t("If you don't have direct file access to the server, use this field to upload your icon."),
     );
+		
+    $form['icon']['image_style_hover'] = array(
+      '#title' => t('Image style for the hover icon'),
+      '#type' => 'select',
+      '#options' => image_style_options(FALSE),
+      '#empty_option' => '<' . t('Menu Icons default') . '>',
+      '#default_value' => $options['menu_icon']['image_style_hover'],
+      '#description' => t('The preview image will be shown while editing the content.'),
+      '#required' => FALSE,
+    );
+		
+    $form['icon']['icon_hover_path'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Path to the hover icon'),
+      '#default_value' => (isset($options['menu_icon']['path_hover']) ? $options['menu_icon']['path_hover'] : variable_get('menu_icons_default_icon_hover', drupal_get_path('module', 'menu_icons') . '/images/default_icon.png')),
+      '#description' => t('The path to the image you would like to use as a background image for this menu item when hovering.'),
+    );
+		
+    $form['icon']['icon_hover_upload'] = array(
+      '#type' => 'file',
+      '#title' => t('Upload a new icon image'),
+      '#maxlength' => 40,
+      '#description' => t("If you don't have direct file access to the server, use this field to upload your hover icon."),
+    );
 
     $form['submit']['#weight'] = 9;
     $form['delete']['#weight'] = 10;
@@ -115,13 +139,14 @@ function menu_icons_form_submit($form, &
 
   // Store the current icon path
   $path = $form_state['values']['icon_path'];
+	$path_hover = $form_state['values']['icon_hover_path'];
 
   // Define the validation settings
   $validate = array(
     'file_validate_is_image' => array(),
   );
 
-  if (empty($form_state['values']['image_style'])) {
+  if (empty($form_state['values']['image_style']) || empty($form_state['values']['image_style_hover'])) {
     $validate['file_validate_image_resolution'] = array(variable_get('menu_icons_file_validate_image_resolution', '45x45'));
   }
 
@@ -136,12 +161,26 @@ function menu_icons_form_submit($form, &
 
     $path = $filename;
   }
+	
+  // Check for a new uploaded hover icon, and use that instead.
+  if ($file_hover = file_save_upload('icon_hover_upload', $validate)) {
+    $parts_hover = pathinfo($file_hover->filename);
+    $filename_hover = $directory_path . '/menu_icon_hover_' . $form_state['values']['mlid'] . '.' . $parts_hover['extension'];
+    file_unmanaged_copy($file_hover->uri, $filename_hover, FILE_EXISTS_REPLACE);
+
+    // Flush image style generated images
+    image_path_flush($filename_hover);
+
+    $path_hover = $filename_hover;
+  }
 
   $options = unserialize(db_query('SELECT options FROM {menu_links} WHERE mlid = :mlid', array(':mlid' => $form_state['values']['mlid']))->fetchField());
   $options['menu_icon'] = array(
     'enable' => $form_state['values']['use_icon_logo'],
     'path' => $path,
+		'path_hover' => $path_hover,
     'image_style' => $form_state['values']['image_style'],
+		'image_style_hover' => $form_state['values']['image_style_hover'],
   );
 
   if (!isset($options['attributes'])) {
@@ -165,7 +204,7 @@ function menu_icons_form_submit($form, &
   if (empty($options['attributes']['class'])) {
     unset($options['attributes']['class']);
   }
-
+	
   db_update('menu_links')
   ->fields(array(
     'options' => serialize($options),
@@ -212,6 +251,14 @@ function menu_icons_admin_settings($form
       '#required' => FALSE,
       '#options' => $options,
     );
+    $form['menu_icons_imagecache_default_hover'] = array(
+      '#type' => 'select',
+      '#title' => t('Image default hover style'),
+      '#default_value' => variable_get('menu_icons_imagecache_default_hover', 'menu_icon'),
+      '#description' => t('Choose a default !link to be used for hover menu icons. This setting can be overwritten per menu item.', array('!link' => l(t('Image style'), 'admin/config/media/image-styles'))),
+      '#required' => FALSE,
+      '#options' => $options,
+    );
   }
 
   $form['menu_icons_image_folder'] = array(
@@ -248,19 +295,23 @@ function menu_icons_admin_settings($form
 function menu_icons_css_generate() {
 
   $css = "";
-  $result = db_query("SELECT mlid, options FROM {menu_links}");
+  $result = db_query("SELECT mlid, options FROM {menu_links}")->fetchAll();
   $pos = variable_get('menu_icons_position', 'left');
+	
 
+	
   foreach ($result as $item) {
     $options = unserialize($item->options);
 
     if (isset($options['menu_icon']) && $options['menu_icon']['enable'] && !empty($options['menu_icon']['path']) && file_exists($options['menu_icon']['path'])) {
+			dsm($item);
+			dsm($options);
 
       $image_path = $options['menu_icon']['path'];
       $image_style = (isset($options['menu_icon']['image_style']) && !empty($options['menu_icon']['image_style'])) ? $options['menu_icon']['image_style'] : NULL;
 
       if ($image_style) {
-        $source_uri = file_build_uri(str_replace(variable_get('file_public_path', conf_path() . '/files') . '/', '', $image_path));
+        $source_uri = str_replace(variable_get('file_public_path', conf_path() . '/files') . '/', '', $image_path);
         $image_path = image_style_path($image_style, $source_uri);
 
         if (!file_exists($image_path)) {
@@ -274,6 +325,28 @@ function menu_icons_css_generate() {
 
       // Support private filesystem
       $css .= theme('menu_icons_css_item', array('mlid' => $item->mlid, 'path' => $image_url, 'size' => $info['width'], 'pos' => $pos));
+			
+			// Add a hover image when specified
+			if (!empty($options['menu_icon']['path_hover']) && file_exists($options['menu_icon']['path_hover'])) {
+				$image_path_hover = $options['menu_icon']['path_hover'];
+				$image_style_hover = (isset($options['menu_icon']['image_style_hover']) && !empty($options['menu_icon']['image_style_hover'])) ? $options['menu_icon']['image_style_hover'] : NULL;
+
+				if ($image_style_hover) {
+					$source_uri_hover = str_replace(variable_get('file_public_path', conf_path() . '/files') . '/', '', $image_path_hover);
+					$image_path_hover = image_style_path($image_style_hover, $source_uri_hover);
+
+					if (!file_exists($image_path_hover)) {
+						image_style_create_derivative(image_style_load($image_style_hover), $source_uri_hover, $image_path_hover);
+					}
+				}
+
+				// Retrieve the image dimensions
+				$info_hover = image_get_info($image_path_hover);
+				$image_url_hover = file_create_url($image_path_hover);
+
+				// Support private filesystem
+				$css .= theme('menu_icons_css_item_hover', array('mlid' => $item->mlid, 'path' => $image_url_hover, 'size' => $info_hover['width'], 'pos' => $pos));
+			}
     }
   }
   if (!empty($css)) {
@@ -292,6 +365,10 @@ function menu_icons_theme() {
       'variables' => array('mlid' => NULL, 'path' => NULL, 'size' => NULL, 'pos' => NULL),
       'template' => 'menu_icons_css_item',
     ),
+    'menu_icons_css_item_hover' => array(
+      'variables' => array('mlid' => NULL, 'path' => NULL, 'size' => NULL, 'pos' => NULL),
+      'template' => 'menu_icons_css_item_hover',
+    ),
   );
 }
 
