(function ($) {
   $.fn.extend({
      //Passaggio della variabile options alla funzione
      slideShowTxt: function (options) {
         $("p:first", this).addClass("active");

         //Setta i valori di default
         var defaults = {
            speed: 1500,
            interval: 2500,
            delay: 0
         };
         //Fonde i valori di default con le opzioni passate
         var options = $.extend(defaults, options);

         var $testi = $('p', $(this));

         $testi.wrapAll(document.createElement("DIV"));
         return this.each(function () {
            var o = options;
            var obj = $(this);
            var testi = $('#testi');
            if (o.delay > 0) {
               setTimeout(function () {
                  setInterval(function () {
                     slideSwitchTxt(obj, o.speed);
                  }, eval(o.interval + o.speed));
               }, o.delay);
            }
            else {
               setInterval(function () {
                  slideSwitchTxt(obj, o.speed);
               }, eval(o.interval + o.speed));
            }
         });
      }
   });

   function slideSwitchTxt(obj, speed) {
      var $activeTxt = $('div > p.active', obj);
      if ($activeTxt.length == 0) {
         $activeTxt = $('div > p:last', obj);
      }
      var $nextTxt = $activeTxt.next().length ? $activeTxt.next() : $('div > p:first', obj);

      $activeTxt.animate({ opacity: 0.0 }, speed / 2);
      $nextTxt.css({
         opacity: 0.0
      }).addClass('active').animate({
         opacity: 1.0
      }, speed / 2, function () {
         $activeTxt.removeClass('active');
      });
   }
})(jQuery);
