

$(document).ready(function() {
     $('span:empty').hide();
      

     $(".through").each(function(i) {
          var myDateEnd = $(this).parent().children(".rss-date-end").text();
          var myTimeEnd = $(this).parent().children(".rss-time-end").text();

          if ((myDateEnd == "") && (myTimeEnd == "")) {
               $(this).hide();
          }
     });
     

      
     $('#other-sites').slideUp('medium');
     $('#show-hide').attr("href", "#"); // disable the link if we have JavaScript

     $('#show-hide').click(function(){
          var myScrolly=window.scrollY;
          if ($('#other-sites').is(':hidden')) {
               $('#other-sites').slideDown('slow');
               $('#show-hide').addClass('down');
          } else {
               $('#other-sites').slideUp('slow');
               $('#show-hide').removeClass('down');
          }
          window.scroll(0,myScrolly);
     });
     
     
     $('ul.sf-menu').superfish({
          dropShadows: false,
          autoArrows: false
     });
     
     String.prototype.reverse = function() {
          var splitext = this.split("");
          var revertext = splitext.reverse();
          var reversed = revertext.join("");
          return reversed;
     }
     
     function rssShowMore(e) {
          if ($(this).parent().siblings('.rss-details:visible').length > 0) {
               var myEmail = $(this).parent().parent().find('.rss-email a').text();
               var myPhone = $(this).parent().parent().find('.rss-phone').text();
               
               $(this).parent().parent().find('.rss-email a').text(myEmail.reverse());
               $(this).parent().parent().find('.rss-email a').attr("href", '');
               $(this).parent().parent().find('.rss-phone').text(myPhone.reverse());
               
               $(this).parent().siblings('.rss-details').find('span:empty').show();
               $(this).parent().siblings('.rss-details').hide();
               $(this).text("show more info")
          } else {
               var myEmail = $(this).parent().parent().find('.rss-email a').text();
               var myPhone = $(this).parent().parent().find('.rss-phone').text();
               
               $(this).parent().parent().find('.rss-email a').text(myEmail.reverse());
               $(this).parent().parent().find('.rss-email a').attr("href", 'mailto:' + myEmail.reverse());
               $(this).parent().parent().find('.rss-phone').text(myPhone.reverse());
               
               $(this).parent().siblings('.rss-details').find('span:empty').hide();
               $(this).parent().siblings('.rss-details').slideDown('fast');
               $(this).text("hide more info")
          }
     }

     $('#tabs div.rss-tab').hide(); // Hide all divs
     $('.rss-details').hide(); // Hide all the details
     $('.rss-more').bind("click", rssShowMore);
     $('#tabs div.rss-tab:first').show();
     $('#tab-1 .region-hub-website a').attr('href', 'https://hubs.apexcommunity.net/default.aspx');
     $('#tab-2 .region-hub-website a').attr('href', 'https://region1.apexcommunity.net/default.aspx');
     $('#tab-3 .region-hub-website a').attr('href', 'https://region2.apexcommunity.net/default.aspx');
     $('#tab-4 .region-hub-website a').attr('href', 'https://region3.apexcommunity.net/default.aspx');
     $('#tab-5 .region-hub-website a').attr('href', 'https://region4.apexcommunity.net/default.aspx');
     $('#tab-6 .region-hub-website a').attr('href', 'https://region5.apexcommunity.net/default.aspx'); 
     $('#tabs #tab-1').show();
     $('#tabs #tab-1 .rss-feed').show(); // Show the first div
     $('#tabs #subNavigation ul li:first').addClass('active'); // Set the class for active state
     $('#tabs #subNavigation ul li a').click(function(){ // When link is clicked
           
          $('#tabs #subNavigation ul li').removeClass('active'); // Remove active class from links
          $(this).parent().addClass('active'); //Set parent of clicked link class to active
          var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
          $('#tabs div.rss-tab').hide();
          
          $(currentTab).show(); // Show div with id equal to variable currentTab
          return false;
     });     
});
