
(function($){

	$.fn.contentSlider = function(settings) 
	{
	    settings = $.extend(
		{
	        newsSpeed: 750
	    }, settings);
	    return this.each(function(i) 
		{
	        SliderExec.itemWidth = parseInt($(".item:eq(" + i + ")",".content-slider").css("width")) + parseInt($(".item:eq(" + i + ")",".content-slider").css("margin-right"));
	        SliderExec.init(settings, this);
	    });
	};

	var SliderExec = 
	{
	    itemWidth: 0,
	    init: function(s, p) 
		{
	        itemLength = $(".item", p).length;
	        newsContainerWidth = itemLength * SliderExec.itemWidth;
	        $(".container", p).css("width", newsContainerWidth + "px");
			$(".prev", p).addClass("prev-off");	
	        animating = false;

			if( $( "." + p.className + " .container .item" ).size() < 2 )
				$(".next", p).addClass("next-off");

	        $(".next", p).click(function() 
			{
	            if (animating == false) 
				{
	                animating = true;
	                animateLeft = parseInt($(".container",p).css("left")) - SliderExec.itemWidth;
	                if (animateLeft + parseInt($(".container",p).css("width")) > 0) 
					{
						$(".prev",p).removeClass("prev-off");
	                    $(".container",p).animate({left: animateLeft}, s.newsSpeed, function() 
						{
	                        $(this).css("left",animateLeft);
	                        if (parseInt($(".container",p).css("left")) + parseInt($(".container",p).css("width")) <= SliderExec.itemWidth) 
							{
	                            $(".next",p).addClass("next-off");
	                        }
	                        animating = false;
	                    });
	                } 
					else 
					{
	                    animating = false;
	                }
	            }
	            return false;
	        });

	        $(".prev", p).click(function() 
			{
	            if (animating == false) 
				{
	                animating = true;
	                animateLeft = parseInt($(".container",p).css("left")) + SliderExec.itemWidth;
	                if ((animateLeft + parseInt($(".container",p).css("width"))) <= parseInt($(".container",p).css("width"))) 
					{
						$(".next",p).removeClass("next-off");
	                    $(".container",p).animate({left: animateLeft}, s.newsSpeed, function() 
						{
	                        $(this).css("left",animateLeft);
	                        if (parseInt($(".container",p).css("left")) == 0) 
							{
	                            $(".prev",p).addClass("prev-off");
	                        }
	                        animating = false;
	                    });
	                }
					else 
					{
	                    animating = false;
	                }
	            }
	            return false;
	        });
	    }
	};

})(jQuery);

