$(document).ready(function(){
//headline image marquee
  capCurrentHfTopLayerName = '.hfBigChildCtnr4';
  capNewLayerJQ = $(capCurrentHfTopLayerName);
  capImageRotateFiredManually = false;
  $(".hfBigChildHeadline").bind("mouseover", function() {
    capImageRotateFiredManually = true;
    return imageRotate($(this));
  });
  capAutoRotator = window.setInterval(showNextHfImage, 5000);
  window.setTimeout(function (a,b) { clearInterval(capAutoRotator); }, 40002);
/* This is causing problems in IE7, remove it for now...
//collapse external links
  capTextWhenVisibleEL=$("#sbExtTitleAction").text();
  $("#sbExtTitleAction").parent().parent().click(function() { toggleExternalLinks(); });
  toggleExternalLinks();
*/
});

//for headline image marquee
function imageRotate(e) {
  capNewLayerName = '.' + e.parent().attr('class');
  if (capCurrentHfTopLayerName == capNewLayerName) return true;

  // reference the relevant layers
  capNewLayerJQ = e.parent();
  capOldLayerJQ = e.parent().parent().find(capCurrentHfTopLayerName);
  capNewLayerImage = e.parent().children(".hfBigChildImage");
  capOldLayerImage = capOldLayerJQ.children(".hfBigChildImage");
  
  // cycle the old reference
//  capOldLayerName = capCurrentHfTopLayerName;
  capCurrentHfTopLayerName = capNewLayerName;

  // run the effects
  e.parent().parent().find('.hfBigChildImage').removeClass('hfbciVisible');
  e.parent().siblings().andSelf().css('z-index',200);
  capOldLayerImage.addClass('hfbciVisible').show();
  capNewLayerImage.addClass('hfbciVisible').hide().show('slow');
  capNewLayerJQ.css('z-index',202);
  capOldLayerJQ.css('z-index',201);
  return false;
}
function showNextHfImage() {
  if (capImageRotateFiredManually === false) {
    e = capNewLayerJQ.next();
    if (e.size() === 0) {
      e = capNewLayerJQ.siblings(':first');
    }
    e = e.find('.hfBigChildHeadline');
    imageRotate(e);
  }
}
function toggleExternalLinks() {
  if ($("#sbExtTitleAction").text() == capTextWhenVisibleEL) { //currently showing all options, change to hidden mode
    $("#sbExtTitleAction").text(" (click to show)");
    $("#sbExternal > ul > li > ul").css('display','none');
  } else { //currently hiding some options, change to visible mode
    $("#sbExtTitleAction").text(capTextWhenVisibleEL);
    $("#sbExternal > ul > li > ul").css('display','block');
  }
}