/*
 * Provides the functionality for backwards/forwards buttons 
 * Written by Dan "Ducky" Little 3/17/2007
 */


var NAVIGATOR_HISTORY_INSTANCE = 0;
function NavigatorHistory(EventManager) {
	var ViewHistory = new Array();
	var currentIndex = -1;
	var MySelf = this;
	var NavigatorId = 'NavigatorHistory-'+NAVIGATOR_HISTORY_INSTANCE;
	NAVIGATOR_HISTORY_INSTANCE++;
	
	this.onNavigate = function(viewCirc) {
		if(!viewCirc.navigatorLog) {
			currentIndex++;
			ViewHistory[currentIndex] = viewCirc;
			ViewHistory[currentIndex].navigatorLog = true;
		}
	}

	this.previous = function () {
		currentIndex--;
		if(ViewHistory[currentIndex]) {
			EventManager.triggerEvent('navigate', ViewHistory[currentIndex]);
		} else {
			currentIndex++;
		}
	}

	this.next = function () {
		currentIndex++;
		if(currentIndex >= ViewHistory.length) {
			currentIndex--;
		} else {
			EventManager.triggerEvent('navigate', ViewHistory[currentIndex]);
		}
	}

	this.initializeEvents = function () {
		EventManager.addEventListener('navigate', NavigatorId, MySelf.onNavigate);
	}
}
