function addLinks() {
  $topicAssocArr = new Object();

  $("#tags li a").each(function() {
    $topicAssocArr[$(this).text()] = $(this).text();
    switch ($(this).text()) {
      case "Al-Qaeda":
        $topicAssocArr["Al-Qaida"] = $(this).text();
        break;
      case "America Online":
        $topicAssocArr["AOL"] = $(this).text();
        break;
      case "American League Championship Series":
        $topicAssocArr["ALCS"] = $(this).text();
        break;
      case "American League Division Series":
        $topicAssocArr["ALDS"] = $(this).text();
        break;
      case "Barack Obama":
        $topicAssocArr["President Obama"] = $(this).text();
        break;
      case "C.C. Sabathia":
        $topicAssocArr["CC Sabathia"] = $(this).text();
        $topicAssocArr["Sabathia"] = $(this).text();
        break;
      case "Cellular Phones":
        $topicAssocArr["cell phones"] = $(this).text();
        $topicAssocArr["cell phone"] = $(this).text();
        $topicAssocArr["cellphones"] = $(this).text();
        $topicAssocArr["cellphone"] = $(this).text();
        break;
      case "Facebook Inc.":
        $topicAssocArr["Facebook"] = $(this).text();
        break;
      case "Federal Bureau of Investigation":
        $topicAssocArr["FBI"] = $(this).text();
        $topicAssocArr["F.B.I."] = $(this).text();
        break;
      case "Hillary Rodham Clinton":
        $topicAssocArr["Hillary Clinton"] = $(this).text();
        break;
      case "Michael Bloomberg":
        $topicAssocArr["Mayor Bloomberg"] = $(this).text();
        $topicAssocArr["Bloomberg"] = $(this).text();
        break;
      case "New York Jets":
        $topicAssocArr["Gang Green"] = $(this).text();
        break;
      case "New York Yankees":
        $topicAssocArr["Yankee Stadium"] = $(this).text();
        $topicAssocArr["The Yankees"] = $(this).text();
        $topicAssocArr["Yankees"] = $(this).text();
        break;
      case "Republican National Committee":
        $topicAssocArr["RNC"] = $(this).text();
        break;
      case "Robert Joseph Halderman":
        $topicAssocArr["Robert \"Joe\" Halderman"] = $(this).text();
        break; 
      case "Twitter Inc":
        $topicAssocArr["Twitter"] = $(this).text();
        break;
      case "U.S. Congress":
        $topicAssocArr["Congressional"] = $(this).text();
      	$topicAssocArr["Congressman"] = $(this).text();
        $topicAssocArr["Congress"] = $(this).text();
        break;
      case "U.S. Democratic Party":
        $topicAssocArr["Democrats"] = $(this).text();
        break;
      case "U.S. House of Representatives":
        $topicAssocArr["House of Representatives"];
        break;
      case "U.S. Republican Party":
        $topicAssocArr["Republicans"] = $(this).text();
        $topicAssocArr["GOP"] = $(this).text();
        $topicAssocArr["G.O.P."] = $(this).text();
        break;
      case "U.S. Senate":
        $topicAssocArr["Senators"] = $(this).text();
        $topicAssocArr["Senator"] = $(this).text();
        $topicAssocArr["Senate"] = $(this).text();
        break;
      case "US State Department":
        $topicAssocArr["State Department"] = $(this).text();
        $topicAssocArr["State Dept."] = $(this).text();
        break;
      default:
        break;
    }//end switch*/
    
    //deal with topics that contain parentheses
    if ($(this).text().indexOf("(") != -1) {
      $strip = jQuery.trim($(this).text().substring(0, $(this).text().indexOf("(")));
      $topicAssocArr[$strip] = $(this).text();
    }//end if

    //deal with topics that contain other stuff
    if ($(this).text().indexOf(", NYPD") != -1) {
      $strip = jQuery.trim($(this).text().substring(0, $(this).text().indexOf(", NYPD")));
      $topicAssocArr[$strip] = $(this).text();
    }//end if
    
    

  });
  
  $count = 0;
  $(".story_body p").each(function() {
    $oldHTML = $(this).html();
    
    if ($oldHTML.indexOf('<object') == -1 && $oldHTML.indexOf('<a') == -1 && $oldHTML.indexOf('<embed') == -1 && $oldHTML.indexOf('<img') == -1) {
    
    for ($tName in $topicAssocArr) {
      $tNameRegExp = new RegExp($tName, "i");
      $linkRegExp = new RegExp("(?!<a .+?(^/)>(.+?)?)" + $tName + "(?!(.+?)?</a>)", "i");
      
      $topicString = $oldHTML.substring($oldHTML.search($tNameRegExp), $oldHTML.search($tNameRegExp)+$tName.length);
      
      if ($tName.toLowerCase() == "swine flu") {
        $newHTML = $oldHTML.replace($linkRegExp, '<a href="/t/Swine_Flu" class="topiclink">' + $topicString + '</a>');
      }//end if
      else {
        $newHTML = $oldHTML.replace($linkRegExp, '<a href="/t/' + $topicAssocArr[$tName].replace(/ /g, '_') + '" class="topiclink">' + $topicString + '</a>');
      }//end else
      
      if ($oldHTML != $newHTML) { 
        $oldHTML = $newHTML;
        $(this).html($newHTML);
        
        //what we need to do here is step thru the list of object properties 
        //and get rid of anything with this property's value.
        delete $topicAssocArr[$tName];
      }//end if
    }//end for
    
    }//end if
  });
  
  $(".blog_blurb p").each(function() {
    $oldHTML = $(this).html();
    if ($oldHTML.indexOf('<object') == -1 && $oldHTML.indexOf('<embed') == -1 && $oldHTML.indexOf('<img') == -1) {
    
    for ($tName in $topicAssocArr) {
      $tNameRegExp = new RegExp($tName, "i");
      $linkRegExp = new RegExp("(?!<a href.+?(^/)>(.+?)?)" + $tName + "(?!(.+?)?</a>)", "i");
      
      $topicString = $oldHTML.substring($oldHTML.search($tNameRegExp), $oldHTML.search($tNameRegExp)+$tName.length);
      
      if ($tName.toLowerCase() == "swine flu") {
        $newHTML = $oldHTML.replace($linkRegExp, '<a href="/t/Swine_Flu" class="topiclink">' + $topicString + '</a>');
      }//end if
      else {
        $newHTML = $oldHTML.replace($linkRegExp, '<a href="/t/' + $topicAssocArr[$tName].replace(/ /g, '_') + '" class="topiclink">' + $topicString + '</a>');
      }//end else
      
      if ($oldHTML != $newHTML) { 
        $oldHTML = $newHTML;
        $(this).html($newHTML);
        
        delete $topicAssocArr[$tName];
      }//end if
    }//end for
    
    }//end if
  });
}//end function

$(document).ready(function() {
  addLinks();
});