/**
 * jQuery TextSwitcher v 1.0
 * Author: Michal Major
 * 
 * Switches multiple paragraphs by showing only one for specified amount of time.
 * 
 * Fell free to use it!
 */

(function ($) {
  $.fn.textsw = function (options) {
	var obj = $(this);       
    var opts = $.extend({}, $.fn.textsw.defaults, options);
         
    /* firebug console output */
    function debug(msg) {
      if (window.console && window.console.log && opts.debug) {
        window.console.log(msg);
      }
	}
		
	return this.each(function(){
	  var nodesNo = obj.children("p").length;
	  var index = 0;
	  
	  function init() {
	    if (index >= nodesNo) index = 0;
	    index++;	
	    if (nodesNo > 1) load(index);
	  }
	  
	  function load(index) {
	    obj.children("p").fadeOut(500);
		obj.children("p:nth-child("+index+")").fadeIn(1000);
	    setTimeout(function(){init();},opts.time);
	  }
	  
	  obj.children("p").hide();
	  init();
	});
	
  }
  
  $.fn.textsw.defaults = {
	  time:		10000  //default time 10s
	};

})(jQuery);
