$(document).ready(function(){

    $("#menu li").hover(function(){
        var offset = $(this).offset();

        var pos = $(this).position();
        $(this).addClass("sfhover"); 
        
        if ($(this).hasClass("second sfhover")){
            $(this).children("ul").css("top", pos.top-1);
            $(this).children("ul").css("left", $(this).width());
            //$(this).children("ul").children("li").children("ul").children("li").width($(this).width());
            //$(this).children("ul").offset(pos.top, pos.left);
        }
        else{
            if ($(this).hasClass("second")){
                $(this).children("ul").css("top", 0);
                $(this).children("ul").css("left", $(this).width());
                //$(this).children("ul").children("li").children("ul").children("li").width($(this).width());
                //$(this).children("ul").offset(pos.top, pos.left);
                $(this).children("ul").width($(this).width());
            }else{
                /*if($(this).width() >= 200){
                    $(this).children("ul").width(200);
                    //$(this).children("ul").children("li").width($(this).width());
                    $(this).children("ul").children("li").children("a").width($(this).width()-20);
                }else{*/

                    $(this).children("ul").width(200);
                    //$(this).children("ul").children("li").width(200);
                    $(this).children("ul").children("li").children("a").width(180);
                //}
                $(this).children("ul").css("left", 0);
                $(this).children("ul").css("top", $(this).height());
            }
        }

    },function(){

        $(this).removeClass("sfhover");
            if ($(this).hasClass("second")){
                $(this).children("ul").css("top", 0);
                $(this).children("ul").css("left", $(this).width());
                //$(this).children("ul").children("li").children("ul").children("li").width($(this).width());
                //$(this).children("ul").offset(pos.top, pos.left);
                $(this).children("ul").width($(this).width());
            }        

    });

});

