/*
    SmartBreadcrumbs
    
    Copyright (c) 2009-2011 Y-Times Publications, LLC. All Rights Reserved.
    Duplication is strictly prohibited without written consent of Y-Times Publications, LLC.
    www.ytimes.info

*/

function smartBreadcrumbs() {
  if (!document.getElementById("breadcrumbs"))
    return;

  // assign ids
  jQuery("#breadcrumbs .breadcrumbs").hide();
  jQuery("#breadcrumbs .breadcrumbs").each( function() {
    var id = "2A2A";
    var parts = jQuery(this).find("a");
    for (var i = 1; i < parts.length; i++)
    {
        if (!jQuery(parts[i]).parent().hasClass("prevLink") && !jQuery(parts[i]).parent().hasClass("nextLink"))
        {
          href = jQuery(parts[i]).attr("href");
          j = href.lastIndexOf("/");
          if (j>0)
             href = href.substring(j+1);
          j = href.indexOf(".");
          if (j>0)
             href = href.substring(0,j);

          var hex = "";
          for (j = 0; j < href.length; j++)
          {
              var h = href.toUpperCase().charCodeAt(j).toString(16);
              hex += h.toUpperCase();
          }
          id += hex;
        }
    }
    if (jQuery(this).attr("leaf")=="0")
    {
        href = location.href;
        j = href.lastIndexOf("/");
        if (j>0)
           href = href.substring(j+1);
        j = href.indexOf(".");
        if (j>0)
           href = href.substring(0,j);

        var hex = "";
        for (j = 0; j < href.length; j++)
        {
            var h = href.toUpperCase().charCodeAt(j).toString(16);
            hex += h.toUpperCase();
        }
        id += hex;
    }
    jQuery(this).attr("id",id);
  });
  var currentBCDiv = null;

  if (typeof(currentBC) != 'undefined' && currentBC)
  {
    if (jQuery("div[id*=" + currentBC + "]").length == 1)
    {
      currentBCDiv = jQuery("div[id*=" + currentBC + "]");
      currentBCDiv.css("display","block");
      SetCookie("currentBC", currentBCDiv.get()[0].id);
    }
    else if(jQuery("div[id*=" + currentBC + "]").length > 1)
    {
      currentBCDiv = jQuery("div[id*=" + currentBC + "]:first");
      currentBCDiv.css("display","block");
      SetCookie("currentBC", currentBCDiv.get()[0].id);
    }
    else
    {
      currentBCDiv = jQuery("#breadcrumbs div:first");
      currentBCDiv.css("display","block");
      SetCookie("currentBC", currentBCDiv.get()[0].id);
    }
  }
  else
  {
    currentBCDiv = jQuery("#breadcrumbs div:first");
    currentBCDiv.css("display","block");
    SetCookie("currentBC", currentBCDiv.get()[0].id);
  }

  if (currentBCDiv != null)
  {
      // show the current prev and next links, but only if there is a placeholder for it
      if (document.getElementById("divPrevNext"))
      {
          if (currentBCDiv.find(".prevLink").length > 0)
          {
               currentBCDiv.find(".prevLink").appendTo(jQuery("#divPrevNext")).show();
          }
          if (currentBCDiv.find(".nextLink").length > 0)
          {
               currentBCDiv.find(".nextLink").appendTo(jQuery("#divPrevNext")).show();
          }
      }
  }
}

jQuery(document).ready( function() {
  smartBreadcrumbs();
});

smartBreadcrumbs();

