/**
 * This jQuery plugin provides a scrolling function for text-based JavaScript arrays.
 *
 * @author Eric Karimov(eric6930 *at* yahoo*dot* com)
 * @version 1.0
 * parameters:
 * @param {array} to scroll through
 * @param {#string} Scroll container id
 * @param {#string} 'Previous' navigation button id
 * @param {#string} 'Next' navigation button id
 * @param {speed: int} optionally scroll speed
 * @return {Object} jQuery Object
 * requires jQuery UI
 */


jQuery.fn.simpleScroll= function(arr, cont, prev, next, params) {

	this.arr = arr;
	this.cont = cont;
	this.prev = prev;
	this.next = next;

	options= {
			speed  : 1000
	};
	jQuery.extend(options, params);

	var i= 0;

	function countUp(){
			i++;
			if(i>=arr.length) i=0;
	}

	function countDown(){
			i--;
			if(i<= -1) i=arr.length-1;
	}

	function move(dirHide, dirShow, func){
		   $(cont).hide("slide", {direction: dirHide}, options.speed, function (){
					func();
					$(this).text(arr[i]);
					$(this).show("slide", {direction: dirShow}, options.speed);
			});
	}

	return this.each(function(){
			$(cont).text(arr[0]);

			$(prev).click(function() {
				move( "left", "right", countDown);
			});
			$(next).click(function() {
					move( "right", "left", countUp);
			});
 	});

}

