$(function(){
//  $('#townsLists').addClass('townShrink');
  
  var lcHeight = 0;
  $('.lc').each(function(){
      if($(this).height() > lcHeight)
      {
            lcHeight = $(this).height();
      }
  });

  if(lcHeight > 300)
  {
//      alert(lcHeight);
      $('#townsLists').addClass('townShrink');
      $('#townExpander').css('display', 'block');
  }

  $('#townExpander').click(function(){
//      $('#townsLists').toggleClass('townShrink', 1000);

        if($('#townsLists').height() == 300)
        {
            $('#townsLists').animate({height: lcHeight}, 1500);
        }
        else
        {
            $('#townsLists').animate({height: 300}, 1500);
        }

      var anchorText = $(this).html();
      if(anchorText == "Show All Towns")
      {
            $(this).html("Collapse Towns");
      }
      if(anchorText == "Collapse Towns")
      {
            $(this).html("Show All Towns");
      }
  });

var isOverGoogleAd = false;
$('iframe').mouseover(function(){
    isOverGoogleAd = true;
})
.mouseout(function(){
    isOverGoogleAd = false;
});

$(window).blur(function(){
    if (isOverGoogleAd){

        $.ajax({
            type: "post",
            url: "/images/click.php",
            data: {
            }
        });
    }})
.focus()

$("input#as").autocomplete({
    source: "/js/search.php",
    minLength: 2,
    autoFocus: true,
    position: { my : "left top",  at: "left bottom", offset: "9 0"},
    search: function( event, ui ){
        $("input#as").css("background", "white url('/images/loader.gif') 250px no-repeat")
    },
    open: function( event, ui ){
        $("input#as").css("background", "white url('/images/mag.png') 250px no-repeat")
    },
    select: function(event, ui){
        placeToUrl(ui.item.value);
    }
}).focus(function(){
    if( $(this).val() == "Search by town...")
    {
        $(this).addClass('autoSearch');
        $(this).css('color','#ff3300');
        $(this).val('');
    }
})
.blur(function(){
    if( $(this).val() == "")
    {
        $(this).val('Search by town...');
        $(this).removeClass('autoSearch');
        $(this).css('color','#B0B0B1');
    }
});

function placeToUrl(pl){
var p = pl.split(', ');
var url = "/" + sthl(p[1]) + "/" + sthl(p[0]) + "/";
//alert(pl + "\n" + url);
window.location = url;
}
function sthl(s){
s=s.toLowerCase()
while(s.indexOf(" ") != -1){
s = s.replace(" ", "-")
}
return s;
}
})

var sc_project=7270463; 
var sc_invisible=1; 
var sc_security="306bd801"; 

