MapAppLoader=function(){};MapAppLoader.prototype.appendToDom=function(fileRef){if(typeof fileRef!="undefined"){document.getElementsByTagName("head")[0].appendChild(fileRef);}};MapAppLoader.prototype.afterLoadProject=function(ajaxRequest){var javaScript='('+ajaxRequest.responseText+')';var result=null;try{result=eval(javaScript);}
catch(e){HSLayers.Apps.Debug.error("Error in loading project definition :");HSLayers.Apps.Debug.error(e);HSLayers.Apps.Debug.error(ajaxRequest.responseText);}
if(result!=null){this.doOnProcessLoadedProject(result.project);var appOptions=HSLayers.Apps.MapAppOptions.getDefaultOptions();appOptions.imgPath=this.getScriptLocation()+"../img/";appOptions.layerSwitcherAdapter="HSLayers.Apps.LsaHSLayerSwitcher";appOptions.language=result.language;appOptions.hsLayersVersion=MapAppLoader._hsLayersVersion;appOptions=HSLayers.Apps.Options.overrideOptions(appOptions,this.options);HSLayers.Apps.Options.sendToDebug(appOptions);var app=this.app;if(app==null){app=this.createDefaultApplication(appOptions);this.app=app;}else{app.initOptions(appOptions);}
app.initProject(result.project);var mapViewer=new HSLayers.Apps.MapViewer();var layerSwitcherAdapter=this.createLayerSwitcherAdapter(appOptions.layerSwitcherAdapter);var dataObjectProvider=new HSLayers.Apps.DataObjectProviderMawes(appOptions);dataObjectProvider.setSearchUrl(result.searchUrl,result.searchUrlMap,result.searchUrlText);var selectedObjectsAdapter=this.createSelectedObjectsAdapter(appOptions.selectedObjectsAdapter,mapViewer);mapViewer.setSelectedObjectsAdapter(selectedObjectsAdapter);app.setLayerSwitcherAdapter(layerSwitcherAdapter);app.setDataObjectProvider(dataObjectProvider);app.setMapViewer(mapViewer);app.init();app.createMapControl();app.initUIForMap();app.initLayerSwitcherAdapter();app.initMapViewer();this.doOnReady(appOptions.appContext);}else{this.doOnError();}};MapAppLoader.prototype.createDefaultApplication=function(appOptions){var app=null;if(MapAppLoader._uiLibrary=="ExtJS"){app=new HSLayers.Apps.ViewerAppExt(appOptions);}else{app=new HSLayers.Apps.ViewerAppHtml(appOptions);}
return app;}
MapAppLoader.prototype.createLayerSwitcherAdapter=function(className){var layerSwitcherAdapter=null
className=this.processLayerSwitcherClassName(className);if(className=="HSLayers.Apps.LsaHSLayerSwitcher"){layerSwitcherAdapter=new HSLayers.Apps.LsaHSLayerSwitcher();}
if(className=="HSLayers.Apps.LsaHSBoxLayerSwitcher"){layerSwitcherAdapter=new HSLayers.Apps.LsaHSBoxLayerSwitcher();}
if(layerSwitcherAdapter==null){layerSwitcherAdapter=new HSLayers.Apps.LayerSwitcherAdapter();}
return layerSwitcherAdapter;};MapAppLoader.prototype.createSelectedObjectsAdapter=function(className,mapViewer){var selectedObjectsAdapter=null;if(className=="HSLayers.Apps.SoaMarkers"){selectedObjectsAdapter=new HSLayers.Apps.SoaMarkers(mapViewer);}
if(className=="HSLayers.Apps.SoaVectors"){selectedObjectsAdapter=new HSLayers.Apps.SoaVectors(mapViewer);}
return selectedObjectsAdapter;};MapAppLoader.prototype.doOnError=function(){if(MapAppLoader.onError!=null){MapAppLoader.onError();}};MapAppLoader.prototype.doOnProcessLoadedProject=function(project){if(MapAppLoader.onProcessLoadedProject!=null){MapAppLoader.onProcessLoadedProject(project);}};MapAppLoader.prototype.doOnReady=function(appContext){if(MapAppLoader.onReady!=null){MapAppLoader.onReady(appContext);}};MapAppLoader.prototype.getScriptLocation=function(){var scriptLocation="";var scriptName="MapAppLoader.js";var scripts=document.getElementsByTagName("script");for(var i=0;i<scripts.length;i++){var src=scripts[i].getAttribute("src");if(src){var index=src.lastIndexOf(scriptName);var pathLength=src.lastIndexOf("?");if(pathLength<0){pathLength=src.length;}
if((index>-1)&&(index+scriptName.length==pathLength)){scriptLocation=src.slice(0,pathLength-scriptName.length);break;}}}
return scriptLocation;};MapAppLoader.prototype.getAPI=function(){if(this._api==null){this._api=new HSLayers.Apps.MapAppAPI(this.app);}
return this._api;};MapAppLoader.prototype.getApp=function(){return this.app;};MapAppLoader.prototype.loadCss=function(filename){var fileref=document.createElement("link");fileref.setAttribute("rel","stylesheet");fileref.setAttribute("type","text/css");fileref.setAttribute("href",filename);this.appendToDom(fileref);};MapAppLoader.prototype.loadFiles=function(){var relpath=this.getScriptLocation();if((MapAppLoader._uiLibrary=="ExtJS")&&(MapAppLoader._dynamicExtJs)){this.loadCss(relpath+"../../../ext/ext-"+MapAppLoader._extJsVersion+"/resources/css/ext-all.css");if(MapAppLoader._theme!=""){this.loadCss(relpath+"../../../ext/ext-"+MapAppLoader._extJsVersion+"/resources/css/"+MapAppLoader._theme+".css");}}
this.loadCss(relpath+"../theme/default/style.css");this.loadCss(relpath+"../theme/default/HSApps.css");this.loadJs(relpath+"../HS.js");if(MapAppLoader._uiLibrary=="ExtJS"){if(MapAppLoader._debug){this.loadJs(relpath+"../HSOpenLayers-apps-debug.js");}else{this.loadJs(relpath+"../HSOpenLayers-apps.js");}}else{if(MapAppLoader._debug){this.loadJs(relpath+"../HSOpenLayers-apps-core-debug.js");}else{this.loadJs(relpath+"../HSOpenLayers-apps-core.js");}}};MapAppLoader.prototype.loadJs=function(filename){var fileref=document.createElement("script");fileref.setAttribute("type","text/javascript");fileref.setAttribute("src",filename);this.appendToDom(fileref);};MapAppLoader.prototype.loadProject=function(){if((this.options.proxy!=null)&&(this.options.proxy!="")){OpenLayers.ProxyHost=this.options.proxy;}
var url=this.url+"&project="+this.project;OpenLayers.loadURL(url,null,this,this.afterLoadProject);};MapAppLoader.prototype.processLayerSwitcherClassName=function(className){if(className==="Glog.LsaLayerParser"){className="HSLayers.Apps.LsaLayerParser";}
if(className==="Glog.LsaHSLayerSwitcher"){className="HSLayers.Apps.LsaHSLayerSwitcher";}
if(className==="Glog.LsaHSBoxLayerSwitcher"){className="HSLayers.Apps.LsaHSBoxLayerSwitcher";}
return className;};MapAppLoader._instance=new MapAppLoader();MapAppLoader._app=null;MapAppLoader._debug=false;MapAppLoader._docLoaded=false;MapAppLoader._dynamicExtJs=true;MapAppLoader._firstRun=true;MapAppLoader._hsLayersVersion="trunk";MapAppLoader._scriptLoaded=false;MapAppLoader._theme="";MapAppLoader._uiLibrary="ExtJS";MapAppLoader._extJsVersion="2.0.2";MapAppLoader.afterDocLoaded=function(){MapAppLoader._docLoaded=true;if((MapAppLoader._scriptLoaded)&&(MapAppLoader._firstRun)){MapAppLoader._doOnStartApplication();}}
MapAppLoader._afterScriptLoaded=function(){MapAppLoader._scriptLoaded=true;if((MapAppLoader._docLoaded)&&(MapAppLoader._firstRun)){MapAppLoader._doOnStartApplication();}}
MapAppLoader.appendLoadingDiv=function(message){var divText=document.createElement("div");divText.setAttribute("class","loader_text");divText.innerHTML=message;var divImg=document.createElement("div");divImg.setAttribute("class","loader_img");var div=document.createElement("div");div.setAttribute("id","__loader__");div.setAttribute("class","loader");div.appendChild(divImg);div.appendChild(divText);document.getElementsByTagName("body")[0].appendChild(div);};MapAppLoader._doOnStartApplication=function(){if(MapAppLoader.onStartApplication!=null){MapAppLoader.onStartApplication();}};MapAppLoader.getInstance=function(){return MapAppLoader._instance;};MapAppLoader.initApplication=function(app){MapAppLoader._app=app;};MapAppLoader.initGlogProject=function(url,project,options){MapAppLoader.initProject(url,project,options);}
MapAppLoader.initProject=function(url,project,options){var instance=new MapAppLoader();instance.app=MapAppLoader._app;instance.url=url;instance.project=project;instance.options=options;MapAppLoader._instance=instance;MapAppLoader.waitForInit(instance);return instance;}
MapAppLoader._initLoadOptions=function(options){if(options!=null){if(options.theme!=null){MapAppLoader._theme=options.theme;}
if(options.hsLayersVersion!=null){MapAppLoader._hsLayersVersion=options.hsLayersVersion;}
if(options.debug){MapAppLoader._debug=options.debug;}
if(options.uiLibrary!=null){MapAppLoader._uiLibrary=options.uiLibrary;}
if(options.dynamicExtJs!=null){MapAppLoader._dynamicExtJs=options.dynamicExtJs;}}};MapAppLoader.load=function(options){MapAppLoader._initLoadOptions(options);MapAppLoader._instance.loadFiles();MapAppLoader._loadAdditionalScripts(MapAppLoader._instance,options);MapAppLoader._loadAdditionalStyles(MapAppLoader._instance,options);};MapAppLoader._loadAdditionalScripts=function(mapAppLoader,options){if(MapAppLoader.isReady(mapAppLoader)){if(options!=null){if(options.debug){HSLayers.Apps.Debug.logLevel=HSLayers.Apps.Debug.LOG_LEVEL_DEBUG;}}
if(options!=null){if((options.proxy!=null)&&(options.proxy!="")){OpenLayers.ProxyHost=options.proxy;}
if(options.scripts!=null){for(var i=0;i<options.scripts.length;i++){var scriptUrl=options.scripts[i];if(HSLayers.Apps.Debug.logLevel==HSLayers.Apps.Debug.LOG_LEVEL_DEBUG){scriptUrl=HSLayers.Apps.Utility.saltURL(scriptUrl);}
var code=HSLayers.Apps.Utility.loadURLSync(scriptUrl);eval(code);}}}
MapAppLoader._afterScriptLoaded();}else{window.setTimeout(function(){MapAppLoader._loadAdditionalScripts.call(this,mapAppLoader,options);},200);}}
MapAppLoader._loadAdditionalStyles=function(mapAppLoader,options){if(options!=null){if(options.styles!=null){for(var i=0;i<options.styles.length;i++){var styleUrl=options.styles[i];mapAppLoader.loadCss(styleUrl);}}}}
MapAppLoader.isReady=function(mapAppLoader){var ready=false;if(MapAppLoader._uiLibrary=="ExtJS"){ready=MapAppLoader.isReadyExt(mapAppLoader);}else{ready=MapAppLoader.isReadyCore(mapAppLoader);}
return ready;}
MapAppLoader.isReadyCore=function(mapAppLoader){var ready=false;if(window.HSLayers!=null){if(window.HSLayers.Apps!=null){ready=true;}}
return ready;}
MapAppLoader.isReadyExt=function(mapAppLoader){var ready=false;if(window.Ext!=null){if(window.Ext.isReady){if(window.HSLayers!=null){if(window.HSLayers.Apps!=null){ready=true;}}}}
return ready;}
MapAppLoader.removeLoadingDiv=function(){var div=document.getElementById("__loader__");document.getElementsByTagName("body")[0].removeChild(div);};MapAppLoader.waitForInit=function(mapAppLoader){if(MapAppLoader.isReady(mapAppLoader)){mapAppLoader.loadProject();}else{window.setTimeout(function(){MapAppLoader.waitForInit.call(this,mapAppLoader);},200);}};
