  function modelTabShift(src, e) {
    var id = e.attr('id');
    $('.model-tab-box').each(function(){
      $(this).hide();
      if($(this).attr('id') == id) {
        $(this).show();
      }
    });
    $('.model-tab-btn').each(function(){
      $(this).removeClass('current');
    });
    src.parent().addClass('current');
    
    if(id == 'model-tab-overview') {
      $('#model-2-info').attr('id', 'model-info');
      $('#model-2-info-bottom').attr('id', 'model-info-bottom');
    } else {
      $('#model-info').attr('id', 'model-2-info');
      $('#model-info-bottom').attr('id', 'model-2-info-bottom');
    }
    
    if(id == 'model-tab-directions') {
        loadDirectionsMap(directionsMapObj.latitude,directionsMapObj.longitude,directionsMapObj.address_encoded,directionsMapObj.address_html,directionsMapObj.address_only_encoded,directionsMapObj.address_only);
    }
    
    return false;
  }
  
  function areaInfoTabShift(src, e) {
    var id = e.attr('id');
    $('.area-info-tab-box').each(function(){
      $(this).hide();
      if($(this).attr('id') == id) {
        $(this).show();
      }
    });
    $('.area-info-tab-btn').each(function(){
      $(this).removeClass('current');
    });
    src.parent().addClass('current');
    
    return false;
  }
  
  function fieldToggleFocus(e, title) {
    if(e.val() == title) 
      e.val('');
  }
  
  function fieldToggleBlur(e, title) {
    if(e.val() == '') 
      e.val(title);
  }
  
  function addOnlineApplicationRow(el_name) {
    $('.'+el_name)
      .clone()
      .removeClass(el_name)
      .css('display', 'table-row')
      .insertBefore('.'+el_name);
      
    return false;
  }
  
  function GM_createMarker(point, pointname, propHTML, iconname, pointdraggable) {
		var marker = new GMarker(point, {icon:iconname,draggable:pointdraggable} );
		var html = propHTML;
		GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(propHTML); });
    GEvent.addListener(marker, "mouseout", function() { marker.closeInfoWindow() ; });
		return marker;
  }
  
	function GM_viewProperty(x,y,markerName) {
		map.closeInfoWindow()

    var mypoint		= new GLatLng(y,x);
    var mymarker	= eval(markerName);
    var myhtml		= eval(markerName + '_HTML');
    map.setCenter(mypoint,12);
    mymarker.openInfoWindowHtml(myhtml);
		
  }
  
	function GM_clearMap() {
		map.clearOverlays();
  } 

  var directionsMapObj = {};
  var directionsMarker = {};
  var directionsOptions = {};
  var directionsHTML1 = '';
  var directionsHTML2 = '';
  var directionsHTMLText = true;
  var directionsRefreshFlag = false;
      
  function saveDirectionsMap(var1,var2,var3,var4,var5,var6) {
    directionsMapObj = {
      latitude: var1,
      longitude: var2,
      address_encoded: var3,
      address_html: var4,
      address_only_encoded:var5,
      address_only: var6
    };
  }

  function loadDirectionsMap(latitude,longitude,address_encoded,address_html,address_only_encoded,address_only) {
      if (GBrowserIsCompatible()) {
          if(el = document.getElementById("model-tab-directions-map")) {
              var map = new GMap2(el, {mapTypes:[G_NORMAL_MAP,G_SATELLITE_MAP]});
              map.addControl(new GSmallMapControl());
              map.addControl(new GMapTypeControl(true));
              map.setCenter(new GLatLng(latitude,longitude),12);
              map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.display = "none";

              var arrowIcon = new GIcon();
              arrowIcon.image = "http://www.google.com/mapfiles/arrow.png";
              arrowIcon.shadow = "http://www.google.com/mapfiles/arrowshadow.png";
              arrowIcon.iconSize = new GSize(39, 34);
              arrowIcon.shadowSize = new GSize(39, 34);
              arrowIcon.iconAnchor = new GPoint(19, 34);
              arrowIcon.infoWindowAnchor = new GPoint(19, 2);

              var point = new GLatLng(latitude,longitude);
              var marker = new GMarker(point, { icon:arrowIcon });
              
              var html = '<div id="model-tab-directions-map-window">';
              html += '<table><tr><td><h4>Address:</h4>';
              html += '<a href="http://maps.google.com/maps?q=' + address_encoded + '&f=q&source=s_q&hl=en&geocode=&ie=UTF8&t=m&view=map" target="_blank">';
              html += address_html;
              html += '</a><hr></td></tr><tr><td>';
              html += '<a href="http://maps.google.com/maps?q=' + address_encoded + '&f=d&source=s_q&hl=en&ie=UTF8&hq=&z=12&iwloc=A&daddr=' + address_only_encoded + '" target="_blank">Directions</a>';
              html += '&nbsp;&nbsp;&nbsp;';
              html += '<a href="#" onclick="return refreshInfoWindow();">Search nearby</a>';
              
              var html2 = '<div id="model-tab-directions-map-search"><form method="get" action="http://maps.google.com/maps" target="_blank">';
              html2 += '<b>Search nearby</b><br>'
              html2 += '<input type="hidden" name="near" value="' + address_only + '">';
              html2 += '<input type="text" name="q">';
              html2 += '&nbsp;<input type="submit" value="Search"><br>';
              html2 += '<span class="small">e.g., "pizza"</span>';
              html2 += '</form></div>';
              
              html += '</td></tr></table>';
              html += '</div>';
              
              directionsHTML1 = html;
              directionsHTML2 = html2;
              
              var markerOptions = { onCloseFn: function () {  if(!directionsRefreshFlag) map.setCenter(new GLatLng(latitude,longitude)); } };
              GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(html, markerOptions);
              });
              directionsOptions = markerOptions;
              
              map.addOverlay(marker);
              marker.openInfoWindowHtml(html, markerOptions);
              
              directionsMarker = marker;
          }
      } else {
          alert("Sorry, the Google Maps API is not compatible with this browser");
      }
  }
  
  function refreshInfoWindow() {
    directionsRefreshFlag = true;
    if(directionsHTMLText) {
        directionsMarker.openInfoWindowHtml(directionsHTML1 + directionsHTML2, directionsOptions);
        directionsHTMLText = false;
    } else {
        directionsMarker.openInfoWindowHtml(directionsHTML1, directionsOptions);
        directionsHTMLText = true;
    }
    directionsRefreshFlag = false;
    return false;
  }
  
  $(function() {
    var params = {
      imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
      imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
      imageBtnNext: '/img/lightbox/lightbox-btn-next.gif',
      imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
      imageBlank: '/img/lightbox/lightbox-blank.gif'
    };
    $('a[rel="lightbox-site-plan"]').lightBox(params);
    $('a[rel="lightbox-directions"]').lightBox(params);
    $('a[rel="lightbox-floor-plan"]').lightBox(params);
    $('.model-overview-image').sliderkit({
      auto:false,
      circular:true,
      shownavitems:15,
      panelfx:"sliding",
      panelfxspeed:500,
      panelfxeasing:"easeOutQuint",
      panelfxbefore:function(){
        $('.sliderkit-nav-clip ul li').each(function(){
          if($(this).hasClass('sliderkit-selected')) {
            $(this).find('a img').attr('src', '/img/model-overview-image-nav-green.png');
          } else {
            $(this).find('a img').attr('src', '/img/model-overview-image-nav.png');
          }
        });
      }
    });
    GM_Load();
    $(".datepicker").datepicker();
    $(".blue-border").mouseover(function(){
      $(this).addClass('blue');
    }).mouseout(function(){
      if(!$(this).hasClass('focus'))
        $(this).removeClass('blue');
    }).focus(function(){
      $(this).addClass('blue');
      $(this).addClass('focus');
    }).blur(function(){
      $(this).removeClass('blue');
      $(this).removeClass('focus');
    });
    $('#home-banner-photo').nivoSlider({effect:'fade',animSpeed:1000,pauseTime:5000,directionNav:false,controlNav:false,keyboardNav:false});
    $('.popup').popupWindow({ 
      height: 400, 
      width: 600, 
      top: Math.round(($(window).height() - 400) / 2), 
      left: Math.round(($(window).width() - 600) / 2),
      scrollbars:1
    });
    
    // li:hover fix
    $('#header-menu-top-middle ul li, #header-menu-bottom ul li').hover(function() {
      $(this).find('ul').show();
    }, function() {
      $(this).find('ul').hide();
    });
    $('#header-menu-bottom > ul > li').hover(function() {
      $(this).find('> a').css({
        color: '#ffffff',
        backgroundColor: '#1A638F',
        textShadow: '#4a8698 2px 2px 3px;'
      });
    },function() {
      $(this).find('> a').css({
        color: '#1A638F',
        backgroundColor: '#ffffff',
        textShadow: '#cccccc 2px 2px 3px'
      });
    });
    $('#header-menu-bottom > ul > li.current').hover(function () {
      $(this).find('> a span').css({
        borderBottom: 0
      });
    },function() {
      $(this).find('> a span').css({
        borderBottom: '5px solid #e38b25'
      });
    });
  });

