MENU_CLASS = ".yojaMenu";

function addSubMenuVerti(_context) {
    var subItems = [];
    var listLiens = $j("ul li a", _context);
    listLiens.each(function(t){
        subItems.push({text : $j(this).text() , url : $j(this).attr("href")});
    });
    return subItems;       
   
}



function addMenuVerti(Y,context) {
    var conteneur = $j("<div id='vertimenu'></div>");
    var originalMenu = $j(".module_categories",context).replaceWith(conteneur);
    var oMenuBar = new YAHOO.widget.Menu("vertimenu", { position: "static" , shadow:false});
    var listLis = $j("ul:first > *", originalMenu);
    var items = [];
    listLis.each(function(i) {    	      
              var _context = $j(this);
              var elemLien = $j("a:first", _context);
              var item = {};
              item.text = elemLien.text();
              item.url = elemLien.attr("href");
              if($j("ul li a", _context).length != 0) {
            	  item.submenu = {id : "submenu"+i,
                          itemdata : addSubMenuVerti(_context)
                  }            	 
            	  YAHOO.util.Dom.addClass(item.submenu, "submenu"); 
              }            
              var menuItem = oMenuBar.addItem(item);
              YAHOO.util.Dom.addClass(menuItem.element.firstChild , elemLien.attr("class"));
          }          
       ); 
     oMenuBar.render();
     conteneur.addClass("module_categories sidebar_block");
     oMenuBar.show();
     return conteneur;
}

function createMenu(Y) {
	  $j("body").addClass("yui-skin-sam");
    var context = $j("div.menu");
    var menu =  addMenuVerti(Y,context);    
    
}

/*******************************************************************************
 * Charger dynamiquement les dépendances puis exécution du module
 ******************************************************************************/

YUI(
        {
            loadOptional :(typeof jQuery == 'undefined'),
            modules : {
                jquery : {
                    name :"jquery",
                    type :"js",
                    fullpath :"http://yoja-web.com/javascript/build/plugins/jquery/jquery.js"
                },
                yoja : {
                    name :"yoja",
                    type :"js",
                    fullpath :"http://yoja-web.com/javascript/build/plugins/yoja/yoja.core.js",
                    optional :[ "jquery" ]
                },
                menuVertiCSS : {
                    name :"menuVertiCSS",
                    type :"css",
                    fullpath :"http://yoja-web.com/javascript/assets/modules/menuVerti/menuverti.css"
                },
                domEvent : {
                    name :"domEvent",
                    type :"js",
                    fullpath :"http://yui.yahooapis.com/2.6.0/build/yahoo-dom-event/yahoo-dom-event.js"                   
                },
                containerCore : {
                    name :"containerCore",
                    type :"js",
                    fullpath :"http://yui.yahooapis.com/2.6.0/build/container/container_core-min.js"
                },
                menuVerti : {
                    name :"menuVerti",
                    type :"js",
                    fullpath :"http://yui.yahooapis.com/2.6.0/build/menu/menu-min.js",
                    requires : ['domEvent', 'containerCore', 'menuVertiCSS']
                }
            }
        }).use('yoja', 'menuVerti', function(Y) {

            createMenu(Y);

});