/**
 * Main menu mouse event processing 
 * Also sets up current active menu selection.
 *
 * @package    cyrillascrochet
 * @author     John Malis
 * @version    SVN: $Id: menu.js 12474 2009-10-31 10:41:27Z john $
 */



var CYRILLASCROCHET = {

// ***** Object properties used throughout

current_menu_item: null,           // Id of current menu item area
current_shader_position: null,     // Current coordinates of old postion
menu_img: null,                    // Id of the menu image
menu_spacer_img: null,             // Id of the menu spacer image
active_menu_name: null,            // Name of the active menu
shader_positions: null,            // Associative array of shader positions


/**
   * Set current active menu name
   *
   * @string  Active Menu Name
   */

setActiveMenuName: function (name)
  {
  this.active_menu_name = name;
  },

/**
   *  Sets up associative array of menu positions
   *
   * @object   Menu Positions
   */
   
setShaderPositions: function (positions)
  {
  this.shader_positions = positions;
  },


/**
   * Returns true if we are running on IE 6
   * Needed to detect if we can change CSS background image property
   *
   * @returns  boolean
   */
   
isIE6: function ()
  {
  var isie6 = false;
  
  if (Browser.Engine.trident && (Browser.Engine.version < 700))
    isie6 =  true;
      
  return isie6;
  },
  

 /**
   * Event processing for menu mouseout event
   * Sets the position of the shader to whatever it was before moused in
   *
   */
rollAreaOff: function ()
  {
  if (this != CYRILLASCROCHET.current_menu_item)
    {
     CYRILLASCROCHET.menu_img.setStyle('background-position', CYRILLASCROCHET.current_shader_position);
    }
  },
  
 /**
   * Event processing for menu mouseover event
   * Sets the position of the shader to the area moused over
   *
   */
   
rollAreaOn: function  () 
  {
  if (this != CYRILLASCROCHET.current_menu_item)
    {
    CYRILLASCROCHET.current_shader_position = CYRILLASCROCHET.menu_img.getStyle('background_position');
    var id = this.get('id');
    if ($chk(id))
      {
      var position = CYRILLASCROCHET.shader_positions[id];
      if ($chk(position))
         CYRILLASCROCHET.menu_img.setStyle('background-position', position);
      }
    }
  },


  
setCurrentMenuItem: function (item)
  {
  this.current_menu_item = $(item);
  if ($chk(this.current_menu_item))
    {
    var id = this.current_menu_item.get('id');
    if ($chk(id))
      {
      this.current_shader_position = this.shader_positions[id];
      this.menu_spacer_img.setStyle('background-position', this.current_shader_position);
      //this.menu_img.setStyle('background-position', this.current_shader_position);
      }
    }
  },


/**
  *
  * Handles Mootools Domready event.
  * Sets up mouse event processing for the main menu image map.
  *
  * Called by Mootools Domready
  *
 **/


setupMouseEvents: function ()
  {
  
  if (!CYRILLASCROCHET.isIE6()) 
    {
      
    // **** Get the id of the menu image and the background spacer image
    
    CYRILLASCROCHET.menu_img = $('menu_img');
    CYRILLASCROCHET.menu_spacer_img = $('menu_spacer_img');
    
    if ($chk(CYRILLASCROCHET.menu_img) && $chk(CYRILLASCROCHET.menu_spacer_img))
      {
      if (CYRILLASCROCHET.shader_positions == null)
        alert('Shader Positions Not Set');
      else
        {
        CYRILLASCROCHET.setCurrentMenuItem(CYRILLASCROCHET.active_menu_name);
        
      // **** Setup mouse events for main menu
      
        var menuareas = $$('#menu_map area');
        if ($chk(menuareas))
          {
          menuareas.addEvents({
            "mouseover": CYRILLASCROCHET.rollAreaOn,
        
            "mouseout": CYRILLASCROCHET.rollAreaOff
            });
          }
        }
      }
    }
  }
  
};  

/***
   * Setup to handle domready event from mootools.
   *
 ***/
 
window.addEvent('domready', CYRILLASCROCHET.setupMouseEvents);

