function levelLayers()
{
  if ($("#layers").length) {

    $("#layers").css("height", "auto");
    $("#last-block").css("height", "auto");
    
    var delta = $("#content").height() - $("#right").height() + 7;

    if (delta < 0) {
      $("#layers").height($("#layers").height() - delta);
      $("#layers").removeClass("zoom");
    } else {
      $("#last-block").height($("#last-block").height() + delta);
      $("#layers").addClass("zoom");
    }
  }
}

function levelLayers_ov()
{
  if ($("#about-house").length) {

    $("#last-block").css("height", "auto");
    
    var delta = $("#content").height() - $(".pages").height() - $("#right").height() - 6;

    if (delta > 0) {
      $("#last-block").height($("#last-block").height() + delta);
      $("#layers").addClass("zoom");
    }
  }
}

$(document).ready(function(){

  // common
  
  $("input.autohiding").each( function() {
    $(this).val($(this).attr("alt"));
  }).focus( function() {
    if ( $(this).val() == $(this).attr("alt") ) 
            $(this).val("");
  }).blur( function() {
      if ( $(this).val() == "" ) 
          $(this).val( $(this).attr("alt") ); 
  });

  // homepage.html
  
/*  
  if ($(".logos").children().length > 1) {
    $(".logos-left").addClass("logos-left-button");
    $(".logos-right").addClass("logos-right-button");
  }

*/
  if ($(".logos").length)
    $(".logos").jCarouselLite({
      auto: 1000,
      speed: 1500,
      visible: 6,
      easing: "jswing"
    });

  $(".logos").mouseover(function(){
    mayRun = false;
  }).mouseout(function(){
    mayRun = true;
  });
  
  $(".logos a").each(function(){
    $(this).css("margin-top", (75 - $(this).find("img").height()) / 2);
  });
  
  $(".logos a img").mouseover(function(){switchImage($(this));}).mouseout(function() {switchImage($(this));});
  
  function switchImage(e) {
    if (e) {
      if ($(e).attr('rel')) {
        var rel = $(e).attr('rel');
        var src = $(e).attr('src');
        $(e).attr('src',rel);
        $(e).attr('rel',src);
      }
    }
  }
      
  if ($("#green-list").length) {
    var max = Math.max($(".twins-inner").height(), $("#green-list").height());
    $(".twins-inner").add("#green-list").height(max);
  }

  if ($(".houses-inner").children().length > 1) {
    $(".houses-left").addClass("houses-left-button");
    $(".houses-right").addClass("houses-right-button");
  }
  
  if ($(".houses-inner").length)
    $(".houses-inner").cycle({
      speed:  1000,
      prev: ".houses-left-button",
      next: ".houses-right-button",
      timeout: 0
    });

  // textpage.html

  if ( $("#long-grey-block").length ) {

    if ( $(".white-block").length )
      if( $(".content").height() < $(".right").height() )
        $(".content").height( $(".right").height() - 8 );
      else
        $("#long-grey-block").height( $(".content").height() - $(".white-block").height() - 12 );
    else {
      var max = Math.max($(".content").height(), $("#long-grey-block").height());
      $(".content").add("#long-grey-block").height(max);
    }

  };

  // detailpage.html
  
  $(".tabs div").click(function(){
    
    $(".layers").children("div").eq($(".tabs div").index($(this))).removeClass("google-map");
  
    $(".tabs div.selected").removeClass("selected");
    $(this).addClass("selected");
    $(".layers div.display").removeClass("display");
    $(".layers").children("div").eq($(".tabs div").index($(this))).addClass("display");
    levelLayers();
  });

  $(".tabs div.selected").click();
  
  $("#horiz-arrow .horiz-arrow").css("top", ($("#horiz-arrow").height() - $("#horiz-arrow .horiz-arrow").height()) / 2 );
  
  // overzicht.html

  levelLayers_ov();
  
  $( ".houses-less a" ).click( function(){
    $( ".picture img" ).attr( "src", $(this).find("img").attr("src").replace("_sm.jpg", ".jpg") );
    return false;
  });
  
});
