jQuery.fn.slideNews = function(settings) {
    settings = jQuery.extend({
        headline: "Top Stories",
        newsWidth: 130,
        newsSpeed: "slow"
    }, settings);
    return this.each(function(i){
/*        jQuery(".messaging",this).css("display","none"); */
        itemLength = jQuery(".item",this).length;
        newsContainerWidth = itemLength * settings.newsWidth;
        jQuery(".container",this).css("width",newsContainerWidth + "px");
/*      jQuery(".newsItems",this).prepend("<h2>" + settings.headline + " [  ‘S" + itemLength + "–‡ ] </h2>");*/

		if (itemLength < 1 ){
	        jQuery(this).css("display","none");
		}

		if (itemLength <= 3){
	        jQuery(".nsNext",this).css("background-position","right top");
	        jQuery("a:eq(1)",this).css("display","none");
		}

		if (itemLength >= 1){
			jQuery(".nsNext",this).css("display","block");
			jQuery(".nsPrev",this).css("display","block");
		}
        animating = false;
        jQuery(".nsNext",this).click(function() {
            thisParent = jQuery(this).parent();
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("left")) - (settings.newsWidth * 3);
                if (animateLeft + parseInt(jQuery(".container",thisParent).css("width")) > 0) {
                    jQuery(".nsPrev",thisParent).css("background-position","left top");
                    jQuery("a:eq(0)",thisParent).css("display","block");
                    jQuery(".container",thisParent).animate({left: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",thisParent).css("left")) + parseInt(jQuery(".container",thisParent).css("width")) <= settings.newsWidth * 4) {
                            jQuery(".nsNext",thisParent).css("background-position","right top");
                            jQuery("a:eq(1)",thisParent).css("display","none");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
                return false;
            }
        });
        jQuery(".nsPrev",this).click(function() {
            thisParent = jQuery(this).parent();
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("left")) + (settings.newsWidth * 3);
                if ((animateLeft + parseInt(jQuery(".container",thisParent).css("width"))) <= parseInt(jQuery(".container",thisParent).css("width"))) {
                    jQuery(".nsNext",thisParent).css("background-position","left top");
                    jQuery("a:eq(1)",thisParent).css("display","block");
                    jQuery(".container",thisParent).animate({left: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",thisParent).css("left")) == 0) {
                            jQuery(".nsPrev",thisParent).css("background-position","right top");
                            jQuery("a:eq(0)",thisParent).css("display","none");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
                return false;
            }
        });
    });
};
