﻿
/**
*	NonHdIsReady() object constructor.
*
**/
function NonHdIsReady()
{
	this._jQueryIsReady = false;
	this._jQueryTestTmrID = -1;
	this._isReadyStartedLoading = false;
	
	this.pageHasLoaded = false;
	
	this._browserVersion = null;
	this._browserType = null;
	
}//end NonHdIsReady()

NonHdIsReady.prototype.setBrowserTypeAndVersion = function()
{
	try
	{
		jQuery.each(jQuery.browser,	
						function(i, val)
						{
							if( i == "version")
							{
								__isReady._browserVersion = val;
							}
							else if(val)
							{
								__isReady._browserType = i;
							}
						}
					);
	}
	catch(e)
	{
		
	}
	
}//end NonHdIsReady.prototype.setBrowserTypeAndVersion

NonHdIsReady.prototype.pageLoaded = function()
{
	__isReady.pageHasLoaded = true;
	
	__isReady.setBrowserTypeAndVersion();
	
	__isReady.pageLoadedTime = (new Date()).getTime();
	
	if(!__isReady._isReadyStartedLoading)
	{
		// we weren't ready before, but are now, so load the rest of the scripts.
		__isReady.masterFileName = "js/loadingEvents/unload.js?cb=" + encodeURI(__isReady.pageLoadedTime);
		$.get(__isReady.masterFileName, null, __isReady.onMasterLoaded);
	}
	
	__isReady._isReadyStartedLoading = true;
	
	//alert("isready::pageLoaded(): FINISHED.");
	
}//end NonHdIsReady.prototype.pageLoaded()

NonHdIsReady.prototype.testForJQueryAndContinue = function()
{
	try
	{
		this._jQueryIsReady = false;
		try
		{
			if(jQuery)
			{
				this._jQueryIsReady = true;
			}
		}
		catch(e)
		{
			this._jQueryIsReady = false;
		}
		
		if(!this._jQueryIsReady)
		{
			if(this._jQueryTestTmrID >= 0)
			{
				clearTimeout(this._jQueryTestTmrID);
			}
			
			// jQuery isn't loaded, yet, try again in 500ms
			this._jQueryTestTmrID = setTimeout(this.testForJQueryAndContinue, 500);
		}
		else if(!this._isReadyStartedLoading)
		{
			// jQuery is now valid.  When it's ready, have it call pageLoaded().
			jQuery(document).ready(this.pageLoaded);
		}
	}
	catch(e2)
	{
		_jQueryIsReady = false;
	}
	
}//end NonHdIsReady.prototype.testForJQueryAndContinue()


NonHdIsReady.prototype.onMasterLoaded = function(a_data)
{
	try
	{
		//alert("NonHdIsReady.onMasterLoaded(): this=" + this + ", __isReady=" + __isReady);
		
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.text = a_data;
		
		var head = $("head")[0]; 
		
		head.appendChild(script);
	}
	catch(e)
	{
		alert("NonHdIsReady.onMasterLoaded(): caught error=" + e);
	}
	
	//alert("NonHdIsReady.onMasterLoaded(): FINISHED");
	
}//end NonHdIsReady.prototype.onMasterLoaded()

NonHdIsReady.prototype.getStatusObj = function()
{
	var statusObj = {};
	statusObj.jQueryIsReady = this._jQueryIsReady;
	statusObj.isReadyStartedLoading = this._isReadyStartedLoading;
	statusObj.pageHasLoaded = this.pageHasLoaded;
	
	statusObj.browserVersion = this._browserVersion;
	statusObj.browserType = this._browserType;
	
	return statusObj;
	
}//end NonHdIsReady.prototype.getStatusObj()

NonHdIsReady.prototype.toString = function()
{
	return "[object NonHdIsReady]";
	
}//end NonHdIsReady.prototype.toString()

/********************************************
*
*	CODE TO EXECUTE UPON LOADING-COMPLETE!
*
*
********************************************/

var __isReady;

try
{
	if(!__isReady)
	{
		__isReady = new NonHdIsReady();
		__isReady.testForJQueryAndContinue();
	}
}
catch(e)
{
	alert("NonHdIsReady.js: FAILED to call testForJQueryAndContinue.  Please note this message and contact customer service.");
	
	_loadingErrors.push("NonHdIsReady.js: FAILED to call testForJQueryAndContinue.  Please note this message and contact customer service. Caught error=" + e);
}

function getIsReadyStatus()
{
	var returnObj = __isReady.getStatusObj();
	
	return returnObj;
	
}//end getIsReadyStatus()

