var BoxesRotation = function() {
	var boxes = new Array();
	var current;
	var next;
	var pointer;
	var rotationVID;
	var variable;
	var delay;
	return {
		init : function(boxClass, milliseconds) {
			variable = this;
			pointer = 0;
			delay = milliseconds;
			jQuery("." + boxClass).each(function(index,el) {
				addBox(el);
				jQuery(el).mouseover(function() {variable.stopRotate()});
				jQuery(el).mouseout(function() {variable.startRotate()});
			});
			variable.startRotate();
		},
		rotateVocabolario : function() {
			jQuery(getCurrent()).fadeOut(500);
			jQuery(getNext()).delay(700).fadeIn(500);
			addPointer();
			variable.startRotate();
		},
		stopRotate : function() {
			rotationVID = clearTimeout(rotationVID);
		},
		startRotate : function() {
			if (boxes.length > 1) {
				rotationVID = setTimeout(variable.rotateVocabolario, delay);
			}
		},
		setDelay : function(milliseconds){
			delay = milliseconds;
		}
	}

	function addBox(box) {
		boxes[boxes.length] = box;
	}
	;

	function getCurrent() {
		return boxes[pointer];
	}
	;

	function getNext() {
		return boxes[(pointer + 1 == boxes.length ? 0 : pointer + 1)];
	}
	;

	function addPointer() {
		if (pointer + 1 == boxes.length)
			pointer = 0;
		else
			pointer = pointer + 1;
	}
	;
};
