if(window.dhtmlHistory) {
window.dhtmlHistory.create({
	toJSON: function(o) {
		return Object.toJSON(o);
	}
	, fromJSON: function(s) {
		return s.evalJSON();
	}
});
}
/*
window.onload = function() {
	//initialize our DHTML history
	dhtmlHistory.initialize();
	log("<b>dhtmlHistory initialized</b>");

	//subscribe to DHTML history change events
	dhtmlHistory.addListener(historyChange);
	log("<b>dhtmlHistory listener created</b>");
};

*/
if(window.dhtmlHistory) {
Event.observe(window, 'load', function() {
        dhtmlHistory.initialize();
		//log("<b>dhtmlHistory initialized</b>");
        dhtmlHistory.addListener(historyChange);
		//log("<b>dhtmlHistory listener created</b>");
});
}

addHistoryEvent = function() {
	if (!rawMaterial[rawIndex]) {
		rawIndex = 0;
	}
	var a = rawMaterial[rawIndex];
	dhtmlHistory.add(a[0],a[1]);
	if (typeof a[1] == "object") {/*stringify this so we can log it better*/
		a[1] = historyStorage.toJSON(a[1]);
	}
	var msg = "<b>A history event has been added:</b> [newLocation=" + a[0] + " | historyData=" + a[1] + "]";
	//alert(msg);
	myLocation = a[0]; 
	$('storageContainer').update($('ajaxContainer').innerHTML);
		
	rawIndex++;
}

/*basic DHTML logging for our test page*/
function log(msg) {
/*
	var logNode = document.getElementById("logWin");
	var content = "<p>" + msg + "</p>" + logNode.innerHTML;
	logNode.innerHTML = content;
*/
}
function clearLog(msg) {
	var logNode = document.getElementById("logWin");
	logNode.innerHTML = "";
}

function historyChange(newLocation, historyData) {
	var historyMsg = (typeof historyData == "object" && historyData != null
		? historyStorage.toJSON(historyData)
		: historyData
	);
	var msg = "<b>A history change has occured:</b> | newLocation=" + newLocation + " | historyData=" + historyMsg + " |";
	
	//alert(msg);
	if(myLocation > newLocation) { 
		//window.location.reload(); 
		$('ajaxContainer').update($('storageContainer').innerHTML);
		$('left_searchResults').hide(); 
	}
};

var myLocation = '';
/*set up test cases for dhtmlHistory*/
var rawIndex = 0;
var rawMaterial = [
	["1", "Hello World Data"],
	["2", 33],
	["3", true],
	["4", true],
	["5","let's try a digit"],
	["6","value of 'four' has now been reset"],
	["complexObject",{
		value1: "This is value1",
		value2: "This is value2",
		value3: ["This is array[0]","This is array[1]"]
	}],
	["7",[0,1,"three","five",9]],
	["8","more data"]
	["complexObject",{
		new1: "all-new",
		new2: "all-different",
		new3: ["it's","the","uncanny","complexObject"]
	}],
];

function callHSTest(hash,val) {
	historyStorage.put(hash,val);
	log("Setting key <b>" + hash + "</b> to value <b>" + val + "</b>.");
}