$(document).ready(function(){
            $('#topnav').children('.nav').mouseover(function()
            {
		dropdown = $(this).children('.dropdown');
                offset_top = $(this).height() + $(this).position().top;
            if($(this).offset().left + dropdown.width() > $(window).width()){
                dropdown.css({'top' : offset_top, 'right' : 0});
	     }else{
                dropdown.css({'top' : offset_top, 'left' : 0});
				}
                dropdown.css('display', 'block');
            });

            $('#topnav').children('.nav').mouseleave(function()
            {
                $(this).children('.dropdown').css('display', 'none');
            });
});

