// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Ajaxの実行確認用
Ajax.Responders.register({
  onCreate: function() {
    if ($("spinner")) {
      $("spinner").innerHTML = "処理中(" + Ajax.activeRequestCount + ")";
      $("spinner").show();
    }
  },
  onComplete: function() {
    if ($("spinner")) {
      if (Ajax.activeRequestCount == 0) {
        $("spinner").hide();
      }
    }
  }
});

// ブックマーク登録ダイアログを開く
//
// 使用例
// <%= link_to("お気に入りに登録する", "#", :class => "bookmark") %>
//
if (typeof(jQuery) != "undefined") { // FIXME: もっとスマートな判別方法ないのか？
  jQuery(document).ready(function(){
    jQuery("a.bookmark").click(function() {
      return addBookmark(document.title, location.href);
    });
    function addBookmark(title, url) {
      if (window.sidebar) {
        // Firefox
        // file:// で始まっていると登録されない
        // https?:// で始まっていると登録された
        window.sidebar.addPanel(title, url, "");
      } else if (document.all) {
        window.external.AddFavorite(url, title);
      } else if (window.opera && window.print) {
        return true;
      }
    }
  });
}
