function getSubMenu(item){
    azon = item.getProperty('id');
    if(item.getElements('ul li').length > 0 || !azon ) return;
    params = azon.split('_');            
    container = item.getElements('ul')[0];
    if(!container) return;
    container.innerHTML = '<img src="/images/ajax-loader.gif" />';
    req = new Request({ url:'/modules/menu.ajax.php?level='+params[0]+'&parent='+params[1],async:false,
            onSuccess: function(resp){
                if(resp.length==0){
                    container.destroy();
                }else{
                    container.set('text','');                    
                    container.innerHTML = resp;
                    lis = container.getElements('li');
                    if(document.all){   
                         //ie fix
                        _self = $('#'+azon);
                		if ($('>ul>li>ul', _self).length > 0) { 
                			$('>ul>li', _self).width($('>ul>li', _self).parent().width());
                		} else {            		
                			setTimeout(function() { 
                					var max = 0;
                					$('>ul>li', _self).each(function() {
                						if ($(this).width() > max) {
                							max = $(this).width();
                						}
                					});
                					$('>ul>li', _self).each(function() {
                						$(this).width(max);
                					});
                				},
                            50);                            
                		} 
                        if ( navigator.appVersion.indexOf('MSIE 6.') > -1 ) {
                            $('#'+azon+' ul').children('li').hover(function(){
                        		$(this).children('a').css('color','black');
                        		if ( $(this).children('ul').size() > 0 ) {
                        			$(this).children('ul').css('display','block');
                        			if ( $(this).parent('ul').attr('class') != 'navigation'){
                        				$(this).children('ul').css('left',$(this).width()+'px');
                        			}
                        		}
                        		if ($('>ul>li>ul', this).length > 0) {
                        			$('>ul>li', this).width($('>ul>li', this).parent().width());
                        		} else {
                        			_self = $(this);
                        			setTimeout(function() {
                        				var max = 0;
                        				$('>ul>li', _self).each(function() {
                        					if ($(this).width() > max) {
                        						max = $(this).width();
                        					}
                        				});
                        				$('>ul>li', _self).each(function() {
                        					$(this).width(max);
                        				});
                        			}, 50);
                        		}
                        		},function(){
                        			$(this).children('a').css('color','white');
                        			if ( $(this).children('ul').size() > 0 ) {
                        				$(this).children('ul').css('display','none');
                        			}
                        		}
                        	);  
                        }
                    }else{  
                        //ff fix
                        lsp = container.getElements('ul li.first');
                        lnlsp = lsp.length;
                        if(lnlsp>0){
                            lsp[0].destroy();
                            lsp[lnlsp-1].destroy();
                        }                        
                        if(lis.length>0){                    
                            lis[0].destroy()
                            lis[lis.length-1].destroy();
                        }
                    }  
                    lis = container.getElements('li');  
                    lis.addEvent('mouseenter',function(e){
                        getSubMenu(this);        
                    });                                                                                              
                }                               
            },
            onFaliure: function(){
                container.set('text','');
            }
    });
    req.send();
}

window.addEvent('domready',function(e){
   $$('ul.navigation li[class!="first"]').addEvent('mouseenter',function(e){
        getSubMenu(this);        
   }); 
});
