
/* js loader inspired by google, written by jeremy yunis */

				if( !embtv ) {
					var embtv = {};
				}

				(function() {

					var debug = false;

					function setDebug(boolDebug) {
						debug = boolDebug;
					}

					function getDebug() {
						return debug;
					}

					var embtvJsapiBaseUrl = 'http://photos.kxly.com/jsapi/jservice_base.php';

					function rand() {
						return ( Math.round( Math.random()*1000 ) ) + 1;
					}

					function ModuleType(str){
                                                this.modtype=str;
                                        }

                                        ModuleType.prototype.getJsFileUrl=function(version,opts) {
                                                var strQuery="&rand="+rand();
						if(opts) {
							strQuery += opts;
						}
                                                return embtvJsapiBaseUrl+"?js="+this.modtype+"&v="+version+strQuery;
                                        };

					function loadJavascriptModule(modType,version,opts) {
						var module = availableModules[":"+modType];
						if(!module){
							var e=new Error("Module: '"+modType+"' not found!");
							e.toString=function(){
								return this.message;
							};
							throw e;
						} else {
							writeLoadTag("script",module.getJsFileUrl(version,opts));
						}
					}
					function loadJSONModule(modType,version,opts) {
						var module = availableModules[":"+modType];
						if(!module){
							var e=new Error("Module: '"+modType+"' not found!");
							e.toString=function(){
								return this.message;
							};
							throw e;
						} else {
							var jsReq = new JSONscriptRequest(module.getJsFileUrl(version, opts));
							jsReq.buildScriptTag();
							jsReq.addScriptTag();
						}
					}
					function setOnLoadCallback(onLoadFunction) {
						var a=window;
						if(a.addEventListener){
							// moz/ff
							a.addEventListener("load",onLoadFunction,false);
						}else if(a.attachEvent){
							// ie
							a.attachEvent("onload",onLoadFunction);
						}else{
							a["onload"]=onLoadFunction;
						}
					}
					function writeLoadTag(type,url){
						if(type=="script"){
							document.write('<script src="'+url+'" type="text/javascript"><\/script>');
						}else if(type=="css"){
							document.write('<link href="'+url+'" type="text/css" rel="stylesheet"></link>')
						}
					}
					function exportFunction(c,a){
						var b=c.split(/\./);
						var d=window;
						for(var e=0;e<b.length-1;e++){
							d=d[b[e]];
						}
						d[b[b.length-1]]=a;
					}
					
					function JSONscriptRequest(fullUrl) {
						this.fullUrl = fullUrl;
						if(debug) {
							alert(this.fullUrl);
						}
						this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
						this.headLoc = document.getElementsByTagName("head").item(0);
						this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
					}

					JSONscriptRequest.scriptCounter = 1;

					JSONscriptRequest.prototype.buildScriptTag = function () {
						this.scriptObj = document.createElement("script");
						this.scriptObj.setAttribute("type", "text/javascript");
						this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
						this.scriptObj.setAttribute("id", this.scriptId);
					}

					JSONscriptRequest.prototype.removeScriptTag = function () {
						this.headLoc.removeChild(this.scriptObj);
					}

					JSONscriptRequest.prototype.addScriptTag = function () {
						this.headLoc.appendChild(this.scriptObj);
					}

					var availableModules = {};
					availableModules[":slideshow"] = new ModuleType("slideshow");
					availableModules[":slideshow_widget"] = new ModuleType("slideshow_widget");

					exportFunction("embtv.load",loadJavascriptModule);
					exportFunction("embtv.loadJSON",loadJSONModule);
					exportFunction("embtv.setOnLoadCallback",setOnLoadCallback);
					exportFunction("embtv.writeLoadTag",writeLoadTag);
					exportFunction("embtv.exportFunction",exportFunction);
					exportFunction("embtv.setDebug",setDebug);
					exportFunction("embtv.getDebug",getDebug);
//					exportFunction("embtv_export",exportFunction);
				})();
