jQuery.fn.slideNews = function(settings) {
	settings = jQuery.extend({
		headline: "Top Stories",
		newsWidth: 285,
		newsHeight: 140,
		newsSpeed: "normal",
		nbItem: 2,
		scrollType: "horizontal"
	}, settings);
	return this.each(function(i){
		jQuery(".messaging",this).css("display","none");
		
		jQuery(".news_items",this).css("overflow","hidden");
		jQuery(".news_items",this).css("position","relative");
		jQuery(".container",this).css("left","0px");
		jQuery(".container",this).css("top","0px");
		jQuery(".container",this).css("position","relative");
		
		itemLength = jQuery(".item",this).length;
		if (settings.scrollType=='horizontal')
		{
			newsContainerSize = itemLength * settings.newsWidth;
			jQuery(".container",this).css("width",newsContainerSize + "px");
			jQuery(".news_items",this).css("width",settings.newsWidth * settings.nbItem + "px");
		}
		else
		{
			newsContainerSize = itemLength * settings.newsHeight;
			jQuery(".container",this).css("height",newsContainerSize + "px");
			jQuery(".news_items",this).css("height",settings.newsHeight * settings.nbItem + "px");
		}

		animating = false;
		jQuery(".next",this).click(function() {
			thisParent = jQuery(this).parent().parent();
			if (animating == false) {
				animating = true;
				if (settings.scrollType=='horizontal') {
					animate = parseInt(jQuery(".container",thisParent).css("left")) - (settings.newsWidth * settings.nbItem);
					if (animate + parseInt(jQuery(".container",thisParent).css("width")) > 0) {
						jQuery(".container",thisParent).animate({left: animate}, settings.newsSpeed, function() {
							jQuery(this).css("left",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				} else {
					animate = parseInt(jQuery(".container",thisParent).css("top")) - (settings.newsHeight * settings.nbItem);
					if (animate + parseInt(jQuery(".container",thisParent).css("height")) > 0) {
						jQuery(".container",thisParent).animate({top: animate}, settings.newsSpeed, function() {
							jQuery(this).css("top",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				}

			}

			return false;
		});
		jQuery(".prev",this).click(function() {
			thisParent = jQuery(this).parent().parent();
			if (animating == false) {
				animating = true;
				if (settings.scrollType=='horizontal') {
					animate = parseInt(jQuery(".container",thisParent).css("left")) + (settings.newsWidth * settings.nbItem);
					if ((animate + parseInt(jQuery(".container",thisParent).css("width"))) <= parseInt(jQuery(".container",thisParent).css("width"))) {
						jQuery(".container",thisParent).animate({left: animate}, settings.newsSpeed, function() {
							jQuery(this).css("left",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				} else {
					animate = parseInt(jQuery(".container",thisParent).css("top")) + (settings.newsHeight * settings.nbItem);
					if ((animate + parseInt(jQuery(".container",thisParent).css("height"))) <= parseInt(jQuery(".container",thisParent).css("height"))) {
						jQuery(".container",thisParent).animate({top: animate}, settings.newsSpeed, function() {
							jQuery(this).css("top",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				}
			}

			return false;
		});
	});
};
