var isFriend=false;var isOnline=false;var statusText="";var initialStatusTextHeight="";$(document).ready(function(){var a=new Image();a.src=getImageMediaAssetURL("ajax_spinner_mini.gif","");$.each($("#announcements img"),function(d,e){if($(e).width()>=530){var c=530/$(e).width();$(e).height(Math.ceil($(e).height()*c))}});$("a#inviteToPlay").hide();$.jqm.params.toTop=true;$.jqm.params.overlayClass="jqmOverlay";$.jqm.params.overlay=80;$("#remove_friend_notice").jqm({modal:true});$("#add_friend_notice").jqm();$("#share_replay_dialog").jqm({modal:true});$("a#add_removeFriend").click(function(){window.location=baseSitePath+"login.aspx?ReturnUrl=user%2fprofile.aspx%3fUserID%3d"+profileUserID;return false});$("a#inviteToPlay").click(function(){inviteToPlay(profileUsername);return false});if($("div#playerStatus span").text()=="Available"){enableInviteToPlay()}$("#remove_friend_yes").click(function(c){c.stopPropagation();friendRemove(profileUsername);isFriend=false;swapAddRemoveImage();$("#remove_friend_notice").jqmHide();return false});$("#remove_friend_no").click(function(c){c.stopPropagation();$("#remove_friend_notice").jqmHide();return false});$("#add_friend_ok").click(function(c){c.stopPropagation();$("#add_friend_notice").jqmHide();return false});if(userID==0){$("#profileOtherButtons").show()}$("#inband_select_all").click(function(c){$("#inband_friends_list input:checkbox").each(function(d){$(this).attr("checked","checked")});$(this).blur()});$("#inband_select_none").click(function(c){$("#inband_friends_list input:checkbox").each(function(d){$(this).removeAttr("checked")});$(this).blur()});$(":checkbox").focus(function(c){$(this).blur()});$(".email_addresses").focus(function(c){$(this).html("")});$(".email_addresses").blur(function(c){if($(this).html()==""){$(this).html("Enter email addresses separated by a comma.")}});$("#send_message_link").click(function(c){$(".send_message:first a:first").click()});var b;if($("#total_records_unread").html()==""){b=0}else{b=parseInt($("#total_records_unread").html())}if(b>=1){$("#active_wrapper").show();$("#inactive_wrapper").hide()}else{$("#inactive_wrapper").show();$("#active_wrapper").hide()}$("#overlay_buttons .profile_overlay_link").click(function(){$("html,body").animate({scrollTop:0},500)});if(typeof(initialMyStatusText)!="undefined"){$("#status_text").html(initialMyStatusText.replace(/(\n|\&\#10\;)/g,"<br />")).height("auto");initialStatusTextHeight=$("#status_text").height();resizeStatusLabel()}$("#edit_status_link a").click(function(d){$("#status_field").autogrow({});$("#status_text_wrapper").hide();var c=$("#status_text").html();c=c.replace(/(<br>|<br\/>|<br \/>)/gi,"\n");c=Encoder.htmlDecode(c);$("#status_field_wrapper").show();$("#status_field").val(c);$("#status_field").focus().select();$("#status_buttons").show()});$("#status_cancel_link").click(function(c){$("#status_text_wrapper").show();$("#status_field_wrapper").hide();$("#status_field").val(statusText);$("#status_text").height(initialStatusTextHeight);resizeStatusLabel();$("#status_buttons").hide()});$("#status_save_link").click(function(f){var k=$("#status_field").val();var g=k.split("\n");var l=new Array(g.length);for(var c=0;c<g.length;c++){var e=g[c].split(/\s+/);var d=new Array();for(var h=0;h<e.length;h++){if(e[h].length>35){d.push(e[h].substr(0,34))}else{d.push(e[h])}}l[c]=d.join(" ")}k=l.join("\n");while(k.substring(k.length-1)=="\n"){k=k.substring(0,k.length-1)}k=Encoder.htmlEncode(k);$.ajax({type:"POST",url:callrouterURL+"UpdateMyStatus",data:'{"NewStatus": "'+k+'"}',dataType:"json",contentType:"application/json; charset=utf-8",beforeSend:function(i){i.setRequestHeader("Content-type","application/json")},success:function(i){var j=(i.d)?i.d:i;if(j.RC==0){$("#status_field_wrapper").hide();$("#status_field").val(j.DBG);$("#status_buttons").hide();var m=j.DBG.replace(/(\&\#10\;|\n)/g,"<br />");$("#status_text").html(m);statusText=$("#status_text").html();$("#status_text_wrapper").show();$("#status_text").show().height("auto");setTimeout(function(){var n=($("#status_text").height()>=15)?$("#status_text").height():15;$("#status_label_view").height(n).hide().show();$("#status_text").height($("#status_label_view").height())},0)}},error:function(j,i,m){$("#status_error").html("Sorry, your status could not be saved.").show().fadeOut(3000)}})});$.ajax({type:"POST",url:proShopServiceURL+"GetPlayerInventoryItems",data:'{"CSUserID":"'+profileUserID+'"}',dataType:"json",contentType:"application/json; charset=utf-8",beforeSend:function(c){c.setRequestHeader("Content-type","application/json")},success:function(c){var d=(c.d)?c.d:c;if(d.length==0){console.log("no items in player inventory")}else{if(d.length>0){renderCurrentEquipment(d)}else{console.log("no response for player inventory")}}}})});function renderCurrentEquipment(a){$.each(a,function(d){var c=this;$("#current_equipment_item_template").children().clone().attr("id","current_equipment_item_"+d).appendTo($("#current_equipment_items"));var b=$("#current_equipment_item_"+d+" img.equipped_item_graphic:first");b.attr("src",getProShopMediaAssetURL(getPath("asset")+c.ImageSmall));if(c.ItemType=="3"){b.attr("title","Balls: "+c.Brand.Name+" "+c.Name)}else{if(c.ItemType=="2"){b.attr("title",c.Attributes.ClubType+": "+c.Brand.Name+" "+c.Name)}}b.css("border","1px solid #9b9b9b");b.hover(function(e){$("#current_equipment_items .highlighted").removeClass("highlighted");$(this).addClass("highlighted");$("img.current_equipment_logo").attr("src",getProShopMediaAssetURL(getPath("asset")+backToForward(c.Brand.LogoSmall))).show()},function(e){$(this).removeClass("highlighted");$("img.current_equipment_logo").hide()})})}function resizeStatusLabel(){setTimeout(function(){var a=($("#status_text").height()>=15)?$("#status_text").height():15;$("#status_label_view").height(a).hide().show();$("#status_label_view img.status_label").css({position:"absolute",top:"38%",left:"28px",width:"43px",paddingTop:"0"});$("#status_text").height($("#status_label_view").height())},0)}function onWidgetReady(){isFriend=profileIsFriend(profileUsername);if(isFriend){$("#send_message_link").show()}else{$("#send_message_link").hide()}swapAddRemoveImage();var d=$("a#add_removeFriend");d.unbind();d.click(function(){if(isFriend){profileRemoveFriend(profileUsername)}else{profileAddFriend(profileUsername)}return false});if($("div#playerStatus span").text()=="Offline"){isOnline=profileIsOnline(profileUsername);if(isFriend&&isOnline||(userID==profileUserID)){$("div#playerStatus span").text("Available");var c=$("div#playerStatus img");c.attr("title","Available");c.attr("alt","Available");var a=c.attr("src");var b=a.replace("offline","available");c.attr("src",b)}}else{isOnline=true}if(isOnline){enableInviteToPlay()}if(userID!=profileUserID){$("#profileOtherButtons").show()}else{$("#profileOwnButtons").show()}}function enableInviteToPlay(){var a=$("a#inviteToPlay");a.show();a.unbind();a.click(function(){inviteToPlay(profileUsername);return false})}function swapAddRemoveImage(){var e="";var d="";if(isFriend){e="removefriend";d="Remove Friend"}else{e="addasfriend";d="Add As Friend"}var c=$("a#add_removeFriend > img");var a=c.attr("src");var b=a.replace(a.match(/button_(\w+)\./)[1],e);c.attr("src",b);c.attr("alt",d);c.attr("title",d)}function profileAddFriend(a){friendAdd(a);$("#add_friend_notice").jqmShow();$("#add_friend_ok").blur();isFriend=true;swapAddRemoveImage()}function profileRemoveFriend(a){$("#remove_friend_notice").jqmShow();$("#remove_friend_yes").blur()}function profileIsFriend(a){var b=getUserStates(a);if(b){b=JSON.parse(b);if(b){return b.friend}else{return false}}else{return false}}function profileIsOnline(a){var b=getUserStates(a);if(b){b=JSON.parse(b);if(b){return b.online}else{return false}}else{return false}};