var mx = 0;
var my = 0;
var defs = new Array();
    defs['First Time Homebuyers'] = "Anyone that has not owned or co-owned their own residence within the past 3 years.";
    defs['Targeted Area'] = "An areas where the Federal government is trying to promote home ownership.";
    defs['Must Have'] = "The features that <b>must</b> be present in the house that you are about to buy (e.g. multiple bedrooms if you have children).";
    defs['Want to Have'] = "The features that you would want to have in the house but are not absoloutely necessary.";
    defs['Would Like'] = "Optional features which may be an added bonus in the house, but you can do without.";
    defs['Seller\'s Agents'] = "An agent who gets a commission from the sale of the property, so their commission is rolled into the sale price";
    defs['Fixed Rate Mortgage'] = "Interest rate doesn't change. The loan is amortized over the length of the term &amp; the per month mortgage payment is fixed.<br/>NOTE: some variation can occur for real estate taxes or other components, but not the loan itself.";
    defs['15 year Fixed Rate'] = "A fixed rate mortgage that has to be paid back in 15 years. It usually gets a better interest rate than the 30 year.";
    defs['30 year Fixed Rate'] = "A fixed rate mortgage that has to be paid back in 30 years. It allows you to have a lower monthly payment than the 15 year.";
    defs['Adjustable-Rate Mortgage (ARM)'] = "Has an adjustable rate, so your payments may go up or down. The rate changes based on a published market index(often a One-Year treasury bond index or the Cost Of Funds Index).";
    defs['Convertible to Fixed Rate ARM'] = "An optional feature that lets you convert your ARM to a Fixed rate mortgage after a period of time. Conversion rules differ between lenders &amp; must be understood.";
//    defs[''] = "";
//    defs[''] = "";
var imgs = new Array(); //what images to use (the src)
    imgs[imgs.length] = 'images/people/bert.jpg';
    imgs[imgs.length] = 'images/people/bruce.jpg';
var blurbs = new Array(); //what phrases to use
    blurbs[blurbs.length] = "At Aspen Mortgage, we believe it's our service that keeps our clients coming back";
    blurbs[blurbs.length] = "As a small company, we can ensure our customers the quickest time to loan closure they can expect";
    blurbs[blurbs.length] = "With over 30 years combined experience, you can be assured you're getting the best service possible";
    blurbs[blurbs.length] = "We focus on each of our customers. Unlike a large company, your loan won't get lost in some huge pile";
    blurbs[blurbs.length] = "We specialize in individual, personal, honest service";
    blurbs[blurbs.length] = "Mortgages have become increasingly complex, &amp; can seem daunting. We strive to make it painless and worthwhile";
    blurbs[blurbs.length] = "Because we're small, we're able to give our clients the best personal service";
    blurbs[blurbs.length] = "We constantly look for the best sources of mortgage money, to offer a broad range of loan programs at the best interest rates available";
    blurbs[blurbs.length] = "Let us help you realize the American Dream of Home ownership. We'll work closely with you to tailor to your needs";
    blurbs[blurbs.length] = "Here we help you buy the most house you can afford while comfortably staying in your budget";
    blurbs[blurbs.length] = "We have access to more than 40 residential lenders and over 100 loan programs";
    blurbs[blurbs.length] = "Since real estate is the single largest investment most ever acquire, it is vital to secure the best financing available";
    blurbs[blurbs.length] = "Our most valuable asset is our ability to find the best loan to meet your individual needs";
    blurbs[blurbs.length] = "As your Mortgage Broker, we will prepare your origination documents, work face-to-face with you, define your borrowing limits, &amp; protect you during the lending process";
    blurbs[blurbs.length] = "We will structure your home loan to streamline the lending process";
    blurbs[blurbs.length] = "At your request, we can obtain loan approval in less than four hours";
    blurbs[blurbs.length] = "From first-time home buyers, to bare land financing, or jumbo loans, we can handle a wide range of lending programs";
    blurbs[blurbs.length] = "A solution oriented approach is the mindset we maintain";
    blurbs[blurbs.length] = "Our vast knowledge and experience in evaluating loans, properties, and borrowers enables us to create lending solutions for each of our clients";
    blurbs[blurbs.length] = "We ask the right questions, which are a vital resource for your real estate lending transaction";
    blurbs[blurbs.length] = "We represent you, not a bank or a single financial institution";
    blurbs[blurbs.length] = "Above all else, we explain your options &amp; help you make an informed choice that should substantially add to your personal wealth";
    blurbs[blurbs.length] = "Don't know how much home you can afford? We provide FREE pre-qualifications";

var imgI = -1;
var blurb = null;
var blurbI = -1;
var numSeconds = 8; //Num of Seconds before blurb switches
$(document).ready(function(){
  $(document).mousemove(function(e){
    mx = e.pageX;
    my = e.pageY;
  });
  navSetup();
  tabSetup();
  footerSetup();
  blurbSetup();
  definitionSetup();
});
function navSetup() {
  var u = window.location.href;
  u = u.replace(/^.*?(\w+\.html).*$/, '$1').toLowerCase();
  if (u == window.location.href)
    u = '';
  var nav = document.createElement('div');
  nav.id = 'navBar';
  nav.innerHTML = '';
  if (u != '' && u != 'index.html') {
    nav.innerHTML =
      '<a href="index.html">'+
        '<img src="images/icon/home.png" title="Home"/><br/>'+
        'Home'+
      '</a><br/><br/><br/>';
  }

  var links = new Array();
  links[links.length] = 'Buy Now|Rates have never been better, and homes are starting to hold their value again|buy.png|purchase.html';
  links[links.length] = 'Steps to Buy|Explanation of the Home Purchasing Process|steps.png|steps.html';
  links[links.length] = 'Mistakes to Avoid|The Top 10 mistakes people make when buying a home, refinancing, or getting a home equity loan|mistakes.png|top10.html';
  links[links.length] = 'Meet Us|Learn more about us|meet.png|about.html';
  links[links.length] = 'Mortgage Basics|Resources to teach you about mortgages|101.png|http://rws.rwstools.com/templateroot/Articles.asp?PVLID=281" target="_blank';
  for (var i = 0; i < links.length; ++i) {
    var temp = links[i].split('|');
    if (u != temp[3]) {
      nav.innerHTML +=
        '<a href="'+temp[3]+'">'+
          '<img src="images/icon/'+temp[2]+'" title="'+temp[1]+'"/><br/>'+
          temp[0]+
        '</a><br/><br/><br/>';
    }
  }
  document.body.appendChild(nav);
}
function blurbSetup() {
  blurb = document.createElement('div');
  blurb.id = 'blurb';
  document.body.appendChild(blurb);
  blurbSwitch();
  setInterval('blurbSwitch()', numSeconds*1000);
}
function blurbSwitch() {
  $(blurb).fadeOut('slow', function() {
    imgI = (imgI+1) % imgs.length;
    var lastBlurb = blurbI;
    while (lastBlurb == blurbI)
      blurbI = Math.floor(Math.random()*blurbs.length);
    var ti = imgs[imgI];
    var tb = blurbs[blurbI];
    blurb.innerHTML = "<img src='"+ti+"'/><br/>"+tb;
    $(blurb).fadeIn('slow');
  });
}
function tabSetup() {
  $('div', '.tabs').click(function(){
    var id = this.id.substr(4); //chop off "tab_"
    $('div', '.tabs').each(function(){
      var id2 = this.id.substr(4); //chop off "tab_"
        $('#'+id2).addClass('invisible');
        $(this).removeClass('active');
    });
    $('#'+id).removeClass('invisible');
    $(this).addClass('active');
  });
}
function definitionSetup() {
  var popover = document.createElement('div');
  var arrow = document.createElement('div');
  var text = document.createElement('div');
  popover.className = 'invisible';
  popover.id = 'popover';
  arrow.id = 'popover_arrow';
  text.id = 'popover_text';
  text.innerHTML = '<img src="images/icon/close.png" onclick="hideDef()" title="Close Definition" />';
  popover.appendChild(arrow);
  popover.appendChild(text);
  document.body.appendChild(popover);

  $('.definition').click(function(){
    var txt = this.innerHTML;
    if (defs[txt]) {
      var l = (mx - 150) + 'px';
      var t = (my - 16) + 'px';
      var pt = document.getElementById('popover_text');
      var temp = pt.innerHTML.replace(/^(.*?>).*$/, '$1');
      pt.innerHTML = temp + defs[txt];
      $('#popover').css({left:l,top:t});
      $('#popover').removeClass('invisible');
    }
  });
}
function hideDef() {
  $('#popover').addClass('invisible');
}
function footerSetup() {
  var foot = document.createElement('div');
  foot.id = 'footer';
  foot.innerHTML =
    "<br/><br/>"+
    "<a href='http://rws.rwstools.com/Data/Connection/cnnQuickAppRouter.asp?PVLID=281'>prequalify today</a>"+
    "<a href='http://fdc.rwstools.com/Data/Connection/cnnApplicationRouter.asp?AcctID=300613&amp;p=aspenmortgage1'>apply online</a>"+
    "<a href='http://fdc.rwstools.com/content/template0/articles.asp?AcctID=300613&amp;p=aspenmortgage1'>calculators</a>"+
    "<a href='http://fdc.rwstools.com/content/template0/articles.asp?AcctID=300613&amp;p=aspenmortgage1&amp;catid=7&amp;article=185'>market updates</a>"+
    "<a href='http://rws.rwstools.com/templateroot/LeadForms/NewsletterCenter.asp?PVLID=281'>newsletter</a><br/><br/>"+

    "<b>(801) 756-7434 &nbsp; Fax: (801) 756-9678 &nbsp; Email: bruce@aspenmtg.com<br/>"+
    "250 West Main, American Fork, Utah 84003</b><br/>"+
    "<img src='images/icon/ehl.png' title='Equal Housing Lender' />";
  document.body.appendChild(foot);

  /* WEB COUNTER CODE (I didn't like it)
    var counter = document.createElement('div');
    counter.id = 'web_counter';
    counter.innerHTML = "You are Visitor Number <a href='http://www.digits.com/'><img src='http://counter.digits.com/wc/-d/4/aspenmtg' /></a>";
    document.body.appendChild(counter);
  */
}

