$(document).ready(function() {
  //check for cookie to alter health topics navigation on current page. -alan, 7/27/10
  if ($.cookie('alt_nav') == 'health') {
    //alter link title and link href. do not alter links on browse a-z health topics landing page.
    $("a[href$='/health-topics/abortion-4260.asp']").not('ul.l_sections_small a').text('Information about Abortion')
    $("a[href$='/health-topics/abortion-4260.asp']").not('ul.l_sections_small a').attr('href', '/health-topics/information-about-abortion-33272.htm')
    
    //sort left nav alphabetically (excluding first link) and add active class.
    alphaSortList('ul#side_nav_health', 'li:not(:first)');
    var pathname = window.location.pathname;
    if (pathname == '/health-topics/information-about-abortion-33272.htm') {
      $("ul#side_nav_health li a[href$='/health-topics/information-about-abortion-33272.htm']").parent().addClass('active');
    }
    
    //sort categories list alphabetically (excluding first link; landing page only).
    alphaSortList('ul#category_list_health', 'li:not(:first)');
    //now wrap category list on landing page into two columns.
    //same code as in global.js but has to execute after sort or sort will break.
    jQuery(".category_list ul").each(function(){
        $lis = jQuery(this).find("li");
        $inc = parseInt(($lis.length/2) + ($lis.length % 2 > 0 )); //Where N = 4
        jQuery.map([$inc, $inc*2], function(value) { //Where [$inc*1, $inc*2,...$inc*N]
            $lis.slice(value-$inc, value).wrapAll("<div class='wrap'></div>");
        });
    });
    $('.category_list ul div.wrap:last-child').addClass('wrap_last');
    
    //sort top nav alphabetically (excluding first link).
    alphaSortList('ul#nav_health_sub', 'li:not(:first)');
  }
});
