
/*** CONFIGURA ***/
var _widthmenu = 150;
var _topoffset = 5;
var _alignerr = 20;
var _menuerr = 60;






var _items = new Array();
var _currentMenu = null;

if( ! document.getElementById ) document.getElementById = function() { return null; }

function _winsize_() {
 var _wsize = null;

 if( parseInt( navigator.appVersion ) > 3 ) {
  if( navigator.appName === "Netscape" ) {
   _wsize = window.innerWidth;
  }

  if( navigator.appName.indexOf( "Microsoft" ) !== -1 ) {
   _wsize = document.body.offsetWidth;
  }
 }

 return _wsize;
}

function _isLeftAlign_() {
 return ( Math.abs( document.getElementById( _items[0] ).offsetLeft - document.getElementById( _items[_items.length - 1] ).offsetLeft ) < _alignerr )? true : false;
}

function _isTopAlign_() {
 return ( Math.abs( document.getElementById( _items[0] ).offsetTop - document.getElementById( _items[_items.length - 1] ).offsetTop ) < _alignerr )? true : false;
}

function _initializeMenu_( _menuId, _actuatorId ) {
 var _menu = document.getElementById( _menuId );
 var _actuator = document.getElementById( _actuatorId );

 if ( ( null === _menu ) || ( null === _actuator ) ) return;

 _actuator.showMenu = function() {
                       _menu.style.width = _widthmenu + "px";
                       _menu.style.left = ( ( _menu.id.indexOf( _items[_items.length - 1] ) !== -1 ) && ( ( this.offsetLeft + _widthmenu + _menuerr ) > _winsize_() ) )? ( ( this.offsetLeft + this.offsetWidth - _widthmenu ) + "px" ) : ( this.offsetLeft + "px" );
                       _menu.style.top = ( _topoffset + this.offsetTop + this.offsetHeight ) + "px";
                       _menu.style.visibility = "visible";
                       _menu.style.display = "block";
                       _currentMenu = _menu;
                       return;

                      }

 _actuator.onfocus = function() {
                      if( _isTopAlign_() ) {
                       if ( null !== _currentMenu ) {
                        if( _currentMenu.id === _menu.id ) {
                         _currentMenu.style.visibility = "hidden";
                         _currentMenu.style.display = "none";
                         _currentMenu = null;
                         return;
                        }
                        else {
                         _currentMenu.style.visibility = "hidden";
                         _currentMenu.style.display = "none";
                         _currentMenu = null;
                        }
                       }

                       this.showMenu();
                      }
                      else if( ( ! _isLeftAlign_() ) && ( null !== _currentMenu ) ) {
                       _currentMenu.style.visibility = "hidden";
                       _currentMenu.style.display = "none";
                       _currentMenu = null;
                      }

                      return;
                     }

 _actuator.onclick = function() {
                      this.blur();
                      if( ( navigator.platform.indexOf( "Mac" ) !== -1 ) && ( navigator.userAgent.indexOf( "Apple" ) !== -1 ) ) return;
                      return ( _isTopAlign_() )? false : true;

                     }

 return;
}

function _applystyle_( _obj, _str ) {
 if( document.all && ( ! window.opera ) )
  _obj.style.setAttribute( "cssText", _str );
 else
  _obj.setAttribute( "style", _str );

 return;
}

function _menuResize_() {
 var _busyspace = 0;

 for( var _index in _items ) {
  _applystyle_( document.getElementById( _items[_index] ), "padding: 0px;" );
  _busyspace += document.getElementById( _items[_index] ).offsetWidth;
 }

 var _padd = Math.floor( ( ( document.getElementById( "mainMenu" ).offsetWidth - _busyspace - _menuerr ) / _items.length ) / 2 );

 for( var _index in _items )
  _applystyle_( document.getElementById( _items[_index] ), "padding: 2px " + _padd + "px;" );

 return;
}
