/* news ticker */
jQuery.fn.jNewsTicker = function( options ) {

    setup = {
        articles        : "",
        articleCount    : 0,
        articleHeight   : "",
        delay           : 8000,
        topPos          : 0,
        count           : 1,
        pause           : false,
        scroller        : ""
    }
    
    jQuery.extend(setup, options);
    
    nextArticle = function() {
        
        if ( !(setup.pause) )
        {
            if ( setup.count >= setup.articleCount )
            {
               setup.count = 0;
               setup.topPos = setup.articleHeight;
            }
            setup.topPos = setup.topPos - setup.articleHeight;
            jQuery(setup.scroller).animate({ top: setup.topPos },500);
            setup.count++;
        }
    }
    
    pause = function() {
        if( setup.pause ) 
        {
            setup.pause = false;
        } 
        else
        {
            setup.pause = true;
        }
    }
    
    return this.each(function() {
        jQuery(this).css("overflow","hidden");
        setup.articleCount = (jQuery(this).children().filter( setup.articles )).length;
        setup.articleHeight = parseInt(jQuery(this).children().filter( setup.articles ).outerHeight());
        jQuery(this).children().filter( setup.articles ).wrapAll("<div class='jNewsTicker'></div>");
        setup.scroller = jQuery(this).find(".jNewsTicker:first");
        if (setup.scroller && (setup.articleCount > 1))
		{
		    jQuery(setup.scroller).mouseover(function(){ pause() });
		    jQuery(setup.scroller).mouseout(function(){ pause() });
			setInterval("nextArticle()", setup.delay );
		}
    });
    
};