(function() {
  var newMethods = {
    check       : function(tf) { return this.each(function(){ this.checked=tf; }) },
    togglecheck : function()   { return this.each(function(){ this.checked= ! this.checked; }) },
    disabled    : function(tf) { return this.each(function(){ this.disabled=tf; }) },
    mostra      : function(tf) { return this.each(function(){ if(tf) {$(this).show();} else {$(this).hide();} }); },
    stile       : function(tf, classe) { return this.each(function(){ if(tf) {$(this).addClass(classe);} else {$(this).removeClass(classe);} }); },
    hoverClass  : function(classe) { return this.each( function(){ $(this).bind("mouseenter", function(){$(this).addClass(classe);})
                                                                          .bind("mouseleave", function(){$(this).removeClass(classe);}); }); },
    tooltip     : function(h, w, a){ 
      // h : html     w : larghezza        a : true / false oggetto
      var of=15, marg=10, w=w || "300px";
      if ($("#tooltip").length==0){
        $("<div id='tooltip' style='width: 300px; border: 1px solid #cc9900; padding: 0; display: none; "+
        "background-color: #ffffcc; text-align: left; z-index: 10000; position: absolute; font-size: .9em;'></div>").appendTo("body");
      }
      return this.each(function(){
        if (a=="img") { var h2=h || "<img src='"+this.value+"' alt='' border='0'>"; var o=$(this); } 
        else if (a=="prev") { var h2=h || $(this).html(); var o=$(this).prev(); } 
        else { var h2=h || $(this).html(); var o=$(this); }
        o.bind("mouseover", function(e){ 
          $("#tooltip").html(h2).show()
          .css("top", (($(window).height()+$(window).scrollTop()-e.pageY-$("#tooltip").height()<marg)? 
            $(window).height()+$(window).scrollTop()-$("#tooltip").height()-marg-of:e.pageY+of)+"px")
          .css("left", (($(window).width()/2+$(window).scrollLeft()<e.pageX)?e.pageX-of-$("#tooltip").width():e.pageX+of)+"px")
          .css({bottom: "auto", right: "auto", width: w});
        })
        .bind("mousemove", function(e){ 
          $("#tooltip").css("top", (($(window).height()+$(window).scrollTop()-e.pageY-$("#tooltip").height()<marg)? 
            $(window).height()+$(window).scrollTop()-$("#tooltip").height()-marg-of:e.pageY+of)+"px")
          .css("left", (($(window).width()/2+$(window).scrollLeft()<e.pageX)?e.pageX-of-$("#tooltip").width():e.pageX+of)+"px")
          .css({bottom: "auto", right: "auto"});
         })
        .bind("mouseout", function(e){ $("#tooltip").html("").hide(); });
      })
    }
  };
  jQuery.each(newMethods, function(i) { jQuery.fn[i] = this; });
})(); 
