/**
* author Ondrej Scecina
*/

(function($){
  $.fn.headline = function(options) {
    
    var defaults = {
      fadeSpeed: 2000,
      initDelay: 0,
      step: 0
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function() {
      var obj = jQuery(this);
      
      obj.children("li").hide();
      
      setTimeout(function() { showNextItem(obj, options.step) }, options.initDelay);
    });
    
    function showNextItem(obj, index)
    {
      var curLi      = obj.children("li").eq(index);
      var totalItems = obj.children("li").length;
      
      curLi.fadeIn("fast", function()
                          {
                            setTimeout(function()
                                        {
                                          curLi.fadeOut("slow", function()
                                                                {
                                                                  index = (index < totalItems - 1) ? index + 1 : 0;
                                                                  showNextItem(obj, index);
                                                                });
                                        }, options.fadeSpeed);
                          });
    }
  };
})(jQuery);

