var gadgets=gadgets||{};gadgets.error={};gadgets.error.SUBCLASS_RESPONSIBILITY="subclass responsibility";gadgets.error.TO_BE_DONE="to be done";gadgets.log=function(a){if(window.console&&console.log){console.log(a)}else{var b=document.createElement("div");b.className="gadgets-log-entry";b.innerHTML=a;document.body.appendChild(b)}};gadgets.callAsyncAndJoin=function(e,a,d){var f=e.length;var c=[];for(var b=0;b<e.length;b++){var g=function(h){e[h].call(d,function(i){c[h]=i;if(--f===0){a(c)}})};g(b)}};gadgets.Extensible=function(){};gadgets.Extensible.prototype.setDependencies=function(a){for(var b in a){this[b]=a[b]}};gadgets.Extensible.prototype.getDependencies=function(a){return this[a]};gadgets.UserPrefStore=function(){};gadgets.UserPrefStore.prototype.getPrefs=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.UserPrefStore.prototype.savePrefs=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.DefaultUserPrefStore=function(){gadgets.UserPrefStore.call(this)};gadgets.DefaultUserPrefStore.inherits(gadgets.UserPrefStore);gadgets.DefaultUserPrefStore.prototype.getPrefs=function(a){};gadgets.DefaultUserPrefStore.prototype.savePrefs=function(a){};gadgets.GadgetService=function(){};gadgets.GadgetService.prototype.setHeight=function(b,a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.GadgetService.prototype.setTitle=function(a,b){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.GadgetService.prototype.setUserPref=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.IfrGadgetService=function(){gadgets.GadgetService.call(this);gadgets.rpc.register("resize_iframe",this.setHeight);gadgets.rpc.register("set_pref",this.setUserPref);gadgets.rpc.register("set_title",this.setTitle);gadgets.rpc.register("requestNavigateTo",this.requestNavigateTo)};gadgets.IfrGadgetService.inherits(gadgets.GadgetService);gadgets.IfrGadgetService.prototype.setHeight=function(a){if(a>gadgets.container.maxheight_){a=gadgets.container.maxheight_}var b=document.getElementById(this.f);if(b){b.style.height=a+"px"}};gadgets.IfrGadgetService.prototype.setTitle=function(b){var a=document.getElementById(this.f+"_title");if(a){a.innerHTML=b.replace(/&/g,"&amp;").replace(/</g,"&lt;")}};gadgets.IfrGadgetService.prototype.setUserPref=function(h,c,e){var g=this.getGadgetIdFromModuleId(this.f);var f=gadgets.container.getGadget(g);var b=f.getUserPrefs();for(var d=1,a=arguments.length;d<a;d+=2){b[arguments[d]]=arguments[d+1]}f.setUserPrefs(b)};gadgets.IfrGadgetService.prototype.requestNavigateTo=function(a,d){var e=this.getGadgetIdFromModuleId(this.f);var b=this.getUrlForView(a);if(d){var c=gadgets.json.stringify(d);if(c.length>0){b+="&appParams="+encodeURIComponent(c)}}if(b&&document.location.href.indexOf(b)==-1){document.location.href=b}};gadgets.IfrGadgetService.prototype.getUrlForView=function(a){if(a==="canvas"){return"/canvas"}else{if(a==="profile"){return"/profile"}else{return null}}};gadgets.IfrGadgetService.prototype.getGadgetIdFromModuleId=function(a){return parseInt(a.match(/_([0-9]+)$/)[1],10)};gadgets.LayoutManager=function(){};gadgets.LayoutManager.prototype.getGadgetChrome=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.StaticLayoutManager=function(){gadgets.LayoutManager.call(this)};gadgets.StaticLayoutManager.inherits(gadgets.LayoutManager);gadgets.StaticLayoutManager.prototype.setGadgetChromeIds=function(a){this.gadgetChromeIds_=a};gadgets.StaticLayoutManager.prototype.getGadgetChrome=function(b){var a=this.gadgetChromeIds_[b.id];return a?document.getElementById(a):null};gadgets.FloatLeftLayoutManager=function(a){gadgets.LayoutManager.call(this);this.layoutRootId_=a};gadgets.FloatLeftLayoutManager.inherits(gadgets.LayoutManager);gadgets.FloatLeftLayoutManager.prototype.getGadgetChrome=function(c){var b=document.getElementById(this.layoutRootId_);if(b){var a=document.createElement("div");a.className="gadgets-gadget-chrome";a.style.cssFloat="left";b.appendChild(a);return a}else{return null}};gadgets.Gadget=function(b){this.userPrefs_={};if(b){for(var a in b){if(b.hasOwnProperty(a)){this[a]=b[a]}}}if(!this.secureToken){this.secureToken="john.doe:john.doe:appid:cont:url:0"}};gadgets.Gadget.prototype.getUserPrefs=function(){return this.userPrefs_};gadgets.Gadget.prototype.setUserPrefs=function(a){this.userPrefs_=a;gadgets.container.userPrefStore.savePrefs(this)};gadgets.Gadget.prototype.getUserPref=function(a){return this.userPrefs_[a]};gadgets.Gadget.prototype.setUserPref=function(a,b){this.userPrefs_[a]=b;gadgets.container.userPrefStore.savePrefs(this)};gadgets.Gadget.prototype.render=function(a){if(a){this.getContent(function(b){a.innerHTML=b})}};gadgets.Gadget.prototype.getContent=function(a){gadgets.callAsyncAndJoin([this.getTitleBarContent,this.getUserPrefsDialogContent,this.getMainContent],function(b){a(b.join(""))},this)};gadgets.Gadget.prototype.getTitleBarContent=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.Gadget.prototype.getUserPrefsDialogContent=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.Gadget.prototype.getMainContent=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.Gadget.prototype.getAdditionalParams=function(){return""};gadgets.IfrGadget=function(a){gadgets.Gadget.call(this,a);this.serverBase_="../../"};gadgets.IfrGadget.inherits(gadgets.Gadget);gadgets.IfrGadget.prototype.GADGET_IFRAME_PREFIX_="remote_iframe_";gadgets.IfrGadget.prototype.CONTAINER="default";gadgets.IfrGadget.prototype.cssClassGadget="gadgets-gadget";gadgets.IfrGadget.prototype.cssClassTitleBar="gadgets-gadget-title-bar";gadgets.IfrGadget.prototype.cssClassTitle="gadgets-gadget-title";gadgets.IfrGadget.prototype.cssClassTitleButtonBar="gadgets-gadget-title-button-bar";gadgets.IfrGadget.prototype.cssClassGadgetUserPrefsDialog="gadgets-gadget-user-prefs-dialog";gadgets.IfrGadget.prototype.cssClassGadgetUserPrefsDialogActionBar="gadgets-gadget-user-prefs-dialog-action-bar";gadgets.IfrGadget.prototype.cssClassTitleButton="gadgets-gadget-title-button";gadgets.IfrGadget.prototype.cssClassGadgetContent="gadgets-gadget-content";gadgets.IfrGadget.prototype.rpcToken=(2147483647*Math.random())|0;gadgets.IfrGadget.prototype.rpcRelay="files/container/rpc_relay.html";gadgets.IfrGadget.prototype.getTitleBarContent=function(a){a('<div id="'+this.cssClassTitleBar+"-"+this.id+'" class="'+this.cssClassTitleBar+'"><span id="'+this.getIframeId()+'_title" class="'+this.cssClassTitle+'">'+(this.title?this.title:"Title")+'</span> | <span class="'+this.cssClassTitleButtonBar+'"><a href="#" onclick="gadgets.container.getGadget('+this.id+').handleOpenUserPrefsDialog();return false;" class="'+this.cssClassTitleButton+'">settings</a> <a href="#" onclick="gadgets.container.getGadget('+this.id+').handleToggle();return false;" class="'+this.cssClassTitleButton+'">toggle</a></span></div>')};gadgets.IfrGadget.prototype.getUserPrefsDialogContent=function(a){a('<div id="'+this.getUserPrefsDialogId()+'" class="'+this.cssClassGadgetUserPrefsDialog+'"></div>')};gadgets.IfrGadget.prototype.setServerBase=function(a){this.serverBase_=a};gadgets.IfrGadget.prototype.getServerBase=function(){return this.serverBase_};gadgets.IfrGadget.prototype.getMainContent=function(a){var c=this.getIframeId();gadgets.rpc.setRelayUrl(c,this.serverBase_+this.rpcRelay);gadgets.rpc.setAuthToken(c,this.rpcToken);var b=(this.scrolling?"auto":"no");a('<div class="'+this.cssClassGadgetContent+'"><iframe allowTransparency="true" id="'+c+'" name="'+c+'" class="'+this.cssClassGadget+'" src="'+this.getIframeUrl()+'" frameborder="no" scrolling="'+b+'"'+(this.height?' height="'+this.height+'"':"")+(this.width?' width="'+this.width+'"':"")+"></iframe></div>")};gadgets.IfrGadget.prototype.getIframeId=function(){return this.GADGET_IFRAME_PREFIX_+this.id};gadgets.IfrGadget.prototype.getUserPrefsDialogId=function(){return this.getIframeId()+"_userPrefsDialog"};gadgets.IfrGadget.prototype.getIframeUrl=function(){return this.serverBase_+"ifr?container="+this.CONTAINER+"&mid="+this.id+"&nocache="+gadgets.container.nocache_+"&country="+gadgets.container.country_+"&lang="+gadgets.container.language_+"&view="+gadgets.container.view_+(this.specVersion?"&v="+this.specVersion:"")+(gadgets.container.parentUrl_?"&parent="+encodeURIComponent(gadgets.container.parentUrl_):"")+(this.debug?"&debug=1":"")+this.getAdditionalParams()+this.getUserPrefsParams()+(this.secureToken?"&st="+this.secureToken:"")+"&url="+encodeURIComponent(this.specUrl)+"#rpctoken="+this.rpcToken+(this.viewParams?"&view-params="+encodeURIComponent(gadgets.json.stringify(this.viewParams)):"")+(this.hashData?"&"+this.hashData:"")};gadgets.IfrGadget.prototype.getUserPrefsParams=function(){var c="";if(this.getUserPrefs()){for(var a in this.getUserPrefs()){var b=this.getUserPref(a);c+="&up_"+encodeURIComponent(a)+"="+encodeURIComponent(b)}}return c};gadgets.IfrGadget.prototype.handleToggle=function(){var b=document.getElementById(this.getIframeId());if(b){var a=b.parentNode;var c=a.style.display;a.style.display=c?"":"none"}};gadgets.IfrGadget.prototype.handleOpenUserPrefsDialog=function(){if(this.userPrefsDialogContentLoaded){this.showUserPrefsDialog()}else{var c=this;var b="ig_callback_"+this.id;window[b]=function(d){c.userPrefsDialogContentLoaded=true;c.buildUserPrefsDialog(d);c.showUserPrefsDialog()};var a=document.createElement("script");a.src="http://gmodules.com/ig/gadgetsettings?mid="+this.id+"&output=js"+this.getUserPrefsParams()+"&url="+this.specUrl;document.body.appendChild(a)}};gadgets.IfrGadget.prototype.buildUserPrefsDialog=function(a){var b=document.getElementById(this.getUserPrefsDialogId());b.innerHTML=a+'<div class="'+this.cssClassGadgetUserPrefsDialogActionBar+'"><input type="button" value="Save" onclick="gadgets.container.getGadget('+this.id+').handleSaveUserPrefs()"> <input type="button" value="Cancel" onclick="gadgets.container.getGadget('+this.id+').handleCancelUserPrefs()"></div>';b.childNodes[0].style.display=""};gadgets.IfrGadget.prototype.showUserPrefsDialog=function(a){var b=document.getElementById(this.getUserPrefsDialogId());b.style.display=(a||a==undefined)?"":"none"};gadgets.IfrGadget.prototype.hideUserPrefsDialog=function(){this.showUserPrefsDialog(false)};gadgets.IfrGadget.prototype.handleSaveUserPrefs=function(){this.hideUserPrefsDialog();var d={};var a=document.getElementById("m_"+this.id+"_numfields").value;for(var e=0;e<a;e++){var b=document.getElementById("m_"+this.id+"_"+e);if(b.type!="hidden"){var g="m_"+this.id+"_up_";var c=b.name.substring(g.length);var f=b.value;d[c]=f}}this.setUserPrefs(d);this.refresh()};gadgets.IfrGadget.prototype.handleCancelUserPrefs=function(){this.hideUserPrefsDialog()};gadgets.IfrGadget.prototype.refresh=function(){var a=this.getIframeId();document.getElementById(a).src=this.getIframeUrl()};gadgets.Container=function(){this.gadgets_={};this.parentUrl_="http://"+document.location.host;this.country_="ALL";this.language_="ALL";this.view_="home";this.nocache_=1;this.maxheight_=2147483647};gadgets.Container.inherits(gadgets.Extensible);gadgets.Container.prototype.gadgetClass=gadgets.Gadget;gadgets.Container.prototype.userPrefStore=new gadgets.DefaultUserPrefStore();gadgets.Container.prototype.gadgetService=new gadgets.GadgetService();gadgets.Container.prototype.layoutManager=new gadgets.StaticLayoutManager();gadgets.Container.prototype.setParentUrl=function(a){this.parentUrl_=a};gadgets.Container.prototype.setCountry=function(a){this.country_=a};gadgets.Container.prototype.setNoCache=function(a){this.nocache_=a};gadgets.Container.prototype.setLanguage=function(a){this.language_=a};gadgets.Container.prototype.setView=function(a){this.view_=a};gadgets.Container.prototype.setMaxHeight=function(a){this.maxheight_=a};gadgets.Container.prototype.getGadgetKey_=function(a){return"gadget_"+a};gadgets.Container.prototype.getGadget=function(a){return this.gadgets_[this.getGadgetKey_(a)]};gadgets.Container.prototype.createGadget=function(a){return new this.gadgetClass(a)};gadgets.Container.prototype.addGadget=function(a){a.id=this.getNextGadgetInstanceId();a.setUserPrefs(this.userPrefStore.getPrefs(a));this.gadgets_[this.getGadgetKey_(a.id)]=a};gadgets.Container.prototype.addGadgets=function(a){for(var b=0;b<a.length;b++){this.addGadget(a[b])}};gadgets.Container.prototype.renderGadgets=function(){for(var a in this.gadgets_){this.renderGadget(this.gadgets_[a])}};gadgets.Container.prototype.renderGadget=function(a){throw Error(gadgets.error.SUBCLASS_RESPONSIBILITY)};gadgets.Container.prototype.nextGadgetInstanceId_=0;gadgets.Container.prototype.getNextGadgetInstanceId=function(){return this.nextGadgetInstanceId_++};gadgets.Container.prototype.refreshGadgets=function(){for(var a in this.gadgets_){this.gadgets_[a].refresh()}};gadgets.IfrContainer=function(){gadgets.Container.call(this)};gadgets.IfrContainer.inherits(gadgets.Container);gadgets.IfrContainer.prototype.gadgetClass=gadgets.IfrGadget;gadgets.IfrContainer.prototype.gadgetService=new gadgets.IfrGadgetService();gadgets.IfrContainer.prototype.setParentUrl=function(a){if(!a.match(/^http[s]?:\/\//)){a=document.location.href.match(/^[^?#]+\//)[0]+a}this.parentUrl_=a};gadgets.IfrContainer.prototype.renderGadget=function(b){var a=this.layoutManager.getGadgetChrome(b);b.render(a)};gadgets.container=new gadgets.IfrContainer();