(function($) {

	$.fn.pontoscroll = function(settings) {

		var defaults = {
			pos:'h',
			visivel: 2,
			alturaFoto: 100,
			larguraFoto: 84
		}

		var settings = $.extend(defaults, settings);

		return this.each(function() {

			var me = this;

			var $element = $(this);

			var atual = 0;
			var total = $element.find('.noticia').length;

			$.scrollTo.defaults.axis = 'xy';
			$(this).scrollTo(0);

			this.init = function() {
				atual = settings.visivel;
			}

			this.bindTop = function() {
				$element.parents('.pontoscroll').find('.arrow_top').bind('click',function() { me.moveTop() });
			};

			this.bindBot = function() {
				$element.parents('.pontoscroll').find('.arrow_bot').bind('click',function() { me.moveBot() });
			};

			this.bindLeft = function() {
				$element.parents('.pontoscroll').find('.arrow_left').bind('click',function() { me.moveLeft() });
			};

			this.bindRight = function() {
				$element.parents('.pontoscroll').find('.arrow_right').bind('click',function() { me.moveRight() });
			};

			switch(settings.pos) {
				case 'v':
					me.bindTop();
					me.bindBot();

					me.moveTop = function() {
						if (atual > settings.visivel) {
							atual--;
							$element.scrollTo({top:'-='+settings.alturaFoto, left:0}, 600);
						} else {
							$element.scrollTo(settings.alturaFoto*(total-settings.visivel), 1000);
							atual = total;
						}
					};

					me.moveBot = function() {
						if ((total > settings.visivel) && (atual < total)) {
							atual++;
							$element.scrollTo({top:'+='+settings.alturaFoto, left:0}, 600);
						} else {
							atual = settings.visivel;
							$element.scrollTo(0, 1000);
						}
					};
				break;

				case 'h':
					me.bindLeft();
					me.bindRight();

					me.moveLeft = function() {
						if (atual > settings.visivel) {
							atual--;
							$element.scrollTo({left:'-='+settings.larguraFoto, top:0}, 600);
						} else {
							$element.scrollTo(settings.larguraFoto*(total-settings.visivel), 1000);
							atual = total;
						}
					};

					me.moveRight = function() {
						if ((total > settings.visivel) && (atual < total)) {
							atual++;
							$element.scrollTo({left:'+='+settings.larguraFoto, top:0}, 600);
						} else {
							atual = settings.visivel;
							$element.scrollTo(0, 1000);
						}
					};
				break;
			}
			this.init();
		});
	}
})(jQuery);
