      
$(function(){
    
    $('#stat').tabs();
    $('.show-code').fancybox({
        'onComplete'        : function() {
            $('#fancybox-content .nastr').hide();
        }
    });
    $('.show-set').fancybox({
        'onComplete'        : function() {
            $('#fancybox-content .code').hide();
        }
    });
    $(".flash-stat").fancybox({
        'autoDimensions'    : false,
        'width'                 : 800,
        'height'                : 'auto',
        'transitionIn'      : 'none',
        'transitionOut'     : 'none',
        'onComplete'        : function() {
            $('#fl').remove();
        }
    });
    $('#profile').click(function() {
    $('#edit_profile').slideToggle('slow', function() {});
    });
    
    var content = $('#top_menu').html();
    if (content != null){
        $('#for-stat').show();
    }
    $('#top_menu').remove();
    $('#stat_menu').append(content);
    
    var removetab = function(tabselector, index) {
        $(".removetab").click(function(){
            $(tabselector).tabs('remove',index);
        });
    };
    var tabs = $('#submenu').tabs({
        ajaxOptions: {
            error: function( xhr, status, index, anchor ) {
                $( anchor.hash ).html(
                    "Возникла ошибка при загрузке аналитики"  );
            }
        },

        spinner: '',
        add: function(event, ui) {
            $(this).tabs('select',ui.index);
            removetab($(this), ui.index);
        },
        load: function(event, ui) {
            removetab($(this), ui.index);
            if (site_id){
                var options = { path: '/', expires: 1000 };
                var current = $('.ui-state-active a').attr('id');
                $.cookie('active_tab'+site_id,  null);
                $.cookie('active_tab'+site_id,  current, options);
            }
           
        }
    });
    if (site_id){
        var current_id = $.cookie('active_tab'+site_id);
        cookie_li = $('a#'+current_id).parent()
        var index = $('li.ui-corner-top').index(cookie_li);
        $('#submenu').tabs( "select" , index );
        $('.left_menu_select').click(function() {
            var options = { path: '/', expires: 1000 };
            var active_view = $(this).attr('id');
            $.cookie('active_view'+site_id,  active_view, options);
            return true;
        });
    }
    if (document.anchors['active']) document.location.href='#active';
    
    
    $('.fc').fancybox();
    var this_url = location.href;
    splitted = this_url.split('#');

    $('a#'+splitted[1]).click();
});

$(function(){
    $("#img_selector img").live('click', function() {
        $("#img_selector img").removeClass('active');
        $(this).addClass('active');

        url = $(this).attr('src').split('/');
        counter_type = url[2].split('.');

        $('#img_selector input').val(counter_type[0]);
    });

});

$(function(){
    $("#img_selector_other img").live('click', function() {
        $("#img_selector_other img").removeClass('active');
        $(this).addClass('active');

        url = $(this).attr('src').split('/');
        counter_type = url[2].split('.');

        $('#img_selector_other input').val(counter_type[0]);
    });

});
