$(document).ready(function(){
// pbsBig image rotator
  if ($('.pbsBigCtnrOut').length > 0) {
    capCurrentPbsTopLayerName = '.pbsBigChild4';
    capNewLayerJQ = $(capCurrentPbsTopLayerName);
    capImageRotateFiredManually = false;
    $(".pbsBigChildHeadline").bind("mouseover", function() {
      capImageRotateFiredManually = true;
      return imageRotate($(this));
    });
    capAutoRotator = window.setInterval(showNextPbsImage, 5000);
    window.setTimeout(function (a,b) { clearInterval(capAutoRotator); }, 40002);
  }

// phsSlide image rotator
  if ($('.pbsSlideCtnrOut').length > 0) {
    capCurrentPbsSlideTopLayerName = '.pbsSlideChild1';
    capNewPbsSlideLayerJQ = $(capCurrentPbsSlideTopLayerName);
    capPbsSlideRotateFiredManually = false;
    $(".pbsSelector").bind("mouseover", function() {
      capPbsSlideRotateFiredManually = true;
      return slideRotate($(this).attr('rel'));
    }).bind("click", function() { return false });
    capAutoSlideRotator = window.setInterval(showNextPbsSlideImage, 5000);
    window.setTimeout(function (a,b) { clearInterval(capAutoSlideRotator); }, 40002);
  }
});

/**
  * Changes to the slide number passed in
  *
  * @param  int e                               The slide number to make visible
  * @return boolean                             Always returns false
  */
function slideRotate(e) {
  capPbsSlideNewLayerName = '.pbsSlideChild' + e;
  capPbsSlideNewLayerJQ = $(capPbsSlideNewLayerName);
  if (capPbsSlideNewLayerJQ.hasClass('pbsSlideVisible')) return false;

  // reference the relevant layers
  $('.pbsSlideVisible').removeClass('pbsSlideVisible');
  capPbsSlideNewLayerJQ.addClass('pbsSlideVisible');
  $('.pbsSelCurrent').removeClass('pbsSelCurrent');
  $('.pbsSel'+e).addClass('pbsSelCurrent');
  
  // cycle the old reference
  capCurrentPbsSlideTopLayerName = capPbsSlideNewLayerName;

  return false;
}
function showNextPbsSlideImage() {
  if (capPbsSlideRotateFiredManually === false) {
    capNewPbsSlideLayerJQ = $('.pbsSlideVisible').next().next('.pbsSlideChildCtnrOut');
    if (capNewPbsSlideLayerJQ.length === 0) {
      capNewPbsSlideLayerJQ = $('.pbsSlideVisible').siblings('.pbsSlideChildCtnrOut:first');
    }
    capPattern = /pbsSlideChild\d+/;
    capNewLayerName = capPattern.exec(capNewPbsSlideLayerJQ.attr('class'));
    capPattern = /\d+/;
    capNewLayerName = capPattern.exec(capNewLayerName);
    if (capNewLayerName != null) slideRotate(capNewLayerName);
  }
}

//for pbsBig image marquee
function imageRotate(e) {
  capPattern = /pbsBigChild[1-4]/;
  capNewLayerName = '.' + capPattern.exec(e.parent().parent().parent().attr('class'));
//  alert(capNewLayerName + ':' + capCurrentPbsTopLayerName);
  if (capCurrentPbsTopLayerName == capNewLayerName) return true;

  // reference the relevant layers
  capNewLayerJQ = e.parent().parent().parent();
  capOldLayerJQ = capNewLayerJQ.parent().find(capCurrentPbsTopLayerName);
  capNewLayerImage = capNewLayerJQ.find(".pbsBigChildImage");
  capOldLayerImage = capOldLayerJQ.find(".pbsBigChildImage");
  
  // cycle the old reference
  capCurrentPbsTopLayerName = capNewLayerName;

  // run the effects
  capNewLayerJQ.parent().find('.pbsBigChildImage').removeClass('pbsBciVisible');
  capNewLayerJQ.siblings('.pbsBigChildCtnrOut').andSelf().css('z-index',200);
  capOldLayerImage.addClass('pbsBciVisible').show();
  capNewLayerImage.addClass('pbsBciVisible').hide().show('slow');
  capNewLayerJQ.css('z-index',202);
  capOldLayerJQ.css('z-index',201);
  return false;
}
function showNextPbsImage() {
  if (capImageRotateFiredManually === false) {
    e = capNewLayerJQ.next('.pbsBigChildCtnrOut');
    if (e.size() === 0) {
      e = capNewLayerJQ.siblings('.pbsBigChildCtnrOut:first');
    }
    e = e.find('.pbsBigChildHeadline');
    imageRotate(e);
  }
}

