jQuery.fn.slideNews = function(settings) {
    settings = jQuery.extend({
        headline: "Fiji Rugby Slider",
        newsHeight: 42,
        newsSpeed: "normal"
    }, settings);
    return this.each(function(i){
        itemLength = jQuery(".item",this).length;
        newsContainerWidth = itemLength * settings.newsHeight;
        jQuery(".container",this).css("height",newsContainerWidth + "px");
        jQuery(".next",this).css("display","block");
        animating = false;
        jQuery(".next",this).click(function() {
            thisParent = jQuery(this).parent();
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("top")) - (settings.newsHeight);
                if (animateLeft + parseInt(jQuery(".container",thisParent).css("height")) > settings.newsHeight * 3) {
                    jQuery(".prev",thisParent).css("display","block");
                    jQuery(".container",thisParent).animate({top: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("top",animateLeft);
                        if (parseInt(jQuery(".container",thisParent).css("top")) + parseInt(jQuery(".container",thisParent).css("height")) <= settings.newsHeight * 3) {
                            jQuery(".next",thisParent).css("display","block");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
                return false;
            }
        });
        jQuery(".prev",this).click(function() {
            thisParent = jQuery(this).parent();
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("top")) + (settings.newsHeight);
                if ((animateLeft + parseInt(jQuery(".container",thisParent).css("height"))) <= parseInt(jQuery(".container",thisParent).css("height"))) {
                    jQuery(".next",thisParent).css("display","block");
                    jQuery(".container",thisParent).animate({top: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("top",animateLeft);
                        if (parseInt(jQuery(".container",thisParent).css("top")) == 0) {
                            jQuery(".prev",thisParent).css("display","block");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
                return false;
            }
        });
    });
};
