(function($){

  $.fn.newscroll = function(settings) {
    
    var config = {
      delay: 5000
    };
    
    var items = new Array();
    var curr_idx = 0;
    var length = 0;
    
    if (settings) $.extend(config, settings);
        
    this.each(
      function(){
        if( $(this).css('position')=='static')$(this).css('position','relative');

        $(this).children().each(
          function(idx){
            items.push(this);
            if(idx == 0){
              $(this).css({position:'absolute',top:0,left:0,'white-space':'nowrap'});
            }else{
              $(this).css({position:'absolute',top:40,left:0,'white-space':'nowrap'});
            }
            length++;
          }
        )   
        
        if(length >1){
          setTimeout(function(){play()}, config.delay);
        }      
              
      }
    )
    
    function init(){
      
    }
    function play(){
     //  alert("PLAY");
      show_item(curr_idx + 1);
      setTimeout(function(){play()}, config.delay);
      
        
    }
    
    function show_item(idx){

      $(items[curr_idx]).animate({top:-10,opacity:0},'slow');
      if(idx > length -1) idx = 0; 
      $(items[idx]).css({top:20,opacity:0}).animate({top:0,opacity:1},'slow' );
      curr_idx = idx;
    }
    

    
  }
})(jQuery);        