// JavaScript Document

$(function() {
		   
		   
   var zIndexNumber = 5000;
   $('div').each(function() {
      $(this).css('zIndex', zIndexNumber);
         zIndexNumber -= 10;
   });
   $("#pageHeaderWrapper").css("z-index", "1");

   $("#sb-container").css("z-index", "6000 !important");
   $("#sb-overlay").css("z-index", "6000 !important");
   $("#sb-wrapper").css("z-index", "6000 !important");

   $(".slideshow a").css("z-index", "6000 !important");
   $(".slideshowFeature a").css("z-index", "6000 !important");

   $(".social-link-controls-wrapper").css("z-index", "6000 !important");

   $(".configuration-container").css("z-index", "20000");
   $(".appearance-container").css("z-index", "20000");





$('<div id="HomeBtn"></div>').insertBefore(".horizontalNavigationBar .content-navigation");


/* ************************************** */
   /* equalize column heights */
   function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
   }

   /* Set column Heights */
   equalHeight($(".list-journal-entry-wrapper .journal-entry"));
/* ************************************** */



/* Homepage Features */
$("#LatestInsights").load("/insights/ .list-journal-entry-wrapper", function(){ 
  //callback...
  $("#LatestInsights .journal-entry-wrapper:gt(5)").css("display", "none");
}); 

$("#LatestPressReleases").load("/insights/category/news-releases/ .list-journal-entry-wrapper", function(){ 
  //callback...
  $("#LatestPressReleases .journal-entry-wrapper:gt(5)").css("display", "none");
}); 

$("#LatestHotlinks").load("/insights/category/hotlinks/ .list-journal-entry-wrapper", function(){ 
  //callback...
  $("#LatestHotlinks .journal-entry-wrapper:gt(5)").css("display", "none");
}); 

$("#LatestInsightsBtn").css("background", "#333");
$("#LatestInsightsBtn a").css("color", "#fff");

$("#LatestInsightsBtn").mouseenter(function() {
  $("#LatestInsights").css("display", "block");
  $("#LatestPressReleases").css("display", "none");
  $("#LatestHotlinks").css("display", "none");
  $("#LatestInsightsBtn").css("background", "#333");
  $("#LatestInsightsBtn a").css("color", "#fff");
  $("#LatestPressReleasesBtn").css("background", "#eee");
  $("#LatestPressReleasesBtn a").css("color", "#333");
  $("#LatestHotlinksBtn").css("background", "#eee");
  $("#LatestHotlinksBtn a").css("color", "#333");
});

$("#LatestPressReleasesBtn").mouseenter(function() {
  $("#LatestInsights").css("display", "none");
  $("#LatestPressReleases").css("display", "block");
  $("#LatestHotlinks").css("display", "none");
  $("#LatestInsightsBtn").css("background", "#eee");
  $("#LatestInsightsBtn a").css("color", "#333");
  $("#LatestPressReleasesBtn").css("background", "#333");
  $("#LatestPressReleasesBtn a").css("color", "#fff");
  $("#LatestHotlinksBtn").css("background", "#eee");
  $("#LatestHotlinksBtn a").css("color", "#333");
});

$("#LatestHotlinksBtn").mouseenter(function() {
  $("#LatestInsights").css("display", "none");
  $("#LatestPressReleases").css("display", "none");
  $("#LatestHotlinks").css("display", "block");
  $("#LatestInsightsBtn").css("background", "#eee");
  $("#LatestInsightsBtn a").css("color", "#333");
  $("#LatestPressReleasesBtn").css("background", "#eee");
  $("#LatestPressReleasesBtn a").css("color", "#333");
  $("#LatestHotlinksBtn").css("background", "#333");
  $("#LatestHotlinksBtn a").css("color", "#fff");
});


/* Twitter Feed */
$("#sectionContent3269853").appendTo("#TwitterFeed");


/* slideshow links */
if ($('.nivoSlider a.nivo-imageLink').css('display') == 'block'){
   $(this).css("z-index","6000");
};





/* Journal Entry Titles */
$(".single-journal-entry-wrapper .journal-entry h2").insertBefore(".single-journal-entry-wrapper .journal-entry .body");



/* Sub-navigation (prev and next btns) */
$('.journal-entry-navigation-next').each(function(){ 
      var navBtnTitle = $(this).html();
      $(this).html("»"); 
});

$('.journal-entry-navigation-prev').each(function(){ 
      var navBtnTitle = $(this).html();
      $(this).html("«"); 
});



$(".list-journal-entry-wrapper .journal-entry .body p strong:contains(Updated)").parent().css("display", "none");






/* Insights - - - - - - - - - - - - - - - - - */

$("#modulePage7438698 .single-journal-entry-wrapper").each(function(){
   $("#sidebar1Wrapper").css("display", "none");
});

/* override print link */
$(".print-item a").attr("href", "javascript:window.print()")



/* Insights Menu */ 
   
// Width, mouseover  
var BtnWidth = '180px'; 
       
// Default width  
var defBtnWidth = '8px';

// Animate the LI LINKS on mouse over, mouse out
$('#InsightsMenu li').click(function () {     
   // Make LI clickable  
   window.location = $(this).find('a').attr('href');  
}).mouseover(function (){  
   // mouse over LI and look for A element for transition
   $(this).animate( {
      width: BtnWidth
   }, { queue:false, duration:400 }); 
   $(this).find('a').css("visibility", "visible");
}).mouseout(function () {  
   // mouse out LI and look for A element and discard the mouse over transition  
   $(this).animate({width: defBtnWidth}, { queue:false, duration:400 });
   $(this).find('a').css("visibility", "hidden");
});   
       

/* Subscribe Btn */
$("#SubscribeBtn").insertAfter("#modulePage7438698 .list-journal-entry-wrapper, #modulePage7438698 .single-journal-entry-wrapper");

/* hotlinks newsletter promo */
$('<div class="hotlinksNewsletterPromo"></div>').appendTo(".single-journal-entry-wrapper .category-hotlinks .journal-entry");

/* set the text */
$(".hotlinksNewsletterPromo").html('<p>Get more Hotlinks from the Arc Aspicio Homeland Security Newsletter. Each week we hand select the stories that catch our attention and describe the weeks events.<br><a href="/newsletter/">Signup for the Newsletter ›</a></p>');







/* Business Ethics */
$("#modulePage7345354 .journal-entry .title a").removeAttr("href");


/* Approach */
$("#modulePage7436855 .journal-entry .title a").removeAttr("href");


/* Employee Benefits */
$("#modulePage7697621 .journal-entry .title a").removeAttr("href");


/* Contracts */
$("#modulePage7674890 .journal-entry .title a").removeAttr("href");





$('h2:contains(Page Not Found)').each(function(){ 
      var str = $(this).html(); 
      $(this).html(str.replace('Page Not Found','Page<br>Not<br>Found')); 
      $("h2").css('height', 'auto');
      $("#sidebar1Wrapper").css('display', 'none');
});

$('h2:contains(Website Login)').each(function(){ 
      var str = $(this).html(); 
      $(this).html(str.replace('Website Login','Website<br>Login')); 
      $("h2").css('height', 'auto');
      $("#sidebar1Wrapper").css('display', 'none');
});

$('.list-journal-entry-wrapper:contains(This journal does not yet contain any entries.)').each(function(){ 
      var str = $(this).html(); 
      $(this).html(str.replace('This journal does not yet contain any entries.','')); 
      $(".list-journal-entry-wrapper").css('display', 'none');
});

$(".adminLinkTable, .managedLinkTable").parent().css("z-index", "5000 !important");



});





/* simple spy */

$(function () {
    $('ul.spy1').simpleSpy(1, 10000); /* home - quotes */
});

(function ($) {    
$.fn.simpleSpy = function (limit, interval) {
      //limit = limit || 1;
      //interval = interval || 4000;
  
  return this.each(function () {
    // 1. setup
      // capture a cache of all the list items
    var $list = $(this),
      items = [], // uninitialised
      currentItem = limit,
      total = 0, // initialise later on
      height = $list.find('> li:first').height();
          
    // capture the cache
    $list.find('> li').each(function () {
      items.push('<li>' + $(this).html() + '</li>');
    });
    
    total = items.length;
    
    // chomp the list down to limit li elements    
    $list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

    // 2. effect        
    function spy() {
      // insert a new item with opacity and height of zero
      var $insert = $(items[currentItem]).css({
        height: 0,
        opacity: 0,
		display : 'none'
      }).prependTo($list);
                    
      // fade the LAST item out
      $list.find('> li:last').animate({ opacity : 0}, 1000, function () {
        // increase the height of the NEW first item
        $insert.animate({ height : height }, 1000).css("display", "block").animate({ opacity : 1 }, 1000);

        // AND at the same time - decrease the height of the LAST item
        $(this).animate({ height : 0 }, 1000, function () {
            // finally fade the first item in (and we can remove the last)
            $(this).remove();
        });
      });
        
      currentItem++;
      if (currentItem >= total) {
        currentItem = 0;
      }
        
      // trigger the effect again in 4 seconds
      setTimeout(spy, interval);
    }
    
    spy();
  });
};    
})(jQuery);
