var iMenuImagesCount = 0;
var iMenuImagesLoaded = 0;

jQuery.noConflict();
    function resizeMenu() {
        if (iMenuImagesLoaded < iMenuImagesCount) {
            setTimeout('resizeMenu()', 100);
            return;
        }

 
        jQuery('#MenuBar > li').show();
        
        jQuery('#MenuBar > li > a').each(function(){
            var item_height = jQuery(this).find('img').height()/2;
            
            jQuery(this).height(item_height);
            jQuery(this).hover(
                function (){
                    var item_height = jQuery(this).find('img').height()/2;
                    jQuery(this).find('img').css('margin-top', -item_height);
                },
                function(){
                    jQuery(this).find('img').css('margin-top', "0");
                }
            );

            jQuery('#MenuBar > li > a.active').find('img').each(function(){
                jQuery(this).css('margin-top', -jQuery(this).height()/2);
            });
            jQuery('#MenuBar > li > a.active').hover(
                function (){
                    var item_height = jQuery(this).find('img').height()/2;
                    jQuery(this).find('img').css('margin-top', -item_height);
                }

            );

        });

        jQuery('#MenuBar > li ul').hover(
            function (){
                var item_height = jQuery(this).parent('li').children('a').children('img').height()/2;
                jQuery(this).parent('li').children('a').children('img').css('margin-top', -item_height);
            },
            function(){
                jQuery(this).parent('li').children('a').children('img').css('margin-top', '0');
            }
        );



       jQuery('li.about_us > ul').width( jQuery('li.about_us a').width()*1.50);
       jQuery('li.projects > ul').width( jQuery('li.projects a').width()*1.3);

    }
jQuery(document).ready(
    function (){
        var oMenuImages = jQuery('#MenuBar > li > a img');

         iMenuImagesCount = oMenuImages.length;

        oMenuImages.each(function(){
            if (this.complete) {
                ++iMenuImagesLoaded;
            }
        });

        if (iMenuImagesLoaded < iMenuImagesCount) {
            oMenuImages.load(function(){
                ++iMenuImagesLoaded;
            });
        }

        resizeMenu();
        
        jQuery(window).resize(
            function () {
                resizeMenu();
            }
         );
    }
    
);
