
//= depends: zapi/zapi

ZAPI.namespace(window, 'APP.Utils').History = Class.create({
	initialize: function(options) {
		this._options = $H({
			name: 'zoo',
			field: 'zoo-history-field',
			frame: 'zoo-history-iframe',
			getState: function() { return ""; },
			setState: function(state) {},
			initialRequest: function() {}
		}).merge(options);

		this._name = this._options.get('name');
		this._getState = this._options.get('getState');
		this._setState = this._options.get('setState');
		this._initialRequest = this._options.get('initialRequest');

		YAHOO.util.History.register(
			this._name,
			YAHOO.util.History.getBookmarkedState(this._name) || '',
			this._setState
		);
		YAHOO.util.History.onReady(this._initialRequest);
		YAHOO.util.History.initialize(this._options.get('field'), this._options.get('frame'));
	},
	navigate: function() {
		var newState = this._getState();
		var currentState = YAHOO.util.History.getCurrentState(this._name);

		if (newState != currentState) {
			YAHOO.util.History.navigate(this._name, newState);
		}
	},
	current: function() {
		return YAHOO.util.History.getCurrentState(this._name);
	}
});
