$(document).ready(function(){
    var fadedelay = 220;
    $('#topmenu ul li').hover(function(){
        //This node - li
        var node = $(this);
        //Coords for position the Third ul
        var coords = node.position();
        //If child node is Third ul
        var nodetochange = node.find('ul').first();
        if(nodetochange.hasClass('third'))
        {
            //Get width of current item
            var width = node.width();
            //Stop current animation and show ul, then set the position
            node.find('ul').first().stop(true,true).fadeIn(fadedelay).css('top',coords.top).css('margin-left',width);
        }
        else
        {
            //If child node not Third ul do
            node.find('ul').first().stop(true,true).fadeIn(fadedelay);
        }
    },function(){
        //When hover is out of item
        var node = $(this);
        node.find('ul').first().stop(true,true).fadeOut(fadedelay);
    });
    $('#topmenu ul li a').click(function(){
        //Make unnactive link using - #
        var node = $(this);
        var link = node.attr('href');
        //If link has not - #, execute link
        if(link=='#')
        {
            return false;
        }
    });
    $('#topmenu ul li').each(function(){
        //Find all items which have ul list, and set arrow on the background
        var node = $(this);
        var subnode = node.find('ul');
        if(subnode.html()!=null)
        {
            //Plese note, that topmenu-arrow.png sets in the CSS file of this menu - topmenu.css
            node.addClass('arrow'); 
        }
    });
});
