var expandedLevel = 0;
$(document).ready(function(){

    $('.menu a + div').hide();
    
    $('.menu a + div').prev().each(function(){
        var child = $(this).next()[0];
        
        //HOVER
        if ($(this).attr('type') == 'hover') {
            $(child).hover(function(){
                $(child).stopTime('controlled');
            }, function(){
                $(child).everyTime(500, 'controlled', function(){
                    $(child).hide('slow');
                });
            });
            
            $(this).hover(function(){
                $(child).stopTime('controlled');
				$(child).css('left', $(this).position().left+'px');
				$(child).css('top', ($(this).position().top + ($(this).innerHeight())) +'px')
				$(this).parent().find('div').each(function(){if(this != child) $(this).hide();});
				
				if ($(this).attr('name') == 'right')
				{//submenu
					
					$(child).css('left', $(this).position().left+($(this).outerWidth({ margin: true }))+'px');
					$(child).css('top', $(this).position().top +'px');
				} 
				
                
				//alert($(this).outerWidth({ margin: true }));
                /*$(child).css('left', ($(this).position().left - parseInt($(this).css('margin-left'))+'px'  ));
                $(child).css('top', ($(this).position().top + ($(this).innerHeight({ margin: true }))) +'px');
                */
				//$(child).scrollLeft($(this).offset().left);
				/*$(child).css('top', 400);
				$(child).scrollTop(400);*/
				/*$(child).offset == 
				{ 
					/*relativeTo: $(this)
					
					top: $(this).offset().left+$(this).offset().width,
					left: $(this).offset().top+$(this).offset().height
				};*/
				
                /*$(child).animate({opacity: .8}).slideDown();
                 * 
                 */
				$(child).slideDown('fast');
            }, function(){
                $(child).everyTime(500, 'controlled', function(){
                    $(child).hide('slow');
                });
            });
        }
        //CLICK
        else {
            $(this).click(function(){
                if (child.style.display == 'none') {
                    $(child).show('slow');
                }
                else {
                    $(child).hide('slow');
                }
                return false;
            });
        }
    });
})

