/* 
 * jQuery.tipText.js
 * © 2011 kumagaiyusuke
*/

(function ($) {
  
  $.tipText = function (tipText) {
    
    
    var $tipText = $("<div>", {
      "class" : "tipText"
    });
    
    var events = $.tipText.events;
    
    var isSupportCSS3 = typeof document.documentElement.style.borderRadius != "undefined";
    
    
    // !初期化
    
    if (isSupportCSS3) {
      $tipText.css({
        border: "1px solid rgba(200, 200, 200, .8)",
        background: "rgba(255, 255, 255, .8)"
      });
    }
    else {
      $tipText.css({
        border: "1px solid #ccc",
        background: "#fff"
      });
    }
    
    $tipText.text(tipText);
    
    $tipText.css({
      opacity: 0
    });
    
    
    // !パブリック
    
    $tipText.show = function (duration) {
      
      $tipText.stop();
      
      $tipText.animate({
        opacity: 1
      }, {
        duration: duration,
        complete: function () {
          if (!$.support.opacity) {
            this.style.removeAttribute("filter");
          }
        }
      });
    };
    
    $tipText.hide = function (duration) {
      
      $tipText.stop();
      $tipText.animate({
        opacity: 0
      }, {
        duration: duration,
        complete: function () {
          $tipText.trigger(events.HIDE_COMPLETE);
        }
      });
    };
    
    
    return $tipText;
  };
  
  
  // !スタティック
  
  $.tipText.events = {
    HIDE_COMPLETE: "hideComplete"
  };

})(jQuery);

