
/**
 * "History" -- a wrapper class for unfocus's HistoryKeeper.  We use flash, and unfocus is
 * cool.  The FlashSuite is way too complicated, especially since ExternalInterface is on
 * the scene.  So, using ExternalInterface, and HistoryKeeper, we now have a super clean,
 * super easy to use Flash-Based-History-System.
 *
 * Thanks unfocus-history-keeper Team!
 *
 * Requirements:
 * 	unFocusHistory-p.js -- or any derivative of unfocus HistoryKeeper
 * 	History.js -- this javascript file
 * 	History.as -- the actionscript 2.0 class file
 *
 * Issues:
 *	safari dosent work.  bookmarking works fine, but setting unFocus.History.addHistory();
 *	does not register history states when it comes from flash.
 */

if(typeof thetainteractive == "undefined") var thetainteractive = new Object();
if(typeof thetainteractive.utilities == "undefined") thetainteractive.utilities = new Object();
if(typeof thetainteractive.utilities.History == "undefined") new function () {
	thetainteractive.utilities.History = this;
	/**
	 * private _SWFID: String
	 *	the id in the html for the flash object
	 */
	var _SWFID;
	/**
	 * private getSWFObject
	 *	this is the recommended Macromedia method for finding the swf object for use
	 *	with ExternalInterface
	 *
	 * @return Object
	 *	returns the html entity that is the swf object that controls the history
	 */
	function getSWFObject () {
		if (navigator.appName.indexOf("Microsoft") != -1) return window[_SWFID];
		else return document[_SWFID];
	}
	/**
	 * private setBrowserState
	 *	this sets the current state of the browser and flash
	 *
	 * @param hash:String
	 *	the new hash string for the url
	 */
	function setBrowserState (hash) {
		if (hash==""||hash=="null"||hash==null||hash==undefined) return;
		getSWFObject().thetainteractive_utilities_History_setHistory(hash);
	}
	/**
	 * public SWFID
	 *	sets the id of the swf
	 *
	 * @param id:String
	 *	the element id for the swf that controls the history
	 */
	this.SWFID = function (id) {
		_SWFID = id;
	}
	/**
	 * public listener
	 *	event that listens to the history object
	 *
	 * @param hash:String
	 *	the new hash string for the url
	 */
	this.listener = function(hash) {
		setBrowserState(hash);
	};
	/**
	 * public setHistory
	 *	add a history state to the history.  this will in turn fire the listener
	 *
	 * @param hash:String
	 *	the new hash string for the url
	 */
	this.setHistory = function(hash) {
		if (hash==""||hash=="null"||hash==null||hash==undefined) return;
		unFocus.History.addHistory(hash);
	};
	/**
	 * public getHistory
	 *	add a history state to the history.  this will in turn fire the listener
	 *
	 * @return:String
	 *	the new hash string for the url
	 */
	this.getHistory = function(hash) {
		return unFocus.History.getCurrent();
	};
	/**
	 * subscribe to the historyChange event
	 */
	unFocus.History.addEventListener('historyChange', this.listener);
}

/**
 * create a shortcut for this class
 */
var History = thetainteractive.utilities.History;
