/*
 * jQuery history plugin
 * 
 * sample page: http://www.mikage.to/jquery/jquery_history.html
 *
 * Copyright (c) 2006-2009 Taku Sano (Mikage Sawatari)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 */


jQuery.extend({
	historyCurrentHash: undefined,
	historyCallback: undefined,
	historyIframeSrc: undefined,
	
	historyInit: function(callback, src) {
		jQuery.historyCallback = callback;
		var current_hash = location.hash.replace("#","");//.replace(/\?.*$/, '');
		jQuery.historyCurrentHash = current_hash;
		// if ((jQuery.browser.msie) && (jQuery.browser.version < 8)) {
		jQuery.historyCallback(current_hash.replace(/^#/, ''));
		setInterval(jQuery.historyCheck, 100);
	},
	
	historyCheck: function() {
		var current_hash = location.hash.replace("#","");//.replace(/\?.*$/, '');
		if(current_hash != jQuery.historyCurrentHash) {
			jQuery.historyCurrentHash = current_hash;
			jQuery.historyCallback(current_hash.replace(/^#/, ''));
		}
	},
	
	historyLoad: function(hash) {
		jQuery.historyChange(hash);
		jQuery.historyCallback(hash);
	},
	
	historyChange: function(hash) {
		//hash = decodeURIComponent(hash.replace(/\?.*$/, ''));
		//hash = decodeURIComponent(hash);
		newhash = '#' + hash;
		location.hash = newhash;
		jQuery.historyCurrentHash = hash.replace("#", "");
	}
	
});