jQuery.fn.slideNews = function(settings) {
    settings = jQuery.extend({
        headline: "Top Stories",
        newsWidth: 285,
        newsSpeed: "normal"
    }, settings);
    return this.each(function(i){
        jQuery(".messaging",this).css("display","none");
        jQuery("a:eq(0)",this).attr("href","#skip_to_news_" + i);
        jQuery("a:eq(4)",this).attr("name","skip_to_news_" + i);
        itemLength = jQuery(".item",this).length;
        newsContainerWidth = itemLength * settings.newsWidth;
        jQuery(".container",this).css("width",newsContainerWidth + "px");
       
        jQuery("a:eq(3)",this).click(function() {
            thisSlider = jQuery(this).parent().parent().parent();
            //jQuery(".next",thisSlider).css("display","none");
            //jQuery(".prev",thisSlider).css("display","none");
            jQuery(".container",thisSlider).css("left","0px");
            jQuery(".container",thisSlider).css("width",settings.newsWidth * 2 + "px");
            jQuery(".view_all",thisSlider).css("display","none");
        });
        jQuery(".next",this).css("display","block");
        animating = false;
        jQuery(".next",this).click(function() {
               thisParent = jQuery(this).parent().parent().parent();
               if (parseInt(jQuery(".container",thisParent).css("left")) + parseInt(jQuery(".container",thisParent).css("width")) <= settings.newsWidth * 6) {
				jQuery("#next").removeClass("on");
				jQuery("#next").addClass("off");
				return false;
               }
			   jQuery(".next").addClass("on");
			    if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("left")) - (settings.newsWidth * 1);
                if (animateLeft + parseInt(jQuery(".container",thisParent).css("width")) > 0) {
                    jQuery(".prev",thisParent).css("display","inline");
					jQuery("#prev").removeClass("off");
					jQuery("#prev").addClass("on");
                    jQuery(".container",thisParent).animate({left: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        animating = false;
                    });
                } else {
                    animating = false;
                }
                return false;
            }
        });
        jQuery(".prev",this).click(function() {
			thisParent = jQuery(this).parent().parent().parent();
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",thisParent).css("left")) + (settings.newsWidth * 1);
                if ((animateLeft + parseInt(jQuery(".container",thisParent).css("width"))) <= parseInt(jQuery(".container",thisParent).css("width"))) {
                    jQuery(".next",thisParent).css("display","block");
					jQuery("#next").removeClass("off");
					jQuery("#next").addClass("on");
                    jQuery(".container",thisParent).animate({left: animateLeft}, settings.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",thisParent).css("left")) == 0) {
                            jQuery("#prev").removeClass("on");
							jQuery("#prev").addClass("off");
                        }
                        animating = false;
                    });
                } else {
       				animating = false;
                }
                return false;
            }
        });
    });
};
