$(window).load(function(){
  //トップページおすすめ物件高さ調整
  var h = $('#sidemenu').height() - $('#contents').height();
  if ($('#recommend-sale_cont').length > 0 && h > 0) {
    $('#recommend-sale_cont').height($('#recommend-sale_cont').height() + h);
  }
  if ($('#recommend-rent_cont').length > 0 && h > 0) {
    $('#recommend-rent_cont').height($('#recommend-rent_cont').height() + h);
  }
});

$(document).ready(function(){
  initRollOverImages();
  compatIE();
  // colorbox条件
  if (typeof $.colorbox !== "undefined") {
    $('a.colorbox').colorbox({
      opacity: 0.6,
      slideshow: true,
      slideshowSpeed: 3500,
      slideshowAuto: false,
      current: '<div class="currentNum">{current}</div>/<div class="totalNum">{total}</div>',
      href: function(){
        var href = $(this).attr('href'), $img;
        if (href == '#') {
          $img = $(this).children('img');
          if ($img.length > 0) {
            href = $img.attr('src');
          }
        }
        return href;
      }
    });
  }
});

function compatIE() {
  //IE6以下でhover時の背景画像ちらつきを解消
  if ($.browser.msie && $.browser.version < 7) {
    document.execCommand('BackgroundImageCache', false, true);
  }
}

function initRollOverImages(context) {
  context = context || document;
  var image_cache = {};
  var freeze = false;
  $('img.hover, input.hover:image', context).not('[src*="_o."]').each(function(){
    var img_src = this.src;
    var img_src_o = img_src.replace(/^([^?#]+)(\.[a-z]+(?:[?#].+)?)$/i, '$1_o$2');
    if (typeof image_cache[img_src] === 'undefined') {
      image_cache[img_src] = new Image();
      image_cache[img_src].src = img_src_o;
    }
    //firefox4以上でSSLページ遷移時にセキュリティ警告が出ないように対策
//TODO srcの切り替えではない方法に変更
    $(this).hover(
      function(){if(!freeze)this.src = img_src_o;},
      function(){if(!freeze)this.src = img_src;}
    ).click(function(){
      var href = $(this).parent().attr('href');
      if (href && href.match(/^https/i)) {
        freeze = true;
        setTimeout(function(){freeze = false;}, 3000);
      }
    });
  });
}

/*
This script is written by Eric (Webcrawl@usa.net)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

function printit(){
  if (window.print) {
    window.print();
  }
  else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
  }
}

