/*****************************************************************************/
/*                                2010 Shio2e                                */
/*                     JAVASCRIPT BUSCADOR :: HISTORIAL                     */
/*****************************************************************************/

buscador.historial = {
	// VARIABLES CONFIGURACION
	reinician 			: ['mapa'],
	max_length 			: 3,

	// VARIABLES INTERNAS
	historial 			: new Array(),
	historial_opciones 	: new Array(),

	// FUNCIONES
	add : function (seccion, opciones){
		if (this.reinicia(seccion)) {
			this.historial 			= new Array();
			this.historial_opciones = new Array();
		}

		if (this.historial.length > 0) {
			if (this.last() != seccion) {
				this.historial.shift();
				this.historial_opciones.shift();

				this.historial.push(seccion);
				this.historial_opciones.push(opciones);
			} else {
				this.historial_opciones[this.historial_opciones.length-1] = opciones;
			}
		} else {
			this.historial.push(seccion);
			this.historial_opciones.push(opciones);
		}
	},

	get : function (){
		if (this.historial.length > 0) {
			return [this.historial.pop(), this.historial_opciones.pop()];
		} else {
			return ['mapa', {}];
		}
	},

	last : function (){
		if (this.historial.length > 0) {
			return this.historial[this.historial.length-1];
		} else {
			return 'mapa';
		}
	},

	reinicia : function (seccion){
		for (i=0; i<this.reinician.length; i++)
			if (this.reinician[i] == seccion)
				return true;
		return false;
	}
};
