function History() {
	// Init the history array (Where all history related things is stored)
	this._history = [];
	
	// Init the pop history array
	this._popHistory;
	
	// Init the hash: make sure it's "#_0" 
	location.hash = "#_"+ this._history.length;
	// Save the hash in a "global" variable for later comparesent (History.prototype.checkHash)
	this._hash = "#_"+ this._history.length;
}

History.prototype.addFile = function(previousView, thisView, thisTitle, changeAction, keepOldLogs) {
	
	// Push a file to the history stack.
	this._history.push({from:previousView, to:thisView, title:thisTitle, action:changeAction});
	
	//  _popHistory is all the used of back button used in row. If you go th "right" direction it empty it.
	if (!keepOldLogs) {  
		this._popHistory = [];
	}
	
	// Change both the "global" variable and the hash
	this._hash = "#_"+ this._history.length;
	location.hash = this._hash;
};

History.prototype.popFile = function() {
	/* popFile: pops the last element of _history and returns it. And it change the hash. */
	
	// Pop the file;
	var pop = this._history.pop(); 
	
	// Push it to the pop history
	this._popHistory.push(pop); 
	
	// Change the hash
	this._hash = "#_"+ this._history.length;
	
	// Apply the changes
	location.hash = this._hash; 
	
	// return the poped element
	return pop;
};

History.prototype.checkHash = function() {
/* changeHash: Running in an interval. It is running every 300 millisecond. It checkes if the hash has change. And makes sure the grey (X) is displaying as it shoud. */
	// If the hash has been change
	if (this._hash != location.hash) {
	
		// Get the number of the old hash
		var newHashNumber = location.hash.substr(2);
		// And the new one
		var oldHashNumber = this._hash.substr(2);
		
		//newHashNumber is greater then oldHashNumber  that mens the forward button has been used
		if (newHashNumber > oldHashNumber) {
		
			// Pop this element from the pop history
			var bob = this._popHistory.pop();
			
			// load the view (including the title)
			UI.clickAndGo(bob.to.id, bob.title, bob.action, true);
			// If an action is set
			if (bob.action) {
				// Trigger it
				bob.action(); 
			}
			// set the hash reference variabel to the new hash
			this._hash = location.hash 
		} else {
			// The back button has been used
			UI.goBack();
		}
		this._hash = location.hash; // set the hash reference variabel to the new hash
	}
	// if the search field is existing
	if (document.getElementById('field_search')) {
		// And the value is not nil
		if (document.getElementById('field_search').value != "") { 
			// Display the grey (X)
			document.getElementById('error').style.backgroundPosition = "0 19px";
			
			// Make sure it has display: block
			document.getElementById('error').style.display = "block";
		} 
		// Remove the (X) if the search field is empty and not displaying the red arrow
		else if (parseInt(document.getElementById('error').style.backgroundPositionY) != 0) { 
			document.getElementById('error').style.display = "none";
		}
	}

};
History.prototype.getLength = function() {
	return this._history.length;
};

History.prototype.getPreviousTitle = function() {
	return this._history[this._history.length - 1].title;
};