/*
 * jquery.buratto.js
 *
 *    require jQuery 1.4.2 or above
 *
 */

jQuery(function($){
  // replace popup.js
  $("#popupTabidayori,#popupColumn,#popupBlog").hover(
    function(){ $("#child_" + $(this).attr("id")).show(); },
    function(){ $("#child_" + $(this).attr("id")).hide(); } 
  );
  
  $("#child_popupTabidayori, #child_popupColumn, #child_popupBlog").hover(
    function() { $(this).show(); },
    function() { $(this).hide(); }
  );
 
  // replace dropdown.js
  $(".dropdown").mouseover(
    function(){ $(this).children("dd:hidden").fadeIn("fast"); }
  );

  $(".dropdown").mouseleave(
    function(){ $(this).children("dd:visible").fadeOut("fast"); }
  );

  // replace show_hide.js
  $(".show_hide").toggle(
    function(){ $("#all").show(); },
    function(){ $("#all").hide(); }
  );
  
  /*
   *  postwitter
   *  
   *  easy way to post tweet on the web page.
   *
   *    require jQuery 1.4.2
   */
  
  var postwitter = {
    base      : "http://twitter.com/home?status=",
    url       : location.href,
    site      : location.host,
    suffix    : false,
    bindId    : "#pt",
    title     : "",

    init      : function(){
      var status;
      
      switch (this.site) {
        case "opi-rina.chunichi.co.jp":     // opi-rina.chunichi.co.jp
          if (document.getElementsByTagName("h1").length !== 0) {
            this.title = document.getElementsByTagName("h1")[0].innerHTML;
          } else {
            this.title = document.getElementsByTagName("h2")[0].innerHTML;
          }
          this.suffix = "";
          break;
        case "tabi.chunichi.co.jp":     // tabi.chunichi.co.jp
          if ($(".topicPath > li:last").text() !== "") {
            this.title = $(".topicPath > li:last").text();
          } else {
            this.title = document.title;
          }
          
          this.suffix = "";
          break;
        default:
          this.title = document.title;
          break;
      }

      if ($("#pt").attr("href") !== "#") {
        this.url = $("#pt").attr("href");
      }

      status = this.title + " " + this.url;
      if (this.suffix !== false) status += " " + this.suffix;
      status = encodeURIComponent(status);
      
      $(this.bindId).attr("href", this.base + status).attr("target", "_blank").click;
    }
  }
  
  postwitter.init();

});

