$(function(){
  
  // turn on or off the predictive search in the banner
  var TOP_LEVEL_SEARCH_ON = false;

  $("#searchSiteLink").click(function(){
    $(this).removeClass("off").addClass("on");
    $("#findDoctorLink").removeClass("on").addClass("off");
    $("#docs").hide();
    $("#site").show();
  });
  $("#findDoctorLink").click(function(){
    $(this).removeClass("off").addClass("on");
    $("#searchSiteLink").removeClass("on").addClass("off");
    $("#site").hide();
    $("#docs").show();
  });
  
  $("#contentShow").click(function(){
    $(this).removeClass("off").addClass("on");
    $("#moreContent").show();
	$("#contentShow").hide();
	$("#lessContent").show();
  });
  
   $("#contentHide").click(function(){
    $(this).removeClass("off").addClass("on");
    $("#moreContent").hide();
	$("#contentShow").show();
  });
  
  
  function lookupAjax(){
    var oSuggest = $("#searchSite")[0].autocompleter;
    oSuggest.findValue();
    return false;
  }

  function formatItem(row) {
    return row[0];
  }

  function findValue(li) {
    if( li == null ) return alert("No match!");

    // if coming from an AJAX call, let's use the CityId as the value
    if( !!li.extra ) var sValue = li.extra[0];
    // otherwise, let's just display the value in the text box
    else var sValue = li.selectValue;
  }

  function selectItem(li) {
    findValue(li);
  }

  // site search
  if ($("#searchConditions").length > 0)
  {
    $("#searchConditions").autocompleteArray(searchTerms,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        onItemSelect:selectItem,
        onFindValue:findValue,
        autoFill:true,
        maxItemsToShow:10
      }
    );
  }
  
  // find a doctor search
  if ($("#searchDoctors").length > 0)
  {
    $("#searchDoctors").autocompleteArray(searchDoctors,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        onItemSelect:selectItem,
        onFindValue:findValue,
        autoFill:true,
        maxItemsToShow:10
      }
    );
  }

  if ($("#searchSite").length > 0 && TOP_LEVEL_SEARCH_ON)
  {
    $("#searchSite").autocompleteArray(searchTerms,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        onItemSelect:selectItem,
        onFindValue:findValue,
        autoFill:true,
        maxItemsToShow:10
      }
    );
  }

  if ($("#findDoctor").length > 0 && TOP_LEVEL_SEARCH_ON)
  {
    $("#findDoctor").autocompleteArray(searchTerms,
      {
        delay:10,
        minChars:1,
        matchSubset:1,
        onItemSelect:selectItem,
        onFindValue:findValue,
        autoFill:true,
        maxItemsToShow:10
      }
    );
  }
});
