$(function() {
  $('#fisheye a').each(function() {
    $(this).prepend('<span class="shadowme">' + this.title + '</span>').removeAttr('title');
  });
  $('#fisheye').removeClass('fisheyeBroken').addClass('fisheyeWorking').Fisheye({
    maxWidth: 60,
    items: 'a',
    itemsText: 'span',
    container: '.fisheyeContainer',
    itemWidth: 40,
    proximity: 80,
    alignment : 'left',
    valign: 'bottom',
    halign : 'center'
  });

  $('div.tabme').each(function() {
    var first_tab = true;
    var $tabme = $(this);
    var $tabbar = $('<ul class="tabbar"></ul>');
    $('div.tab', this).each(function() {
      var $tab = $(this);
      if (first_tab) {
        $tab.addClass('selected');
      } else {
        $tab.addClass('screenhide');
      }
      $('<li' + (first_tab?' class="selected"':'')  + '>' + $('h2', $tab).addClass('screenhide').html() + '</li>').appendTo($tabbar).click(function() {
        if ($('a', this).length) {
          window.location = $('a', this).attr('href');
        } else {
	  $('div.tab.selected', $tabme).removeClass('selected').addClass('screenhide');
	  $('li.selected', $tabbar).removeClass('selected');
	  $tab.addClass('selected').removeClass('screenhide');
	  $(this).addClass('selected');
        }
        return false;
      });
      first_tab = false;
    });
    $tabme.prepend('<br style="clear: both;" class="printhide" />').prepend($tabbar);
  }).addClass('tabbed');
  
  $('span.shadowme').each(function() {
    var $this = $(this);
    $this.html('<span class="shadow">' + $this.html() + '</span><span> ' + $this.html() + '</span>');
  });
  $('#PropertySearch select').change(function() {
    if (this.value) {
      var action = $(this).parents('form').attr('action');
      window.location = action + this.value + '/';
    }
  });
  $("#PropertySearch :submit").hide();
  $("#PropertySearch").removeClass('havegobuttons');

  $('#filter-form').submit(function(ev) {
    var url = document.location.href.split('#');
    url = url[0].split('?');
    url = url[0];
    var first = true;
    $('#filter-form select').each(function() {
      var val = this.value;
      var thedefault = $(this).children().val();
      if (val != thedefault) {
	if (first) {
	  url += '?';
	  first = false;
	} else {
	  url += '&';
	}
        url += this.name + '=' + val
      }
    });
    url += '#developments'
    document.location.href = url;
    return false;
  });

  $dev = $('#developments');
  if ($dev.length && !/#developments$/.test(document.location.href)) {
    var target = $dev.offset().top;
    $('html').animate({scrollTop: target}, 3000);
  }
});
