var current_image_index = 1;
var images;

function loadImage() {

  $('#header_banner img').fadeTo(500, 0.20, function() {
    $('#header_banner img').attr('src', images[current_image_index++ % images.length]);
  });
  
  $('#header_banner img').fadeTo(500, 0.99);
  
  setTimeout(loadImage, 5000);
  
}

function switchAd(ads) {
  LoadFrontAd((current_ad_index + 1 ) % ads.length);
}

function rotateImages(imgs) {

  images = imgs;
  
  setTimeout(loadImage, 5000);

}

$(function() {
  
  $('table.styled tr:even:not(.header)').addClass('alt');

  $('a').linkDisclaimer({
    disclaimer: "You are now leaving CUC Mortgage's web site. CUC Mortgage does not control external links and cannot guarantee the relevance, timeliness or accuracy of the materials provided by other agencies or organizations.",
    valid_domains: ['cuc.alpha.trabian.com', 'cucmortgage.com', '#', 'mattdean-macbook.local:3000', 'secure.cucmortgage.com', 'secure2.cucmortgage.com', 'cuc.mortgagewebcenter.com', 'estatusii.loanware.com']
  });
  
  $('a[href$=.pdf]').attr('target', '_blank');

  $('a[href=/cu/build]').click(function(e) {
    e.preventDefault();
    tb_show('testing', '/cu/build?KeepThis=true&TB_iframe=true&height=588&width=470')
  });
  
  $('.rss_feeds').wrapInner('<div class="rss_feeds_inner"></div>')

  $('.rss_feed').livequery(function() {
    $('.rss_feed .item:last').addClass('last');
  });

  $('#mortgage-bot').load("/mortgage_bot", function() {
    $(this).find('a.mortgage-bot-rate').click(function(e) {
      e.preventDefault();
      window.open(this.href, 'mortgagebotdetail', 'resizeable,scrollbars,toolbar=0,location=0,menubar=0,status=0,width=630px,height=400px');
    });
  });
  
  $('#appraisal-fee-form').validate({});

});