jQuery.fn.accessNews = function(settings) {
	var settings = jQuery.extend({
		newsSpeed: "normal",
		newsNumber: 2,
		scrollType: "horizontal",
		news_items_addCss: {position: "relative", overflow: "hidden"},
		container_addCss: {position: "relative"},
		itemSize: 100
	}, settings);
    
	var aNewsSlider = ({
		init: function(s,p){
			jQuery(".messaging",p).css("display","none");
			itemLength = jQuery(".item",p).length;
			newsContainerSize = itemLength * s.itemSize;

                        jQuery(".news_items",p).css(s.news_items_addCss);
			if(s.scrollType == 'horizontal')
			{
				jQuery(".container",p).css(s.container_addCss).css("width",newsContainerSize + "px").css("left","0px");
				jQuery(".news_items",p).css("width", s.itemSize * s.newsNumber);
			}
			else
			{
				jQuery(".container",p).css(s.container_addCss).css("height",newsContainerSize + "px").css("top","0px");
				jQuery(".news_items",p).css("height", s.itemSize * s.newsNumber);
			}

			if(s.newsNumber < itemLength)
				jQuery(".bt_next",p).addClass('on');

		        animating = false;
			jQuery(".bt_next",p).click(function()
			{
				if (animating == false)
				{
					animating = true;
					if(s.scrollType == 'horizontal')
					{
						animate = parseInt(jQuery(".container",p).css("left")) - (s.itemSize * s.newsNumber);
						if (animate + parseInt(jQuery(".container",p).css("width")) > 0)
						{
							jQuery(".bt_prev",p).addClass('on');
							jQuery(".container",p).animate({left: animate}, s.newsSpeed, function()
							{
								jQuery(this).css("left",animate);
								if (parseInt(jQuery(".container",p).css("left")) + parseInt(jQuery(".container",p).css("width")) <= s.itemSize * s.newsNumber)
								{
									jQuery(".bt_next",p).removeClass('on');
								}
								animating = false;
							});
						}
						else
						{
							animating = false;
						}
					}
					else
					{
						animate = parseInt(jQuery(".container",p).css("top")) - (s.itemSize * s.newsNumber);
						if (animate + parseInt(jQuery(".container",p).css("height")) > 0)
						{
						        $.log('move to: ' + animate);
							jQuery(".bt_prev",p).addClass('on');
							jQuery(".container",p).animate({top: animate}, s.newsSpeed, function()
							{
								jQuery(this).css("top",animate);
								if (parseInt(jQuery(".container",p).css("top")) + parseInt(jQuery(".container",p).css("height")) <= s.itemSize * s.newsNumber)
								{
									jQuery(".bt_next",p).removeClass('on');
								}
								animating = false;
							});
						}
						else
						{
							animating = false;
						}
					}
				}
				return false;
			});

			jQuery(".bt_prev",p).click(function()
			{
				if (animating == false)
				{
					animating = true;
					if(s.scrollType == 'horizontal')
	        			{
						animate = parseInt(jQuery(".container",p).css("left")) + (s.itemSize * s.newsNumber);
						if ((animate + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width")))
						{
							jQuery(".bt_next",p).addClass('on');
							jQuery(".container",p).animate({left: animate}, s.newsSpeed, function()
							{
								jQuery(this).css("left",animate);
								if (parseInt(jQuery(".container",p).css("left")) == 0)
								{
									jQuery(".bt_prev",p).removeClass('on');
								}
								animating = false;
							});
						}
						else
						{
							animating = false;
						}
					}
					else
					{
						animate = parseInt(jQuery(".container",p).css("top")) + (s.itemSize * s.newsNumber);
						if ((animate + parseInt(jQuery(".container",p).css("height"))) <= parseInt(jQuery(".container",p).css("height")))
						{
						        $.log('move to: ' + animate);
							jQuery(".bt_next",p).addClass('on');
							jQuery(".container",p).animate({top: animate}, s.newsSpeed, function()
							{
								jQuery(this).css("top",animate);
								if (parseInt(jQuery(".container",p).css("top")) == 0)
								{
									jQuery(".bt_prev",p).removeClass('on');
								}
								animating = false;
							});
						}
						else
						{
							animating = false;
						}
					}
				}
				return false;
			});
		}
	});

	return this.each(function(i) {
		if (jQuery(".item", this).length == 0)
			return;

/*alert(jQuery(".item:eq(" + i + ")",this).css("width")+ ' ' +parseInt(jQuery(".item:eq(" + i + ")",this).css("width"))); return;
		if (settings.scrollType == 'horizontal')
			aNewsSlider.itemSize = parseInt(jQuery(".item:eq(" + i + ")",this).css("width")) + parseInt(jQuery(".item:eq(" + i + ")",this).css("margin-left")) + parseInt(jQuery(".item:eq(" + i + ")",this).css("margin-right"));
		else
		        aNewsSlider.itemSize = parseInt(jQuery(".item:eq(" + i + ")",this).css("height")) + parseInt(jQuery(".item:eq(" + i + ")",this).css("margin-top")) + parseInt(jQuery(".item:eq(" + i + ")",this).css("margin-bottom"));
*/

		aNewsSlider.init(settings, this);
	});
};