// this prevents double definition of Map24 namespace, what would cause 
// javascript errors
if( !(window["Map24"] instanceof Function) ) {
	/**
	 * 	The Map24 package is a package, it should not be used as constructor.
	 *
	 * 	@since 2.0.0
	 *	@constructor
	 *	@class
	 * 		This class defines the Map24 namespace and contains all classes 
	 * 		beeing necessary to load a pre-defined library package.
	 *
	 *	The Map24 package is the root namespace in which all further classes
	 *	will be located.
	 *
	 * 	@package Map24
	 * 	@copyright Copyright: &copy; NAVTEQ 2009
	 */
	window["Map24"] = function() {};
	
	// note: we have to use this syntax because of Internet Explorer, 
	// because if we use function Map24(){}; this stupid browser defines 
	// the function, even if it is already defined, therefore it causes an 
	// endless loop if using our debug-code
	/**
	 *	The version number of the API.
	 *
	 *	Syntax is "&lt;major&gt;.&lt;minor&gt;.&lt;release&gt.&lt;revision&gt;",
	 * 	e.g. "2.0.0.1208", "2.1.0.1508", "2.1.1.1708" or "2.2.0.1692". As you 
	 * 	can see, the revision is the build number and doesn't give you any 
	 * 	important information, this is only necessary to be able to check-out 
	 * 	the version from the repository. It is possible that a newer release 
	 * 	has a smaller revision number then an older one, if the older one has 
	 * 	received a fix lately, after the new release has been made.
	 *
	 *	@final
	 * 	@since 2.0.0
	 *	@type {String}
	 */
	Map24.VERSION = "2.2.0";
	/**
	 *	If true, then no wordbooks are used for bDOM encoding.
	 * 
	 * 	@private
	 * 	@since 2.0.0
	 * 	@type {boolean}
	 */
	Map24.DISABLE_WORDBOOK = false;
	/**
	 * 	A hashtable with all configuration information about the application 
	 * 	key beeing supplied as parameter while including this loader script.
	 *
	 *	The entries will have the properties "MapTpHost", "WebServicesBaseUrl", 
	 * 	"AjaxBaseUrl" and "XsltBaseUrl".
	 * 	
	 *	@private
	 * 	@since 2.2.0
	 * 	@type {Map24.AppKeyConfig[<Id>]}
	 */
	Map24._AppKeyConfig = {};
	/**
	 * 	The default application key to be used.
	 * 
	 *	@readonly
	 * 	@since 2.0.0
	 *	@type {String}
	 */
	Map24.DEFAULT_APPKEY = null;
	/**
	 *	The absolute URL of a spacer image.
	 *
	 *	@final
	 * 	@since 2.0.0
	 *	@type {String}
	 */
	Map24.SPACER_URL = null; // Map24.IMAGES_BASE_URL + "space.gif";
	/**
	 *	An array with all packages that should be loaded.
	 * 
	 * 	@private
	 * 	@since 2.0.0
	 *	@type {String[]}
	 */
	Map24.LIB_PACKAGES = [];
	/**
	 *	The user defined function to call.
	 * 
	 * 	@private
	 * 	@type function
	 * 	@since 2.0.0
	 */
	Map24.OnLoadCallback = null;
	
	/**
	 * 	This method is called by the Map24.loadApi method if loading the API 
	 *	and/or any of their packages failed.
	 * 
	 * 	@private
	 * 	@since 2.0.0
	 * 	@param {String} msg
	 * 		The error message with the reason why the load failed.
	 * 	@return {void}
	 */
	Map24.loadFailed = function( msg ) {};
	/**
	 * 	This hashtable contains the references to all classes that can be 
	 * 	created by their name.
	 *
	 * 	If you want to create a instance of a class the only thing you need 
	 * 	to do is to use the following code snipped:
	 * 	<pre>
	 * 	var c = new Map24.forName["Map24.Coordinate"](3000,500);
	 * 	</pre>
	 * 	This is much faster as using "eval"!
	 *
	 * 	@readonly
	 * 	@since 2.0.0
	 * 	@type {Function[<key>]}
	 */
	Map24.forName = {};
	/**
	 *	If this property is true, the API script is loaded in the debug mode.
	 * 
	 * 	This property is basically to prevent that the API is reloading 
	 * 	itself over and over again, therefore the API will only reload itself 
	 * 	once for debugging purposes if a new API version is requested via 
	 * 	the internal debug document URL parameter "map24:version=?".
	 * 
	 * 	@private
	 *	@since 2.1.0
	 * 	@type {boolean}
	 */
	Map24._DebugLoading = false;
	
	/**
	 * 	As long as this property is true, the method "Map24.loadApi" will 
	 * 	do nothing, but put the calling arguments into the static property 
	 * 	Map24._DebugLoadingApiRecall.
	 * 
	 * 	This is to prevent that the web application is loading the base 
	 * 	classes of the API until the loader script has reloaded itself for 
	 * 	debugging purpose.
	 * 
	 * 	@private
	 * 	@since 2.1.0
	 * 	@type {boolean}
	 */
	Map24._DebugLoadingApiStop = false;
	/**
	 *	If this property is set to a specific version, then the API will 
	 * 	load all packages and files of this version, inpedendently of what 
	 * 	the web application wants.
	 * 
	 * 	@private
	 * 	@since 2.1.0
	 * 	@type {String}
	 */
	Map24._DebugLoadVersion = null;
	/**
	 *	If the user has called the "loadApi" method while a debug-version 
	 * 	of the AJAX API is loading, this property contains the parameter 
	 * 	of this call.
	 * 
	 * 	After the debug version is loaded the loader script will call the 
	 * 	"Map24.loadApi" method with the parameters set in here.
	 * 
	 * 	@private
	 * 	@since 2.1.0
	 * 	@type {Object[]}
	 */
	Map24._DebugLoadingApiRecall = null;
	/**
	 * 	The method/function to be called as soon as the API is loaded and 
	 * 	ready and it will cause the Web Services classes to be created and 
	 * 	call the user-callback.
	 * 
	 * 	@private
	 * 	@since 2.0.0
	 * 	@return {void}
	 */
	Map24.onLoad = function() {
		setTimeout(Map24._async_onLoad,1);
	}
	/**
	 * 	Desynchronized "onLoad".
	 *
	 * 	Using this way leave the browser time to render the page while the 
	 * 	script is loading (strange enough). Seems only to apply only for 
	 * 	IE.
	 *
	 * 	@private
	 * 	@since 2.2.0
	 * 	@return {void}
	 */
	Map24._async_onLoad = function() {
		var item = Map24.LIB_PACKAGES.shift();
		if( item ) {
			Map24._include( item.Url );
		} else {
			Map24.preClassCreation();
			Map24.Xsd.Type.createClasses();
			Map24.Soap.Message.createClasses();
			Map24.postClassCreation();
			Map24.OnLoadCallback[1].call(Map24.OnLoadCallback[0]);
		}
	}
	
	/**
	 *	Files to be included asynchroniously.
	 *
	 *	@private
	 *	@since 2.2.0
	 *	@type {String[]}
	 */
	Map24._Includes = [];
	
	/**
	 *	Internal method to include the next pending script (called via 
	 *	setTimeout).
	 *
	 *	@private
	 * 	@since 2.0.0
	 * 	@return {void}
	 */
	Map24._async_include = function() {
		var url = Map24._Includes.shift();
		if( !url ) return;
		var script = document.createElement('script');
		script.defer = "defer";
		script.src = url;
		script.type= "text/javascript";
		script.charset = "utf-8";
		
		// this will work with all browsers, except Opera
		var opera = false;
		try {
			document.getElementsByTagName('HEAD')[0].appendChild(script);
		} catch(e) {
			// we don't like Opera
			opera = true;
		}
		
		// if we're within Opera or other simlar bad browsers
		if( opera ) {
			// append the script tag into the document (works here)
			document.appendChild(script);
		}
	
		//	Older alternative (had problems with some browsers)
		//
		//	document.write('<' + 'script');
		//	document.write(' language="javascript"');
		//	document.write(' type="text/javascript"');
		//	document.write(' src="' + Map24.CONST["HTTP_ROOT"] + name.replace(/[.]/g, "/") + '.js">');
		//	document.write('</' + 'script' + '>');
	}
	/**
	 *	Internal method to include a script.
	 *
	 *	@private
	 * 	@since 2.0.0
	 *	@param {String} url
	 * 		URL of the script to become included.
	 * 	@return {void}
	 */
	Map24._include = function( url ) {
		// this is a workaround for Opera and IE which might block the 
		// currently executed script and wait for the file to be included 
		// before continue to process the currently executed script, but as 
		// this method is defined as beeing asynchroniously we have to create 
		// timeout calls
		Map24._Includes[Map24._Includes.length] = url;
		setTimeout(Map24._async_include,1);
	}
	
	/**
	 *	This method will start loading the given AJAX API libraries.
	 *
	 * 	Possible optional parameters of the parameter "params" are:
	 * 	<ul>
	 * 	<li><b>gzip</b>: If set to false, then the uncompressed package files 
	 * 			are loaded. Only disable gzip compression if you have any 
	 * 			problems with this feature as it will slow down the API load 
	 * 			greatly!
	 *	<li><b>obfuscate</b>: If set to false, then the sourcecode will be 
	 * 			loaded which is a lot larger and slower then the obfuscated 
	 * 			version, but which is very helpfull while debugging.
	 * 	<li><b>AppKey</b>: Overwrite the application key to be used for 
	 * 			loading the API packages/files and set the default application
	 * 			key to be used if none is specified in the Map24.Map 
	 * 			constructor.
	 * 	<li><b>BASE_URL</b>: Overwrite the "AjaxBaseUrl" value of the 
	 *			application key configuration, which is the URL from where 
	 * 			the AJAX API and it's packages are loaded. If the URL is 
	 * 			finished with a slash (e.g. "http://localhost/ajax/") a 
	 * 			non-service load is estimated while a string finishing 
	 * 			without a slash estimates a service load (e.g. 
	 * 			"http://maptp.map24.com/map24/webserives1.5").
	 * 	<li><b>WEBSERVICES_BASE_URL</b>: Overwrite the WebServices base URL
	 * 			to be used for the default application key, must not be 
	 * 			finished with a slash, e.g. "http://maptp.map24.com/map24/webserives1.5".
	 * 	<li><b>MAPTP_HOST</b>: Overwrite the maptp-host to be set for the 
	 * 			default application key, e.g. "maptp.map24.com".
	 * 	<li><b>XSLT_BASE_URL</b>: Overwrite the XSLT base URI of the default 
	 * 			application key and must be finished with a slash, e.g. 
	 * 			"ajax/".
	 * 	<li><b>IMAGES_BASE_URL</b>: Overwrite the ImagesBaseUrl property of 
	 * 			the default application key with the supplied value, e.g.
	 * 			"http://localhost/images/" or 
	 * 			"http://maptp.map24.com/map24/webservices1.5?loadimg=".
	 * 	<li><b>NOSERVICELOAD</b>: Overwrite the autodetection if the AJAX 
	 * 			base URL is a service load or not.
	 * 	</ul>
	 * 
	 *	@final
	 * 	@since 2.0.0
	 * 	@param {String[]} lib_packages
	 * 		An array with the names of all API library packages to be loaded, 
	 * 		if this is only a string this is taken as the package name.
	 * 	@param {Function} callback
	 * 		The callback function to be called, either a function or an array 
	 * 		with the object and function like e.g. [obj, obj.method].
	 * 	@param {String = null} version
	 * 		If given, then it must be the version of the API to be loaded,
	 * 		otherwise the version setup to the application key with which 
	 * 		the loader script is included is used.
	 * 	@param {Object = null} params
	 * 		Additional optioinal parameters only to be used for debugging or 
	 * 		API development purpose (see function body description for more 
	 * 		details).
	 * 	@return {void}
	 * 	@throws {String}
	 * 		if any error occurs or any parameter is wrong.
	 */
	Map24.loadApi = function( lib_packages, callback, version, params ) {
		// if we should not load the API as we're reloading the loader script 
		// currently, remember the call to come back later
		if( Map24._DebugLoadingApiStop ) {
			Map24._DebugLoadingApiRecall = [lib_packages, callback, version, params];
			return;
		}
	
		// validate parameters
		if( typeof lib_packages=="string" ) lib_packages = [lib_packages];
		if( !(lib_packages instanceof Array) )
			throw "Map24.loadApi: Invalid 'lib_packages' parameter, should be of type string or array!";
		if( !(params instanceof Object) ) params = {};
	
		// register callback
		if( typeof callback=="function" )
			callback = [window, callback];
		if( !(callback instanceof Array) && typeof callback[1]!="function" )
			throw "Map24.loadApi: Invalid 'callback' supplied!";
		Map24.OnLoadCallback = callback;
		// fetch the default application key config
		var appkey = Map24._AppKeyConfig[ Map24.DEFAULT_APPKEY ];
		
		// if the user wants to use a different application key
		if( params["AppKey"] ) {
			// check if there is already a config for this key
			appkey = Map24._AppKeyConfig[ params["AppKey"] ];
			// if not
			if( !appkey ) {
				// create a new config as a clone of the default config
				appkey = new Map24.AppKeyConfig();
				var default_appkey = Map24._AppKeyConfig[ Map24.DEFAULT_APPKEY ];
				if( default_appkey )
					for( var key in default_appkey ) appkey[key] = default_appkey[key];
				appkey.Id = params["AppKey"];
				Map24._AppKeyConfig[ appkey.Id ] = appkey;
			}
		}
		// overload API version, if requires
		if( typeof version=="string" ) appkey.Version = version;
		if( typeof Map24._DebugLoadVersion=="string" ) appkey.Version = Map24._DebugLoadVersion;
		// if debug-mode
		var no_service_mode = null;
		var obfuscate = true;
		var gzip = true;
		var no_test_lib = false;
		if( params instanceof Object ) {
			if( typeof params["gzip"]=="boolean" )
				gzip = params.gzip;
			if( typeof params["obfuscate"]=="boolean" )
				obfuscate = params.obfuscate;
			if( typeof params["NOSERVICELOAD"]=="boolean" && params.NOSERVICELOAD )
				no_service_mode = true;
			if( typeof params["NOTESTLIB"]=="boolean" && params.NOTESTLIB )
				no_test_lib = true;
			if( typeof params["BASE_URL"]=="string" )
				appkey.AjaxBaseUrl = params.BASE_URL;
			if( typeof params["WEBSERVICES_BASE_URL"]=="string" )
				appkey.WebServicesBaseUrl = params.WEBSERVICES_BASE_URL;
			if( typeof params["MAPTP_HOST"]=="string" )
				appkey.MapTpHost = params.MAPTP_HOST;
			if( typeof params["XSLT_BASE_URL"]=="string" )
				appkey.XsltUri = params.XSLT_BASE_URL;
			if( typeof params["IMAGES_BASE_URL"]=="string" )
				appkey.ImagesBaseUrl = params.IMAGES_BASE_URL;
		}
		
		// for Internet Explorer <= IE 6.0 SP2 we do have to disable GZIP 
		// compression as it won't work (see MRFC-41)
		try {
			if( navigator.userAgent.match(new RegExp("MSIE")) ) {
				var ie_rexp = new RegExp("MSIE ([0-9])\\.([0-9])([0-9]{0,1})");
				var ie_res = ie_rexp.exec( navigator.userAgent );
				if( (ie_res instanceof Array) && (ie_res.length>=2) ) {
					if( ie_res[1]<6 )
						gzip = false;
					else
					// ok, IE 6
					if( ie_res[1]==6 ) {
						// IE 6.0 SP2+ contains "SV1" in the user-agent, while
						// IE 6 SP1 or below doesn't
						ie_rexp = new RegExp("(SV1)");
						ie_res = ie_rexp.exec( navigator.userAgent );
						if( !(ie_res instanceof Array) ||
							(ie_res.length<2) ||
							(ie_res[1]!="SV1") ) {
							// for IE 6.0 below SP2 don't use GZIP compression
							gzip = false;
						} // else
						// gzip stays what it is as we've IE 6 SP2+
					}
				}
			}
		} catch(e) {}
		// if we have do not have a WebServices base URL or other URLs 
		// missing, build default values
		if( !appkey.WebServicesBaseUrl ) 
			appkey.WebServicesBaseUrl = appkey.Protocol +
										"://" +
										appkey.MapTpHost+
										"/map24/webservices1.5";
		if( !appkey.ImagesBaseUrl ) {
			if( appkey.AjaxBaseUrl.charAt(appkey.AjaxBaseUrl.length-1)=="/" ) {
				appkey.ImagesBaseUrl = appkey.AjaxBaseUrl+"images/";
			} else {
				appkey.ImagesBaseUrl = appkey.WebServicesBaseUrl+
							"?action=demo&image=../../ajax/"+
							appkey.Version+
							"/images/";
			}
		}
		if( !appkey.XsltBaseUri )
			appkey.XsltBaseUri = "ajax/";
		if( !appkey.XsltUri )
			appkey.XsltUri = appkey.XsltBaseUri+appkey.Version+"/";
		// if the web application has modfied the application key, rewrite 
		// the new config as default config
		if( params["AppKey"] ) Map24.setDefaultAppKey(appkey);
		// if the document URL contains the string "map24:test_lib=1", then 
		// we will load the API test-unit package which will allow us to load 
		// aribitrary code that is specified in the additional parameter 
		// "map24:debug_lib=<url>". The debug-lib will be loaded as first library 
		// and therefore takes over full control over the whole loading process
		// and the application.
		// Note that the test-lib is uploaded on demand only and must be deleted
		// if no longer beeing necessary.
		if( !no_test_lib ) try {
			var doc_url = decodeURIComponent(top.document.URL);
			var patch_lib_regexp = new RegExp("(.*?)map24:test_lib=([0-9._ystrue]*)","i");
			var lib_patch = patch_lib_regexp.exec( doc_url );
			if( (lib_patch instanceof Array) && (lib_patch.length >=2) &&
				(typeof lib_patch[2]=="string") && (lib_patch[2].length>=1) ) {
				lib_packages.unshift( "test_lib" );
			}
		} catch(e) {
			// ignore exceptions as this is only a debug feature
		}
	
		// set libs to be loaded
		var lib_url = null;
		var service_load = null;
		var lib_url_regex = new RegExp("^[a-z0-9]+://","i");
		for( var i=0; i<lib_packages.length; i++) {
			lib_url = lib_packages[i];
			if( typeof lib_url != "string") throw "Map24.loadApi: Invalid 'lib_packages' parameter!";
			// if the library URL is absolute
			if( lib_url.match(lib_url_regex) ) {
				// nothing do to
			} else
			// otherwise, a relative library URL is supplied 
			{
				// if we should autodetect service-mode
				if( no_service_mode==null ) {
					if( appkey.AjaxBaseUrl.charAt( appkey.AjaxBaseUrl.length -1 )=="/" )
						service_load = false;
					else
						service_load = true;
				} else
				// otherwise we do what the user has told us
					service_load = !no_service_mode;
				// if we're loading from the WebServices
				if( service_load ) {
					lib_url = appkey.AjaxBaseUrl+
							"?action=ajax_load_part"+
							"&v="+appkey.Version+
							"&name="+lib_packages[i]+
							"&gzip="+(gzip?"1":"0")+
							"&obfuscate="+(obfuscate?"1":"0");
				} else
				// otherwise, we're loading the an absolute URL
				{
					lib_url = appkey.AjaxBaseUrl+
								"api/"+lib_packages[i]+
								(obfuscate?"_obfuscated":"")+
								".js";
				}
			}
			Map24.LIB_PACKAGES[Map24.LIB_PACKAGES.length++] = { Url: lib_url };
		}
	
		// load first item from libs
		Map24.onLoad();
	}
	/**
	 * 	This method will set the supplied application key configuration as 
	 * 	the default application key to be used.
	 *
	 *	@since 2.2.0
	 * 	@param {Map24.AppKeyConfig} appkey
	 * 		The application key to be set as default application key.
	 * 	@return {void}
	 * 	@throws {String}
	 * 		if the supplied parameter 'appkey' is no valid instance of 
	 * 		Map24.AppKeyConfig.
	 */
	Map24.setDefaultAppKey = function( appkey ) {
		if( !(appkey instanceof Map24.AppKeyConfig) ) throw "Invalid application key supplied, no instance of Map24.AppKeyConfig!";
		Map24.VERSION = appkey.Version;
		Map24.DEFAULT_APPKEY = appkey.Id;
		Map24.MAPTP_HOST = appkey.MapTpHost;
		Map24.BASE_URL = appkey.AjaxBaseUrl;
		Map24.WEBSERVICES_BASE_URL = appkey.WebServicesBaseUrl;
		Map24.IMAGES_BASE_URL = appkey.ImagesBaseUrl;
		Map24.SPACER_URL = Map24.IMAGES_BASE_URL + "core_api/space.gif";
		Map24.XSLT_BASE_URL = appkey.XsltUri;
	}
}
/**
 * 	This method initializes the API, does some debug loading aso..
 *
 * 	The method is automatically called at the end of the loader script and 
 * 	the call can be found in the "loader.xml" config file. The reason for 
 * 	beeing located there is, that this method requires the class 
 * 	"Map24.AppKeyConfig" to be included before beeing called.
 * 
 * 	@private
 * 	@since 2.2.0
 * 	@return {void}
 */
Map24.$init = function() {
	// the content of the strings is replaces by the Web Services with 
	// correct values
	var default_appkey = "CJX_APPKEY_AJAX_CUSTOMER_ROLLOUT_00";
	var version = "2.3.0.4700";
	var ajax_base_url = "http://maptp.webmaps.com.mx/WebMaps/ajax";
	var webservices_base_url = "http://maptp.webmaps.com.mx/WebMaps/webservices1.5";
	var maptp_host = "maptp.webmaps.com.mx";
	var xslt_base_uri = "ajax/";
	var appkey = null;
	
	// if the Web Services have done the replacements and we've received 
	// a new application key, add this key into the global hashtable of 
	// keys
	if( default_appkey != ("$"+"{AJAX_DEFAULT_APPKEY}") ) {
		appkey = new Map24.AppKeyConfig();
		appkey.Id = default_appkey;
		appkey.Version = version;
		appkey.MapTpHost = maptp_host;
		appkey.AjaxBaseUrl = ajax_base_url;
		appkey.WebServicesBaseUrl = webservices_base_url;
		appkey.ImagesBaseUrl = webservices_base_url+"?action=demo&image=../../ajax/"+version+"/images/";
		appkey.XsltBaseUri = xslt_base_uri;
		appkey.XsltUri = xslt_base_uri + version + "/";
		Map24._AppKeyConfig[ appkey.Id ] = appkey;
	}
	
	// for the first application key loaded we will fill the old deprecated 
	// static properties to guarantee downward compatibility with older code
	if( appkey && !Map24.DEFAULT_APPKEY ) Map24.setDefaultAppKey( appkey );
	// if we've not done a debug loading already (this section must only be 
	// entered once, even if the file is included multiple times to prevent 
	// endless-looping API reloading)
	if( appkey && !Map24._DebugLoading ) {
		// if the document URL contains the string "map24:version=", then we 
		// will reload the API with the version supplied
		var doc_url = null;
		var version = null;
		try {
			doc_url = decodeURIComponent(top.document.URL);
			var patch_version_regexp = new RegExp("(.*?)map24:version=([a-z0-9._]*)","i");
			var ver_patch = patch_version_regexp.exec( doc_url );
			if( (ver_patch instanceof Array) && (ver_patch.length >=2) &&
				(typeof ver_patch[2]=="string") && (ver_patch[2].length>=3) ) {
				version = ver_patch[2];
			}
		} catch(e) {
			// ignore exceptions as this is only a debug feature
		}
	
		// if a debug version is wished, reload the loader script
		if( version!=null ) {
			// we're in debug loading, stop loading the final API classes 
			// and files until we've finished reloading the loader script 
			// in debug mode and remember the version that we should load
			// later
			Map24._DebugLoading = true;
			Map24._DebugLoadingApiStop = true;
			Map24._DebugLoadVersion = version;
			Map24._include( appkey.AjaxBaseUrl+"?appkey="+appkey+"&v="+version );
		}
	} else 
	// if this script is included the second time as part of a debug loading
	if( Map24._DebugLoading ) {
		// from now on the loadApi method is correct, it may start loading the 
		// class files
		Map24._DebugLoadingApiStop = false;
		
		// if the "Map24.loadApi" method has been called meantime, recall it 
		// now
		if( Map24._DebugLoadingApiRecall!=null ) {
			var args = Map24._DebugLoadingApiRecall;
			Map24._DebugLoadingApiRecall = null;
			Map24.loadApi( args[0], args[1], args[2], args[3] );
		}
	}
};
/**
 *	Creates a new application key configuration.
 * 
 * 	@since 2.2.0
 *	@constructor
 * 	@param {Object = null} default_args
 * 		A hashtable with the default values to be set at this instance. If 
 * 		false is supplied this instance should be a prototype constructor 
 * 		and will not do anything within the constructor.
 *
 *	@class
 * 		This class represents all basic information available about an 
 * 		application key.
 * 	@package Map24
 * 	@copyright Copyright: &copy; NAVTEQ 2009
 */
Map24.AppKeyConfig = function( default_args ) {
	// skip prototype constructors
	if( typeof default_args=="boolean" && default_args==false ) return;
	if( default_args!=null && (default_args instanceof Object) ) {
		for( var key in default_args ) this[key] = default_args[key];
	}
}
/** @private */
Map24.AppKeyConfig.prototype = {};
/** @private */
Map24.AppKeyConfig.prototype.Super = {};
/** @private */
Map24.AppKeyConfig.prototype.constructor = Map24.AppKeyConfig;
/** @private */
Map24.AppKeyConfig.prototype.Class = "AppKeyConfig";
/** @private */
Map24.AppKeyConfig.prototype.Package = "Map24";
/** @private */
Map24.AppKeyConfig.prototype.ClassId = "Map24.AppKeyConfig";
/** @private */
Map24.forName["Map24.AppKeyConfig"] = Map24.AppKeyConfig;
/**
 * 	The application key identifier of this configuration set.
 *
 * 	@readonly
 *	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.Id = null;
/**
 * 	The base URL from where AJAX API and it's packages should be loaded.
 *
 *	If this value is not finished with a slash, then it is taken as a 
 * 	service URL (e.g. "http://maptp11.map24.com/ajax") and it will be 
 * 	appended by a question mark and parameters to load the API files. If it 
 * 	is finished with a slash, then it will be seens as a no-service load 
 * 	(e.g. "http://localhost/ajax/") and the API will load it's files by 
 * 	appending the filenames to the URL.
 * 
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.AjaxBaseUrl = null; // BASE_URL
/**
 * 	The base URL from where AJAX API loads images.
 *
 *	This value must be finished with a slash and is always taken as a 
 * 	no-service load, e.g. "http://img.map24.com/images/", however, it might 
 * 	contains as well a service request like e.g. 
 * 	"http://maptp11.map24.com/map24/webservices1.5?action=loadimage&img=", 
 * 	because the final URL is build by simply appending the filename to the 
 * 	base URL.
 *
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.ImagesBaseUrl = null; // IMAGES_BASE_URL
/**
 * 	The base URL of the Map24 Web Services.
 *
 *	This property must not be finished with a slash and must contain the 
 * 	full URL of the WebServices, e.g. "http://maptp11.map24.com/map24/webservices1.5".
 * 
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.WebServicesBaseUrl = null; // WEBSERVICES_BASE_URL
/**
 *	The maptp-host for which this application key is been setup, e.g. 
 * 	"maptp11.map24.com".
 *
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.MapTpHost = null; // MAPTP_HOST
/**
 * 	A list that contains a regular expressions to be used for to detect if 
 * 	a hostname should be randomized followed by a "key" to use for the  
 * 	replacement.
 *
 *	The "key" may contain two type of placeholders, ${PERFIX} to put in the  
 *	randomized prefix for the supplied salt and hostname as returned by the 
 *	method "fromSaltToPrefix" and "${<n>}" to be replaced by the n'th match 
 *	of the regex. The default key looks like "${PREFIX}.tl.${1}" which will 
 *	result in hostnames like "DFD43DH.tl.maptp999.map24.com".
 *
 *	@since 2.3.0
 *	@type {String[]}
 */
Map24.AppKeyConfig.prototype.RandomHosts = [
	new RegExp("(maptp[0-9]*.map24.com)","mgi"), "${PREFIX}.tl.${1}",
	new RegExp("(tmaptp[0-9]*.traffic.com)","mgi"), "${PREFIX}.tl.${1}"
];
/**
 *	The protocol to be used to communicate with the maptp-host, e.g. "http"
 * 	or "https".
 *
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.Protocol = "http";
/**
 * 	The AJAX API version for which this application key is configured.
 *
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.Version = null;
/**
 * 	The relative URI of where the XSLT files are located on the Web Services
 * 	finished with a slash, e.g. "ajax/".
 *
 * 	@readonly
 * 	@since 2.2.0
 * 	@type {String}
 */
Map24.AppKeyConfig.prototype.XsltBaseUri = null;
/**
 *	The relative URI of where the XSLT files for this application key are 
 * 	located on the Web Services finished with a slash, e.g. "ajax/2.1.2/".
 *
 *	@readonly
 * 	@since 2.2.0
 *	@type {String}
 */
Map24.AppKeyConfig.prototype.XsltUri = null; // XSLT_BASE_URL
/**
 * 	This method returns a hostname prefix for the supplied salt and hostname.
 * 
 * 	This method may be overloaded if the number of available subdomains are 
 * 	limited, e.g. only "1.tl.<host>" up to "9.tl.<host>" are available. By 
 * 	default the method will return a hash like "A62932FC".
 *
 *	@since 2.3.0
 *	@param {String} hostname
 *		The hostname for which the salt should be used.
 *	@param {String = null} salt
 *		An arbitrary salt or null if not supplied.
 *	@return {String}
 *		The host prefix to be used for the supplied salt and hostname.
 */
Map24.AppKeyConfig.prototype.fromSaltToPrefix = function( hostname, salt ) {
	if( typeof salt=="number" ) salt = ""+salt;
	if( typeof salt!="string" ) salt = new Date().getTime()+"_"+Math.random();
	return Map24.hash( salt ).toLowerCase();
}
/**
 *	This method will return a random host for the supplied hostname and 
 *	salt, only used internally by the class.
 *
 *	@since 2.3.0
 *	@param {String} hostname
 *		The hostname for which a random host should be created.
 *	@param {String = null} salt
 *		An optional salt to create the same hostname for the same situation.
 *	@return {String}
 *		The randomized hostname, if randomization is possible.
 */
Map24.AppKeyConfig.prototype.getRandomHost = function( hostname, salt ) {
	if( !(this.RandomHosts instanceof Array) || this.RandomHosts.length==0 ) return hostname;
	// otherwise, fix paramters
	if( typeof hostname!="string" ) hostname = this.MapTpHost;
	// check if for the supplied hostname a valid replacement key is defined
	for( var i=0; i < this.RandomHosts.length; i+=2 ) {
		// if yes
		if( hostname.match( this.RandomHosts[i] ) ) {
			// apply the regexp and create the randomized hostname
			var m = this.RandomHosts[i].exec( hostname );
			if( !(m instanceof Array) || (m.length <= 0) ) return hostname;
			var key = this.RandomHosts[i+1].replace("${PREFIX}", this.fromSaltToPrefix(hostname, salt));
			for( var j=1; j < m.length; j++ ) {
				key = key.replace("${1}", m[1].replace("$", "$$"));
			}
			return key;
		}
	}
	return hostname;
}
/**
 *	This method will try to return a random URL for the maptp-server so that 
 * 	multiple parallel requests to the maptp-server can be done, because 
 * 	normally the browser will only open up to two parallel connection per 
 * 	host.
 * 
 * 	Note that the returned host-name might been a static one if the 
 *	corresponding maptp-server doesn't support random URLs.
 *
 * 	@since 2.2.0
 * 	@param {String} salt
 * 		The salt to be used to build the hash, if not supplied the salt will 
 * 		be a random number, for the same salt the same URL is returned!
 * 	@return {String}
 * 		The hostname of the maptp-server, e.g. "AF4D7312.tl.maptp11.map24.com".  
 */
Map24.AppKeyConfig.prototype.getRandomMapTpHost = function( salt ) {
	if( !(this.RandomHosts instanceof Array) || this.RandomHosts.length==0 ) return this.MapTpHost;
	return this.getRandomHost(this.MapTpHost, salt);
};
/**
 *	This method will try to return a random URL for the WebServices so that 
 * 	multiple parallel requests to the Web Services can be done, because 
 * 	normally the browser will only open up to two parallel connection per 
 * 	host.
 * 
 * 	Note that this mechanism doesn't work for HTTPS, in that case the 
 * 	method returns the original URL and it won't work for any other 
 * 	WebServices URLs except those of the Map24 cluser. However, feel free 
 * 	to overload this method and to implement your own randomize, e.g. if 
 * 	you have a certain amount of WebServices URLs.
 *
 * 	@since 2.2.0
 * 	@param {String} salt
 * 		The salt to be used to build the hash, if not supplied the salt will 
 * 		be a random number, for the same salt the same URL is returned!
 * 	@return {String}
 * 		The full URL of the Map24 Web Services, e.g. 
 * 		"http://AF4D7312.tl.maptp11.map24.com/map24/webservices1.5".
 */
Map24.AppKeyConfig.prototype.getRandomWebServicesUrl = function( salt ) {
	if( !(this.RandomHosts instanceof Array) || this.RandomHosts.length==0 ) return this.WebServicesBaseUrl;
	var url = new Map24.Url( this.WebServicesBaseUrl );
	return this.WebServicesBaseUrl.replace( url.Host, this.getRandomHost(url.Host, salt) );
};
/**
 *	This method will try to return a random URL for requesting images
 * 	from the server so that multiple parallel requests to the server can
 * 	be done, because normally the browser will only open up to two parallel
 * 	connection per host.
 * 
 * 	@since 2.2.0
 * 	@param {String} salt
 * 		The salt to be used to build the hash, if not supplied the salt will 
 * 		be a random number, for the same salt the same URL is returned!
 * 	@return {String}
 * 		The base URL from where to request AJAX API images, e.g. 
 * 		"http://AF4D7312.tl.maptp11.map24.com/map24/webservices1.5?action=demo&image=../../ajax/"+version+"/images/"
 * 		or something like "http://localhost/files/images/".
 */
Map24.AppKeyConfig.prototype.getRandomImageUrl = function( salt ) {
	if( !(this.RandomHosts instanceof Array) || this.RandomHosts.length==0 ) return this.ImagesBaseUrl;
	
	var url = new Map24.Url( this.ImagesBaseUrl );
	return this.ImagesBaseUrl.replace( url.Host, this.getRandomHost(url.Host, salt) );
};
Map24.$init();
