﻿
$(function() {
    $('.dropdownmenu>ul>li').hover(
        function(e) {
            var x = $(this).offset().left;
            var y = $(this).offset().top + $(this).outerHeight();
	var left = $('.dropdownmenu>ul').offset().left;           
	var width = $('.dropdownmenu>ul').outerWidth();
	var widthul = $(this).find('ul').eq(0).outerWidth();
	var leftul = x;

           if( (left + width) < (x + widthul) )
		{
			x = x - ( (x + widthul) - ( left + width) ) - 2;
		}
            $(this)
                .find('ul')
                .eq(0)
                .css('left',x + 'px')
                .css('top',y + 'px')
                .show();   
        },
        
        function(e) {
            $(this)
               .find('ul')
               .eq(0)
               .hide();        
        }
    );
    
    $('.dropdownmenu>ul>li>ul>li').hover(
        function(e) {
            var top = $(this).position().top ;
            var left = $(this).outerWidth() - 10;
            var width = $(this).outerWidth();



            $(this)
                .find('ul')
                .eq(0)
                .css('left', left + 'px')
                .css('top', top + 'px')
                .show();
        }, 
        function(e) {
            $(this)
                .find('ul')
                .eq(0)
                .hide();
        });
});