window.showGraph = function(category, tab, location) {
    if ($('#graphs #graphs-' + tab).length === 0) {
        $.ajax({
            method: "POST",
            url: category+"/graphs/"+tab+(location !== null ? "?bra_id="+location : ""),
            success: function (graphs) {
                $('#graphs').append(graphs);
                $(graphs).find('a').click(function() {
                    //window.history.pushState("", "", window.location+$(graphs).find('a')[0].href.split('/'+lang)[1]);
                })
            }
        });
    }
    $('#graphs').show();
    $("#graphs").children().hide();
    $('#graphs #graphs-' + tab).show();
}

$('a[class="pull-right btn btn-primary btn-xs m-r-lg"]').click(function() {
    var link = $(this).attr('href');
    $('li[role="presentation"] a[href="'+link+'"]').closest('li').addClass('active').siblings().removeClass('active');
});

$(document).ready(function () {
    $(function() {
        var jcarousel = $('.jcarousel');

        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
                var carousel = $(this),
                    width = carousel.innerWidth();

                if (width >= 600) {
                    width = 200;
                } else if (width >= 350) {
                    width = 170;
                }

                carousel.jcarousel('items').css('width',width);
            })
            .jcarousel({
                wrap: 'circular'
            });

        $('.jcarousel-control-prev').jcarouselControl({
            target: '-=1'
        });

        $('.jcarousel-control-next').jcarouselControl({
            target: '+=1'
        });

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 4) {
            $('.jcarousel-control-prev').addClass("hidden-lg")
            $('.jcarousel-control-next').addClass("hidden-lg")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 3) {
            $('.jcarousel-control-prev').addClass("hidden-md")
            $('.jcarousel-control-next').addClass("hidden-md")
        }

        if ($('.jcarousel-wrapper .jcarousel ul li').length <= 2) {
            $('.jcarousel-control-prev').addClass("hidden-sm")
            $('.jcarousel-control-next').addClass("hidden-sm")
        }
    });

    if($('#graphs .list-group.panel .active').parent().hasClass('collapse')){
        $('#graphs .list-group.panel .active').parent().attr('class', 'collapse in');
    }

    $('a[data-toggle="tab"]').on('shown.bs.tab', Category.changeTab);
});


$('.category .nav-graph .list-group-item').click(function() {
    $(this).addClass('selected').siblings().removeClass('selected');
    $(this).children().removeClass('selected');
    $(this).siblings().children().removeClass('selected');
});

var Category = (function() {

    function changeTab(e) {
        if ($(this).attr('graph') != null) {
            var category = this.dataset.id,
                location = this.dataset.location,
                tab = $(this).attr('aria-controls');

            var url = window.location.href.split('?')[0];

            if(url.split('/').length == 6)
                window.history.pushState('', '', url + '/' + tab);
            else{
                var url = window.location.href.split('?')[0];
                url = url.split('/');
                url.pop();
                url = url.concat(tab);
                url = url.join('/');
                window.history.pushState('', '', url);
            }

            showGraph(category, tab, location);
        } else {
            $('#graphs').hide();
        } 
    }

    return {
        changeTab : changeTab
    }

})();

@@ -21,24 +21,19 @@
 unction(
-category
+url
 , tab, l
@@ -161,17 +161,14 @@
 rl: 
-category+
+url + 
 %22/gr
@@ -177,13 +177,17 @@
 hs/%22
-+tab+
+ + tab + 
 (loc
@@ -213,17 +213,19 @@
 bra_id=%22
-+
+ + 
 location
@@ -2823,226 +2823,39 @@
 ion 
-changeTab(e) %7B%0A        if ($(this).attr('graph') != null) %7B%0A            var category = this.dataset.id,%0A                location = this.dataset.location,%0A                tab = $(this).attr('aria-controls');%0A%0A  
+getUrlBeforePageTab()%7B%0A
         
   va
@@ -2842,34 +2842,32 @@
 eTab()%7B%0A        
-  
 var url = window
@@ -2905,20 +2905,16 @@
         
-    
 if(url.s
@@ -2952,74 +2952,28 @@
     
-    
-window.history.pushState('', '', url + '/' + tab);%0A   
+return url;%0A
         
  els
@@ -2968,17 +2968,16 @@
         
- 
 else%7B%0A  
@@ -2990,50 +2990,25 @@
     
-    var url = window.location.href
+url = url
 .split('
 ?')%5B
@@ -3007,20 +3007,36 @@
 it('
-?
+/
 ')
-%5B0%5D
 ;%0A    
+        url.pop();%0A
     
@@ -3045,37 +3045,36 @@
       url = url.
-split
+join
 ('/');%0A         
@@ -3072,37 +3072,34 @@
             
-    url.pop()
+return url
 ;%0A          
@@ -3100,52 +3100,54 @@
     
-  
+%7D%0A
     
-  url = url.concat(tab);%0A     
+%7D%0A%0A    function updateUrl(tab)%7B%0A
         
    u
@@ -3142,37 +3142,46 @@
         
-  
+var
  url = 
-url.join('/'
+getUrlBeforePageTab(
 );%0A     
@@ -3183,24 +3183,16 @@
         
- 
-       
 window.h
@@ -3219,32 +3219,242 @@
  '', url
+ + '/' + tab
 );%0A    
+%7D%0A%0A
     
-    %7D
+function changeTab(e) %7B%0A        if ($(this).attr('graph') != null) %7B%0A            var location = this.dataset.location,%0A                tab = $(this).attr('aria-controls');%0A%0A            updateUrl(tab);
 %0A%0A      
@@ -3469,24 +3469,37 @@
 owGraph(
-category
+getUrlBeforePageTab()
 , tab, l

Fix show graph function