Type.registerNamespace("MySpace");Type.registerNamespace("MySpace.UI");function getFirstChildByClassName(A,E){if(A.childNodes.length==0){return null}var B=new RegExp("(^|\\s)"+E+"(\\s|$)");for(var D=0;D<A.childNodes.length;D++){var F=A.childNodes[D];if(B.test(F.className)){return F}var C=getFirstChildByClassName(F,E);if(C!=null){return C}}return null}MySpace.UI.AppChrome=function(A){MySpace.UI.AppChrome.initializeBase(this,[A])};MySpace.UI.AppChrome.remoteRequest=function(A){MySpace.Apps.JSONP.request("MySpace.UI.AppChrome.profileLoad",A+"&ownerid="+MySpace.ClientContext.DisplayFriendId,function(){},30000)};MySpace.UI.AppChrome.load=function(N,H,B,L){H.style.display="none";var A=L.replace(".","");var J=A;if(J.indexOf("profile")>-1){J="profile"}var E=MySpace.Apps.JSONP.getContext(A+"MaxTitleWidth");for(var I=B.length-1;I>=0;I--){var D=B[I];if(D.title.length>E){D.title=D.title.substr(0,E-3)+"..."}var K=N.replace(/\{appid\}/g,D.id.toString());K=K.replace(/\{title\}/g,D.title);K=K.replace(/\{titleurl\}/g,D.profileUrl);var F=document.createElement("div");F.innerHTML=K;var M=getFirstChildByClassName(F,"appcontent");M.innerHTML=MySpace.MDP.Apps.generateAppMarkup(D,L);for(var G=F.childNodes.length-1;G>=0;G--){H.parentNode.insertBefore(F.childNodes[G],H.nextSibling)}var C=D.id.toString()}for(var I=0;I<B.length;I++){var D=B[I];var C=D.id.toString();$create(MySpace.UI.AppChrome,{appId:D.id,headerElement:$get("appchromeheader_"+C),panelElement:$get("apppanel_"+C+"_"+J),surfaceId:L,osToken:D.osToken},null,null,$get("appchrome_"+C))}};MySpace.UI.AppChrome.loadLeft=function(A){MySpace.UI.AppChrome.load(MySpace.Apps.JSONP.getContext("profileleftTemplate"),$get("profileleftApps"),A,"profile.left")};MySpace.UI.AppChrome.loadRight=function(A){MySpace.UI.AppChrome.load(MySpace.Apps.JSONP.getContext("profilerightTemplate"),$get("profilerightApps"),A,"profile.right")};MySpace.UI.AppChrome.profileLoad=function(C){if(!C){return}var D=[];var A=[];for(var B=0;B<C.length;B++){var E=C[B];if(E.hasOwnProperty("panelType")){if(E.panelType.toLowerCase()=="opensocial"&&E.hasOwnProperty("iframeUrl")){if(E.iframeUrl.indexOf("surface=profile.left")>-1){D.push(E)}else{if(E.iframeUrl.indexOf("surface=profile.right")>-1){A.push(E)}}}else{if(E.panelType.toLowerCase()=="flash"&&E.hasOwnProperty("flashVars")){if(E.flashVars.indexOf("surface=profile.left")>-1){D.push(E)}else{if(E.flashVars.indexOf("surface=profile.right")>-1){A.push(E)}}}}}}MySpace.UI.AppChrome.loadLeft(D);MySpace.UI.AppChrome.loadRight(A)};MySpace.UI.AppChrome._panelList={};MySpace.UI.AppChrome.createButton=function(B){var A=document.createElement("div");A.style.display="none";A.style.cssFloat=A.style.styleFloat="right";A.style.cursor="pointer";A.style.paddingLeft="3px";A.style.paddingRight="3px";A.className="whitetext12";A.innerHTML=B;return A};MySpace.UI.AppChrome.prototype={_minElement:null,_xElement:null,_upElement:null,_downElement:null,_reportElement:null,_headerElement:null,_panelElement:null,_minimized:false,_originalHeight:0,_originalStyleHeight:0,_appId:null,_surfaceId:null,_orderIndex:-1,_rootElement:null,_appName:"",_osToken:"",get_appId:function(){return this._appId},set_appId:function(A){this._appId=A},get_headerElement:function(){return this._headerElement},set_headerElement:function(A){this._headerElement=A},get_panelElement:function(){return this._panelElement},set_panelElement:function(A){this._panelElement=A},get_surfaceId:function(){return this._surfaceId},set_surfaceId:function(A){this._surfaceId=A},get_appName:function(){return this._appName},set_appName:function(A){this._appName=A},get_osToken:function(){return this._osToken},set_osToken:function(A){this._osToken=A},initialize:function(){if(this._panelElement==null||this._headerElement==null){return}MySpace.UI.AppChrome.callBaseMethod(this,"initialize");var F=false;if(MySpace.ClientContext.IsLoggedIn){if(MySpace.ClientContext.UserId==MySpace.ClientContext.DisplayFriendId){F=true;var B=MySpace.UI.AppChrome.createButton("");this.createAppIcon(B,4,"uninstall");$addHandler(B,"click",Function.createDelegate(this,this.uninstallClick));this._headerElement.appendChild(B);this._xElement=B}else{var D=MySpace.UI.AppChrome.createButton("");this.createAppIcon(D,5,"report");$addHandler(D,"click",Function.createDelegate(this,this.reportClick));this._headerElement.appendChild(D);this._reportElement=D}}var E=MySpace.UI.AppChrome.createButton("");this.createAppIcon(E,2,"min");$addHandler(E,"click",Function.createDelegate(this,this.minimizeClick));this._headerElement.appendChild(E);this._minElement=E;if(F){var A=MySpace.UI.AppChrome.createButton("");this.createAppIcon(A,0,"up");$addHandler(A,"click",Function.createDelegate(this,this.upClick));this._headerElement.appendChild(A);this._upElement=A;var C=MySpace.UI.AppChrome.createButton("");this.createAppIcon(C,1,"down");$addHandler(C,"click",Function.createDelegate(this,this.downClick));this._headerElement.appendChild(C);this._downElement=C}this._originalHeight=this._panelElement.height;this._originalStyleHeight=this._panelElement.style.height;$addHandler(this._element,"mouseover",Function.createDelegate(this,this.mouseOver));$addHandler(this._element,"mouseout",Function.createDelegate(this,this.mouseOut));if(this._surfaceId!=null){if(!MySpace.UI.AppChrome._panelList.hasOwnProperty(this._surfaceId)){MySpace.UI.AppChrome._panelList[this._surfaceId]=new Array()}this._orderIndex=MySpace.UI.AppChrome._panelList[this._surfaceId].length;MySpace.UI.AppChrome._panelList[this._surfaceId].push(this);this._rootElement=this._headerElement.parentNode.parentNode.parentNode}},dispose:function(){this._minElement=null;this._xElement=null;this._headerElement=null;this._panelElement=null;MySpace.UI.AppChrome.callBaseMethod(this,"dispose")},mouseOver:function(){if(this._xElement!=null){this._xElement.style.display="inline"}if(this._upElement!=null){this._upElement.style.display="inline"}if(this._downElement!=null){this._downElement.style.display="inline"}if(this._reportElement!=null){this._reportElement.style.display="inline"}this._minElement.style.display="inline"},mouseOut:function(){if(this._xElement!=null){this._xElement.style.display="none"}if(this._upElement!=null){this._upElement.style.display="none"}if(this._downElement!=null){this._downElement.style.display="none"}if(this._reportElement!=null){this._reportElement.style.display="none"}this._minElement.style.display="none"},createAppIcon:function(C,E,B){var A=document.createElement("div");A.id=B+this._appId.toString();var F=17;A.style.overflow="hidden";A.style.width=(F-1)+"px";A.style.height="14px";var D=document.createElement("img");D.src=AppChrome_ControlBoxSrc;D.style.marginLeft="-"+(E*F)+"px";A.appendChild(D);C.appendChild(A)},upClick:function(){if(this._orderIndex>0&&MySpace.UI.AppChrome._panelList[this._surfaceId].length>1){var A=MySpace.UI.AppChrome._panelList[this._surfaceId][this._orderIndex-1];if(this._rootElement.nextSibling.tagName.toLowerCase()=="br"){this._rootElement.parentNode.removeChild(this._rootElement.nextSibling)}this._rootElement.parentNode.removeChild(this._rootElement);A._rootElement.parentNode.insertBefore(this._rootElement,A._rootElement);A._rootElement.parentNode.insertBefore(document.createElement("br"),A._rootElement);MySpace.UI.AppChrome._panelList[this._surfaceId][A._orderIndex]=this;MySpace.UI.AppChrome._panelList[this._surfaceId][this._orderIndex]=A;MySpace.Web.Services.Apps.Apps.MoveAppUp(this._osToken,this.get_surfaceId(),function(C,D){},function(C,D){});var B=this._orderIndex;this._orderIndex=A._orderIndex;A._orderIndex=B;this.mouseOut()}},downClick:function(){if(this._orderIndex<MySpace.UI.AppChrome._panelList[this._surfaceId].length-1&&MySpace.UI.AppChrome._panelList[this._surfaceId].length>1){var B=MySpace.UI.AppChrome._panelList[this._surfaceId][this._orderIndex+1];if(B._rootElement.nextSibling.tagName.toLowerCase()=="br"){B._rootElement.parentNode.removeChild(B._rootElement.nextSibling)}B._rootElement.parentNode.removeChild(B._rootElement);this._rootElement.parentNode.insertBefore(B._rootElement,this._rootElement);this._rootElement.parentNode.insertBefore(document.createElement("br"),this._rootElement);MySpace.UI.AppChrome._panelList[this._surfaceId][B._orderIndex]=this;MySpace.UI.AppChrome._panelList[this._surfaceId][this._orderIndex]=B;MySpace.Web.Services.Apps.Apps.MoveAppDown(this._osToken,this.get_surfaceId(),function(C,D){},function(C,D){});var A=this._orderIndex;this._orderIndex=B._orderIndex;B._orderIndex=A;this.mouseOut()}},reportClick:function(){window.location=AppChrome_ReportAppLink.replace("{0}",this._appId.toString())},minimizeClick:function(){if(this._minimized){this._panelElement.height=this._originalHeight;this._panelElement.style.height=this._originalStyleHeight;if(Sys.Browser.agent==Sys.Browser.Firefox){this._panelElement.parentNode.style.borderWidth="1px"}while(this._minElement.childNodes.length>=1){this._minElement.removeChild(this._minElement.firstChild)}this.createAppIcon(this._minElement,2,"min");this._minimized=false}else{this._originalHeight=this._panelElement.height;this._originalStyleHeight=this._panelElement.style.height;this._panelElement.style.height=0;if(Sys.Browser.agent==Sys.Browser.Firefox){this._panelElement.parentNode.style.borderWidth="0 1px 0 1px"}while(this._minElement.childNodes.length>=1){this._minElement.removeChild(this._minElement.firstChild)}this.createAppIcon(this._minElement,3,"min");this._minimized=true}},uninstallClick:function(){var B=new Sys.StringBuilder(MySpaceRes.AppManagement.AppChromeHideContent);var A=Function.createDelegate(this,this.uninstallHandler);var C=MySpace.UI.AppsPopup.create(B.toString(),MySpaceRes.AppManagement.AppChromeHideHeader);C.add_button("Cancel",true).isCancel=true;C.add_button(MySpaceRes.AppManagement.AppChromeHideButton).action="h";C.show(A)},uninstallHandler:function(B,A){if(A.target.isCancel){return}switch(A.target.action){case"h":MySpace.Web.Services.Apps.Apps.UpdateApplicationSettings(this._appId,null,["displayonprofile"],Function.createDelegate(this,function(D){var C=this._element.nextSibling;C.parentNode.removeChild(C);this._element.parentNode.removeChild(this._element)}),Function.createDelegate(this,function(C){alert("Unexpected error hiding the app.")}));break;case"r":MySpace.Apps.uninstallApplication(this._osToken,Function.createDelegate(this,function(){var C=this._element.nextSibling;C.parentNode.removeChild(C);this._element.parentNode.removeChild(this._element)}),Function.createDelegate(this,function(){alert("Unexpected error removing the app.")}));break}}};MySpace.UI.AppChrome.registerClass("MySpace.UI.AppChrome",Sys.UI.Control);if(typeof(Sys)!="undefined"){Sys.Application.notifyScriptLoaded()};
