var w3gDialogsButtonLocale = {1:{'IT':'ok','EN':'ok'}, 0:{'IT':'annulla','EN':'cancel'}, 2:{'IT':'si','EN':'yes'}, 3:{'IT':'no','EN':'no'}};/* 
Main menu' in HTML list mode controller
author: FC      
version: 1.1.0 - fix flickering issue in IE6, code improved. 
version: 1.0.1 - 3th level visibility fix
version: 1.0.0 - first release
*/

var w3gMainMenu = { 
    current: null,
    currSub: null,
    swapClassName:function(el,className,classNameNew){ 
      var childs1 = $A(el.getElementsByClassName(className) || new Array());
      var childs2 = $A(el.getElementsByClassName(classNameNew) || new Array());
      childs = childs1.concat(childs2);
      $A(childs).each(function(ul){
                  if(ul.className==className){
                    ul.className=classNameNew;
                  }else if(ul.className==classNameNew){
                    ul.className=className;
                  }});      
    },
    changeClassName:function(el,className,classNameNew){
      var childs = $A(el.getElementsByClassName(className) || new Array());
      $A(childs).each(function(ul){
                  if(ul.className==className){
                    ul.className=classNameNew;
                  }}
             );      
    },
    initialize: function(el){
         el = $(el);         
         if(el!=null && typeof el != 'undefined'){
             w3gMainMenu.current = el;
             var subs = $$('#'+el.getAttribute('id')+' .item_menu_sel');
             if(subs !=null && subs.length!=0){
                 w3gMainMenu.currSub = subs[0];
                 //w3gMainMenu.expand(w3gMainMenu.currSub);
             }
         }
         w3gMainMenu.show(w3gMainMenu.current);
    },
    expand:function(el,evt){  
        el = $(el);
        if(el==null)return;
        if(el.getElementsByTagName("UL").length>0){                    
            el.addClassName('terzolivello_sel');
            w3gMainMenu.swapClassName(el,'terzolivello_items_sel','terzolivello_items');
            /*var items_sel= $A(el.getElementsByClassName('terzolivello_items_sel'));
            var items= $A(el.getElementsByClassName('terzolivello_items'));
            items_sel.each(function(ul){ul.className='terzolivello_items';});
            items.each(function(ul){ul.className='terzolivello_items_sel';}); */ 
            $A(el.getElementsByTagName('LI')).each(function(node){Element.forceRerendering(node);});                      
        }
       if(w3gMainMenu.currSub!=null && el.id.replace(/\D+/g,'')!=w3gMainMenu.currSub.id.replace(/\D+/g,'')){
             w3gMainMenu.collapse(w3gMainMenu.currSub);
        }
    
    },
    collapse:function(el,evt){
        
        el = $(el);
        if(el==null)return;
        if(el.getElementsByTagName("UL").length>0){
            el.removeClassName('terzolivello_sel');             
            w3gMainMenu.changeClassName(el,'terzolivello_items_sel','terzolivello_items');
            //$A(el.getElementsByClassName('terzolivello_items_sel')).each(function(ul){ul.className='terzolivello_items';});                    
        }
        if(w3gMainMenu.currSub!=null && el.id.replace(/\D+/g,'')!=w3gMainMenu.currSub.id.replace(/\D+/g,'')){
            w3gMainMenu.expand(w3gMainMenu.currSub);
        }
    },
    show :function(el,evt){        
        el = $(el);
        if(el==null || !/titolo_max/.test(el.className))return;
        el.className = 'titolo_max_sel';
        el.id= el.id.replace(/\D+/g,'titolo_max_sel');
        w3gMainMenu.swapClassName(el,'primolivello_sel','primolivello');
        /*var primolivello_sel = $A(el.getElementsByClassName('primolivello_sel'));
        var primolivello = $A(el.getElementsByClassName('primolivello'));  
        primolivello_sel.each(function(ul){ul.className='primolivello';}); 
        primolivello.each(function(ul){ul.className='primolivello_sel';});*/
        if(w3gMainMenu.current!=null && el.id.replace(/\D+/g,'')!=w3gMainMenu.current.id.replace(/\D+/g,'')){
            w3gMainMenu.hide(w3gMainMenu.current);
        }
        w3gMainMenu.expand($A(el.getElementsByClassName('item_menu_sel'))[0]);
    },
    hide : function(el,evt){        
        el = $(el);
        if(el==null || !/titolo_max/.test(el.className))return;
        el.className = 'titolo_max';
        el.id= el.id.replace(/\D+/g,'titolo_max');
        w3gMainMenu.changeClassName(el,'primolivello_sel','primolivello');
       // $A(el.getElementsByClassName('primolivello_sel')).each(function(ul){ul.className='primolivello';});                
        if(w3gMainMenu.current!=null && el.id.replace(/\D+/g,'')!=w3gMainMenu.current.id.replace(/\D+/g,'')){
            w3gMainMenu.show(w3gMainMenu.current);                    
        }
        w3gMainMenu.collapse($A(el.getElementsByClassName('item_menu_sel'))[0]);
    },    
    version: function(){
                        var release ='1';
                        var major='1';
                        var minor='0';                 
                        this.release=release;this.major=major;this.minor=minor;  
                        function fullVersion(){     return release+'.'+major+'.'+minor; }
                        return fullVersion();
            }
}
