(function($) {
  $(document).ready(function() {

    // All pages
    addBreadcrumbsBackgrounds();

    // Only run on pages where body contains the class jsChevron
    // This if statement can be deleted when it's required for all sites, please remove the class from the design (45136)
    //if ($('body').hasClass('jsChevron'))
    //  hideNavChevron();

    // Add new function calls common to all Tait mini sites here

  });  
})(jQuery);


function addBreadcrumbsBackgrounds() {

  // Add class to each <li> in the breadcrumbs <ol>. The class is prefixed by 'bread' and suffixed by the breadcrumb number.
  
  // First find number of crumbs
  var noOfCrumbs = $("#breadcrumbs ol li").length;
  
  var crumb = 1;
  $("#breadcrumbs ol li").each(function() {
    $(this).addClass("bread" + crumb);
    
    // Add a class of 'last' to the <a> tag within the <li> if the crumb is the last one.
    if (crumb == noOfCrumbs) {
      $(this).find("a").addClass("last");
    } else {
      $(this).find("a").removeClass("last");
    }
    
    crumb++;
  });

} // end of addBreadcrumbsBackgrounds


function hideNavChevron() {

  // Hides the navigation chevrons for menu items that have no children

  $('#left-nav').find('li a').each(function() {

    var currentElement = $(this);
currentElement.css('background-image', 'none');

    if (currentElement.hasClass('hierarchy')) {
      currentElement.css('background-image', 'url("/__data/assets/image/0015/52305/nav-expanded.gif")');
    }
    else {

      var id = currentElement.attr('id').replace('left-nav-','');
      $.get('/does-asset-have-children?id=' + id, function(data) {
//        if (data == 0)
//          currentElement.css('background-image', 'none');
        if (data != 0)
          if (currentElement.hasClass('current'))
            currentElement.css('background-image', 'url("/__data/assets/image/0015/52305/nav-expanded.gif")');
          else
            currentElement.css('background-image', 'url("/__data/assets/image/0016/52306/nav-unexpanded.gif")');
      });

    }

  });

}


// Add new function declarations common to all Tait mini sites here
