function canvas_appinstall_performRedirect(D){if(D!=null&&D!=""){var G=window.location.search.match(/appparams=([^&$]*)/i);if(G!=null){var F=gadgets.json_.parse(decodeURIComponent(G[1]))}var E=MySpaceClientContext.UserId;var A=window.location.search.match(/friendid=([^&$]*)/i);if(A!=null){E=parseInt(A[1])}var C="";var B=MySpace.Apps.getFIMAdvParameter();if(B){var C="adv="+B}ifpc_widget_requestNavigateToEx(MySpaceAppProfileContext.appId,E,"canvas",F,null,true,C)}}function canvas_appinstall_failed(A){if(A){alert(A)}}function canvas_uninstallFailedCallback(A){if(A){alert(A)}}function canvas_uninstallSuccessCallback(){location.reload(true)}function canvas_appuninstall(){handler=function(C,B){if(B.target.isCancel){return}MySpace.Apps.uninstallApplicationEx(MySpaceAppProfileContext.token,canvas_uninstallSuccessCallback,canvas_uninstallFailedCallback)};content=MySpaceRes.ProfileDisplay.AppUninstallConfirm;headerContent=MySpaceRes.ProfileDisplay.AppInstallUninstallHeader;buttonContent=MySpaceRes.ProfileDisplay.AppInstallPopupButtonUninstall;var A=MySpace.UI.AppsPopup.create(content,headerContent);A.add_button(buttonContent);A.add_button(MySpaceRes.ProfileDisplay.AppInstallPopupButtonCancel,true).isCancel=true;A.show(handler)}function ifpc_requestInstall(){headerContent=MySpaceRes.ProfileDisplay.AppInstallHeader+MySpaceAppProfileContext.appDisplayName;MySpace.UI.AppsPopup.ajaxAddApp(MySpaceAppProfileContext.appId,headerContent,function(A,C){if(C.target.parentNode.isCancel||C.target.isCancel){return}var B=MySpace.UI.AppsPopup.getSelectedPermissions(A);MySpace.Web.Services.Apps.Apps.InstallApplicationEx(MySpaceAppProfileContext.token,B,"sourceURL="+escape(window.location),function(D){if(D!=undefined){switch(D.status){case 0:if(D.callbackUrl!=null&&D.callbackUrl!=""){MySpace.Apps.executeInstallCallback(D.callbackUrl);setTimeout("canvas_appinstall_performRedirect('"+D.redirectUrl+"');",2*1000)}else{canvas_appinstall_performRedirect(D.redirectUrl)}return;case 1:canvas_appinstall_failed(D.content);return;default:canvas_appinstall_failed(D.content);return}}},function(D){canvas_appinstall_failed(null)})})}function ifpc_requestPreferences(){headerContent=MySpaceRes.AppManagement.UserAppPref_Heading.replace("{0}",MySpaceAppProfileContext.appDisplayName);MySpace.UI.AppsPopup.ajaxPreferences(MySpaceAppProfileContext.appId,headerContent,function(A,B){})}var appinstall_link=$get("apptopnav_appinstall_link");_IFPC.registerService("requestInstall",ifpc_requestInstall);var appsettings_link=$get("apptopnav_appsettings_link");var appuninstall_link=$get("apptopnav_appuninstall_link");(function hookEvts4Subnav(A){A("#msSubnav").click(function(C){var B=A(C.target).closest("li").attr("id");switch(B){case"apptopnav_appinstall_link":ifpc_requestInstall();return false;break;case"apptopnav_appsettings_link":ifpc_requestPreferences();return false;break;case"apptopnav_appuninstall_link":canvas_appuninstall();return false;break;case"menuWrap":PopUpActiveFriends(C);return false;break;default:break}})})(jQuery);var __iframes=document.getElementsByTagName("iframe");if(__iframes.length>0){for(var __iframesIndex=0;__iframesIndex<__iframes.length;__iframesIndex++){var __iframeId=__iframes[__iframesIndex].id;if(typeof __iframeId==="string"&&__iframeId.indexOf("apppanel_")===0){gadgets.rpc.setAuthToken(__iframeId,"0")}}}var UI=new function(){};UI.DropDownList=function(data,dataType,title){var self=this;var dropDownData=data,dropDownDataType=dataType,dropDownTitle=title;self.RenderList=function(elementID){if(dropDownData==""||dropDownData==null){return false}document.getElementById(elementID).innerHTML=getMenu();return true};var getMenu=function(){switch(dropDownDataType){case UI.DropDownList.DataType.JSON:return getMenuFromJSON();break;default:return getMenuFromJSON();break}};var getMenuFromJSON=function(){var temp=eval(dropDownData),menu="";menu+='<a href="javascript:;"><span>'+dropDownTitle+'</span></a><ul id="dropDownMenu" style="display:block;top:22px;left:10px" onmouseout="fixOnMouseOut(this, event, onMenuOut)">';for(var i=0;i<temp.length;i++){menu+="<li "+(temp[i].IsActive?' class="friendIsActive"':"")+'><a href="'+temp[i].ProfileURL+'" onclick="onFriendClick(event, '+temp[i].IsActive+", "+temp[i].FriendId+')"><img src="'+temp[i].ProfileImageURL+'" />&nbsp;'+temp[i].Name+"</a></li>"}menu+="</ul>";return menu}};UI.DropDownList.DataType={JSON:"1"};var MSCustom=new function(){var C=this,B,A,F="/Modules/Applications/Services/";C.getFriendCount=function(I,J){A=J;MySpace.WebRequest.invoke(F+"OnlineFriendsCount.ashx?id="+FIM_advAppId,true,"",Function.createDelegate(this,G),Function.createDelegate(this,H),"getFriendCount",0)};C.getFriendList=function(I,J){B=J;MySpace.WebRequest.invoke(F+"OnlineFriends.ashx?id="+FIM_advAppId+"&to=5&showall=true",true,"",Function.createDelegate(this,G),Function.createDelegate(this,H),"getFriendList",0)};C.renderLoading=function(I,J){document.getElementById(I).innerHTML=J+'<div id="loader">loading...</div>'};C.myInit=function(){var I=document.getElementById("apptopnav_friends_show");if(typeof I!=undefined&&I!=null){I.style.display="inline-block"}};var G=function(J,I){var K=E(I);D(K,J,I,true)};var H=function(J,I){var K=E(I);D(K,J,I,false)};var D=function(L,J,I,K){if(typeof L!=undefined||!L){L(J,I,K)}};var E=function(I){switch(I){case"getFriendCount":return A;break;case"getFriendList":return B;break;default:return null;break}}};$addHandler(window,"load",checkFriends);$addHandler(window,"load",MSCustom.myInit);var totalFriends=0;function is_child_of(A,B){if(B!=null){while(B.parentNode){if((B=B.parentNode)==A){return true}}}return false}function fixOnMouseOut(B,C,D){var A=null;if(C.toElement){A=C.toElement}else{if(C.relatedTarget){A=C.relatedTarget}}if(!is_child_of(B,A)&&B!=A){D()}}function onMenuOut(){$get("menuWrap").innerHTML='<a href="javascript:;"><span>'+getFriendsLabel()+"</span></a>"}function getFriendsLabel(){if(totalFriends<=0){return"Friends"}else{return"Friends ("+totalFriends+")"}}function checkFriends(){MSCustom.getFriendCount(FIM_advAppId,onGetFriendCount)}function PopUpActiveFriends(A){cancelEvent(A);jQuery("#menuWrap").append('<div id="loader" style="top:22px;left:10px;">loading...</div>');MSCustom.getFriendList(FIM_advAppId,onGetFriendList)}function cancelEvent(A){A=A||window.event;if(A.stopPropagation){A.stopPropagation();A.preventDefault()}else{if(typeof A.cancelBubble!="undefined"){A.cancelBubble=true;A.returnValue=false}}}function onFriendClick(C,B,A){if(B){cancelEvent(C);MySpace.invokeWebIMWrapper(A)}}function onGetFriendCount(B,A,E){var C=E?B:"0";totalFriends=C;var D=$get("apptopnav_friends_show");if(typeof D!=undefined&&D!=null){$get("apptopnav_friends_show").innerHTML='<div id="menuWrap"><a href="javascript:;"><span>'+getFriendsLabel()+"</span></a></div>"}}function onGetFriendList(C,B,D){if(D){var A=C;var E=new UI.DropDownList(A,UI.DropDownList.DataType.JSON,getFriendsLabel());if(!E.RenderList("menuWrap")){document.getElementById("menuWrap").innerHTML='<a href="javascript:;"><span>'+getFriendsLabel()+"</span></a>"}}else{document.getElementById("menuWrap").innerHTML='<a href="javascript:;"><span>'+getFriendsLabel()+"</span></a>"}}window.setInterval(checkFriends,60000);
