// We need the host root URL to execute the AJAX calls
baseURL = window.location.protocol + "//" + window.location.host;

// News list template
var template = '<li class="list-group-item"><a href="#LINK#" target="_blank">#TITLE#</a></li>';

// Busy Processing Indicator
$.ajaxSetup({
    beforeSend: function () {
        $("#loading").show();
    },
    complete: function () {
        $("#loading").hide();
    }
});


//AJAX Call to refresh the Main Panel after user clicks on a menu item
function refreshNewsSource(obj) {

    var params;
    var id = obj.attr('id');

    params = {
        ns: id
    };

    // For local News Sources we have to fecth JQuery.data to know the location (eg.: DF, SP, etc.)
    if (id == 'local') {
        params.local = obj.data('state');
    }

    // AJAX call to refresh the news source
    $.get(
        baseURL + '/most_read_ns',
        params,
        function (responseContent) {
            //Set the title of the news
            $('#aml-source').text(responseContent.header);

            //Remove old news
            $('.list-group-item', '#aml-list').remove();

            //Now set the list of news
            var newsList = $('#aml-list');
            for (var i = 0; i < responseContent.news.length; i++) {
                var n = template.replace('#LINK#', responseContent.news[i].link).replace('#TITLE#', responseContent.news[i].title);
                newsList.append(n);
            }
        },
        'json'
    );
}

// Menu Item click handler
$('#aml-menu > a.list-group-item').click(function () {

    //Highlight the correct menu item
    $('#aml-menu > a.list-group-item').removeClass('active');
    $(this).addClass('active');

    refreshNewsSource($(this));
});

//National/International buttons handler
$('.aml-btn').click(function(){

    var id = $(this).attr('id');

    if(id == 'btn-national') {
        $('.national').css('display', 'block');
        $('.international').css('display','none');
    } else {
        $('.national').css('display','none');
        $('.international').css('display', 'block');
    }






});
@@ -1482,122 +1482,156 @@
 %7D%0A%0A/
-/ M
+*%0A Activates selected m
 enu 
-I
+i
 tem 
-click handler%0A$('#aml-menu %3E a.list-group-item').click(function (
+(and deactivates previous selected menu item)%0A */%0Afunction toggleMenuItem(menuItem
 ) %7B%0A
-%0A
     //
-Highlight the correct menu
+Remove previous selected
  ite
@@ -1698,23 +1698,57 @@
 ');%0A    
-$(this)
+//Activate current menu item%0A    menuItem
 .addClas
@@ -1764,56 +1764,71 @@
 ');%0A
-%0A
     
-refreshNewsSource($(this)
+$(this).addClass('active'
 );%0A%7D
-);
 %0A%0A/
-/
+*%0A Changes between 
 National
 /Int
@@ -1823,17 +1823,21 @@
 National
-/
+ and 
 Internat
@@ -1846,23 +1846,120 @@
 nal 
-buttons handler
+news source%0A Activates selected menu (based on the first news source of the national or international list)%0A */%0A
 %0A$('
@@ -1983,18 +1983,20 @@
 function
+ 
 ()
+ 
 %7B%0A%0A    v
@@ -2026,16 +2026,35 @@
 d');
+%0A    var firstItem;
 %0A%0A    if
 (id 
@@ -2049,16 +2049,17 @@
 %0A%0A    if
+ 
 (id == '
@@ -2157,32 +2157,33 @@
 ).css('display',
+ 
 'none');%0A    %7D e
@@ -2171,24 +2171,69 @@
 ', 'none');%0A
+        firstItem = $('.national').first();%0A%0A
     %7D else %7B
@@ -2270,16 +2270,17 @@
 isplay',
+ 
 'none');
@@ -2341,15 +2341,283 @@
     
-%7D%0A%0A%0A%0A%0A%0A
+    firstItem = $('.international').first();%0A    %7D%0A    toggleMenuItem(firstItem);%0A    refreshNewsSource(firstItem);%0A%7D);%0A%0A/*%0A Select and refresh news source%0A */%0A$('#aml-menu %3E a.list-group-item').click(function () %7B%0A    toggleMenuItem($(this));%0A    refreshNewsSource($(this));
 %0A%7D);

Fix #11