jQuery(document).ready(function() {
	$(document).ready(function(){
		
		// Работа с меню
		var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 10);

        $('.mainmenu').hide();
        $('.menupanel').css({'visibility':'hidden'});
        var i = 0;
        var count = $('.mainitem').length;
        var panelWidth = $('.menupanel').width();
        var panelItemsSumWidth = 0;
        var diffPanelWidth = 0;
        var _this = this;
        
        $('.mainitem').each(function(){
        	var href = $(this).find('ul:first').find('b').find('a:first').attr('href');
        	
            if(i<(count-1)){
                if(!isIE)
            		$('.menupanel').append('<span><a tabindex="0" href="'+href+'" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" id="'+i+'_flyout"><span class="ui-icon ui-icon-triangle-1-s"></span>Text</a><img border="0" alt="" src="bar.gif"  style="margin-left: 15px;"/></span>');
                else{
                	$('.menupanel').append('<span><a tabindex="0" href="'+href+'" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" id="'+i+'_flyout"><span class="ui-icon ui-icon-triangle-1-s"></span>Text</a><img border="0" alt="" src="bar_ie.gif" style="margin-right: 20px;"/></span>');
                }
            }else
            	$('.menupanel').append('<span><a tabindex="0" href="'+href+'" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" id="'+i+'_flyout"><span class="ui-icon ui-icon-triangle-1-s"></span>Text</a><img border="0" alt="" src="bar2.gif"/></span>');
            $('#'+i+'_flyout').html($(this).find('ul:first').find('b').find('a:first').html());
    		$('#'+i+'_flyout').menu({ content: $(this).html(), flyOut: true });
    		var id = i+'_flyout';
    		i++;
        });
        $('.menupanel span').each(function(){
        	panelItemsSumWidth += $(this).width();
        });
        diffPanelWidth = (panelWidth - panelItemsSumWidth)/count-2;
        $('.menupanel span').each(function(){
        	$(this).css({'margin-left':(diffPanelWidth/2+7)+'px'});
        });
        $('.menupanel span a').each(function(){
        	$(this).css({'margin-right':(diffPanelWidth/2-18)+'px'});
        });
        $('.menupanel').css({'width':$('.menupanel').width()+'px'});
        $('.menupanel').css({'visibility':'visible'});
	});
});
