(function($){var Mustache=function(){var Renderer=function(){};Renderer.prototype={otag:"{{",ctag:"}}",pragmas:{},buffer:[],pragmas_implemented:{"IMPLICIT-ITERATOR":true},context:{},render:function(template,context,partials,in_recursion){if(!in_recursion){this.context=context;this.buffer=[]}if(!this.includes("",template)){if(in_recursion){return template}else{this.send(template);return}}template=this.render_pragmas(template);var html=this.render_section(template,context,partials);if(in_recursion){return this.render_tags(html,context,partials,in_recursion)}this.render_tags(html,context,partials,in_recursion)},send:function(line){if(line!=""){this.buffer.push(line)}},render_pragmas:function(template){if(!this.includes("%",template)){return template}var that=this;var regex=new RegExp(this.otag+"%([\\w-]+) ?([\\w]+=[\\w]+)?"+this.ctag);return template.replace(regex,function(match,pragma,options){if(!that.pragmas_implemented[pragma]){throw ({message:"This implementation of mustache doesn't understand the '"+pragma+"' pragma"})}that.pragmas[pragma]={};if(options){var opts=options.split("=");that.pragmas[pragma][opts[0]]=opts[1]}return""})},render_partial:function(name,context,partials){name=this.trim(name);if(!partials||partials[name]===undefined){throw ({message:"unknown_partial '"+name+"'"})}if(typeof(context[name])!="object"){return this.render(partials[name],context,partials,true)}return this.render(partials[name],context[name],partials,true)},render_section:function(template,context,partials){if(!this.includes("#",template)&&!this.includes("^",template)){return template}var that=this;var regex=new RegExp(this.otag+"(\\^|\\#)\\s*(.+)\\s*"+this.ctag+"\n*([\\s\\S]+?)"+this.otag+"\\/\\s*\\2\\s*"+this.ctag+"\\s*","mg");return template.replace(regex,function(match,type,name,content){var value=that.find(name,context);if(type=="^"){if(!value||that.is_array(value)&&value.length===0){return that.render(content,context,partials,true)}else{return""}}else{if(type=="#"){if(that.is_array(value)){return that.map(value,function(row){return that.render(content,that.create_context(row),partials,true)}).join("")}else{if(that.is_object(value)){return that.render(content,that.create_context(value),partials,true)}else{if(typeof value==="function"){return value.call(context,content,function(text){return that.render(text,context,partials,true)})}else{if(value){return that.render(content,context,partials,true)}else{return""}}}}}}})},render_tags:function(template,context,partials,in_recursion){var that=this;var new_regex=function(){return new RegExp(that.otag+"(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?"+that.ctag+"+","g")};var regex=new_regex();var tag_replace_callback=function(match,operator,name){switch(operator){case"!":return"";case"=":that.set_delimiters(name);regex=new_regex();return"";case">":return that.render_partial(name,context,partials);case"{":return that.find(name,context);default:return that.escape(that.find(name,context))}};var lines=template.split("\n");for(var i=0;i<lines.length;i++){lines[i]=lines[i].replace(regex,tag_replace_callback,this);if(!in_recursion){this.send(lines[i])}}if(in_recursion){return lines.join("\n")}},set_delimiters:function(delimiters){var dels=delimiters.split(" ");this.otag=this.escape_regex(dels[0]);this.ctag=this.escape_regex(dels[1])},escape_regex:function(text){if(!arguments.callee.sRE){var specials=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];arguments.callee.sRE=new RegExp("(\\"+specials.join("|\\")+")","g")}return text.replace(arguments.callee.sRE,"\\$1")},find:function(name,context){name=this.trim(name);function is_kinda_truthy(bool){return bool===false||bool===0||bool}var value;if(is_kinda_truthy(context[name])){value=context[name]}else{if(is_kinda_truthy(this.context[name])){value=this.context[name]}}if(typeof value==="function"){return value.apply(context)}if(value!==undefined){return value}return""},includes:function(needle,haystack){return haystack.indexOf(this.otag+needle)!=-1},escape:function(s){s=String(s===null?"":s);return s.replace(/&(?!\w+;)|["'<>\\]/g,function(s){switch(s){case"&":return"&amp;";case"\\":return"\\\\";case'"':return"&quot;";case"'":return"&#39;";case"<":return"&lt;";case">":return"&gt;";default:return s}})},create_context:function(_context){if(this.is_object(_context)){return _context}else{var iterator=".";if(this.pragmas["IMPLICIT-ITERATOR"]){iterator=this.pragmas["IMPLICIT-ITERATOR"].iterator}var ctx={};ctx[iterator]=_context;return ctx}},is_object:function(a){return a&&typeof a=="object"},is_array:function(a){return Object.prototype.toString.call(a)==="[object Array]"},trim:function(s){return s.replace(/^\s*|\s*$/g,"")},map:function(array,fn){if(typeof array.map=="function"){return array.map(fn)}else{var r=[];var l=array.length;for(var i=0;i<l;i++){r.push(fn(array[i]))}return r}}};return({name:"mustache.js",version:"0.3.1-dev",to_html:function(template,view,partials,send_fun){var renderer=new Renderer();if(send_fun){renderer.send=send_fun}renderer.render(template,view,partials);if(!send_fun){return renderer.buffer.join("\n")}}})}();$.mustache=function(template,view,partials){return Mustache.to_html(template,view,partials)}})(jQuery);Meetup.profilePhotoPicker=function(el,opts){var config={noDialog:false,elemId:"uploadPhoto",isManagePhotosPage:false};if(opts){$.extend(config,opts)}var EL_ID=opts.elemId,mainEl=$("#pickerDiv"),$dialog=null,$boothScreen=$('<div id="photoBoothScreen" style="display: none;" />'),exts=["jpg","gif","png","jpeg"];var uploadError=function(copy){$(".msgText","#upload_error").html(copy);$("#upload_error").show()};Meetup.doUploadPhoto=function(){$("#upload_error").hide();$(".J_upload_fail").hide();$("#facebook_uploader").show();$("#facebook_button").hide();$("#profilePhoto").trigger("onajaxsubmit");$.post(APIURL,{method:"syncProfilePhotoWithFacebook",arg_member:Member.id},function(data){$uploadButton.show();$fileInput.hide();$("#profilePhoto").trigger("onajaxsuccess");if(typeof(data.urls)!=="undefined"){checkForPhoto();updatePreviewPhotos(data.urls);if(isManagePhotosPage){updatePhotoListUI(data.urls)}if($get("photo_prefs")&&$get("photoId")){updateProfileEditUI(data.urls)}$get("profilePhoto").src=data.urls.member;$get("profilePhoto").style.backgroundColor="#eee";$get("profilePhoto").style.backgroundPosition="top";setTimeout(function(){$("#facebook_uploader").hide();$("#facebook_button").show()},1000)}else{$("#facebook_uploader").hide();$("#facebook_button").show();uploadError(Meetup.Copy.facebookError)}})};var template_photoListItem=['<li class="item">','<div style="background-image: url({{imageUrl}})">','<a target="_blank" href="{{imageUrl_highres}}">&nbsp;</a>',"</div>",'<ul class="D_actions">','<li class="canDo">Your main profile photo<li>','<li><a href="{{baseUrl}}/account/photo/?id={{photoId}}&op=del" class="canDo D_signal D_signal_appear_to_confirmProfilePhotoDelete">',"Delete","</a></li>","</ul>","</li>"].join("");var template_makeMainLink=["<li>",'<a class="canDo" href="{{baseUrl}}/account/photo/?id={{photoId}}&op=swap">Make main profile photo</a>',"</li>"].join("");var template_otherPhotos=['<div class="profilePhotoOptions"><div id="pickerPics" style="height:170px;margin:5px;overflow-y:auto;padding-left:20px;width:430px;">{{#photos}}','<div class="pickerPic linked" id="{{photo_id}}">','<img class="linked" src="{{#urls}}{{thumb}}{{/urls}}"></div>{{/photos}}','</div><div style="height:20px;text-align:center"><a href="" id="cancel_picker" class="D_less">Back</a></div></div>'].join("");var isManagePhotosPage=config.isManagePhotosPage;var getPhotoIdFromUrl=function(url){var matches=url.match(/\_([0-9]*)\./);return matches[1]};var updateProfileEditUI=function(urls){$get("photoId").value=getPhotoIdFromUrl(urls.thumb);$get("photo_prefs").value="show"};var updatePhotoListUI=function(urls){var photoItem=$.mustache(template_photoListItem,{imageUrl:urls.member,imageUrl_highres:urls.highres,baseUrl:"http://www.meetup.com",photoId:getPhotoIdFromUrl(urls.thumb)});var $UL=$("#memberOwnPhotosListWider,#memberOwnPhotoOnlyOne");$UL.find("li").each(function(i,el){var $li=$(el);var $actions=$li.find(".D_actions li");$actions.each(function(idx,action){if(action.className=="canDo"){var photoUrl=$li.find("div a").attr("href");var makeMainHTML=$.mustache(template_makeMainLink,{baseUrl:"http://www.meetup.com",photoId:getPhotoIdFromUrl(urls.thumb)});$(action).replaceWith(makeMainHTML)}})});$UL.prepend(photoItem)};var getUploadedPhotos=function(){$.get("/api/",{method:"getProfilePhotos",arg_memberId:Member.id},function(data){if(data.photoCount>0){var photo_html=$($.mustache(template_otherPhotos,{photos:data.photos}));if(!$get("pickerPop")){var $form=(!config.noDialog)?$("#"+config.elemId).find("div.D_form"):$("#"+config.elemId);$("#other_photos").append($('<a href="" id="pickerPop" class="meh">'+Meetup.Copy.pickFromPhotos+"</a>"));$("#pickerPop").click(function(e){e.preventDefault();$form.after(photo_html);$form.hide();$uploadButton.show();$fileInput.hide();$("#profile-photo-container").hide();$("#cancel_picker").click(function(e){e.preventDefault();photo_html.remove();$form.show();$("#profile-photo-container").show()});photo_html.delegate(".pickerPic","click",function(e){$("#profilePhoto").trigger("onajaxsubmit");var src=$("img",this).attr("src");var id=this.id;var urls={thumb:src,member:src.replace("thumb_","member_"),highres:src.replace("thumb_","highres_")};var params;if(typeof(Chapter)!=="undefined"&&Chapter.id!=0){params={method:"makeGroupProfilePhoto",arg_member:Member.id,arg_chapter:Chapter.id,arg_memberPhotoId:id}}else{params={method:"makeMainProfilePhoto",arg_member:Member.id,arg_memberPhotoId:id}}var success=function(data){$profilePhoto.trigger("onajaxsuccess");checkForPhoto();if(config.isManagePhotosPage){updatePhotoListUI(urls)}if($get("profilePhoto")){$get("profilePhoto").src=urls.member;$get("profilePhoto").style.backgroundColor="#eee"}photo_html.remove();$form.show();$("#profile-photo-container").show();updatePreviewPhotos(urls)};if($get("photo_prefs")&&$get("photoId")){success();updateProfileEditUI(urls)}else{$.ajax({type:"POST",url:APIURL,data:params,success:success})}})})}}})};var updatePreviewPhotos=function(urls){$("img.preview-photo").attr("src",urls.thumb);$("img.big-preview-photo").attr("src",urls.member)};var checkForPhoto=function(){if($get("photo-upload-msg")){$("div.profilePhotoContainer",mainEl).html('<img id="profilePhoto" src="" />')}};var handlePickerChange=function(e){var ext=this.value.split(".").pop().toLowerCase(),badExt=true;for(var i=0,len=exts.length;i<len;i++){if(ext==exts[i]){badExt=false}}if(badExt){uploadError(Meetup.Copy.filetypeError)}else{if(!config.noDialog){checkForPhoto();$("#profilePhoto").trigger("onajaxsubmit");$(this.form).submit()}else{$("div.profilePhotoContainer").html('<div id="photo-upload-msg" style="width:188px;font-weight:bold;text-align:center;">We will upload this photo when you save your profile.</div>')}}};var renderPhotoBooth=function(e){e.preventDefault();$dialog.find(".D_dialog_chunk").css("padding-bottom","100px");if($dialog.find("#photoBoothScreen").length<1){$dialog.append($boothScreen);$boothScreen.bind("onSaveSuccess",function(e,data){$boothScreen.trigger("destroy");$("#profilePhoto,#uploadPhoto").attr("src","data:image/jpg;base64,"+data)})}$boothScreen.fadeIn("fast",function(){$("#profileUploaderClose").hide();$boothScreen.photoBooth()})};var destroyPhotoBooth=function(e){$dialog.find(".D_dialog_chunk").css("padding-bottom","12px");if(!e||e.type!=="onDestroy"){$boothScreen.trigger("destroy");$boothScreen.hide()}else{$("#profileUploaderClose").show();$boothScreen.fadeOut("fast")}};if(typeof Meetup.IframeUpload!="undefined"){Meetup.IframeUpload($get(EL_ID),{photoType:"object"})}if(!config.noDialog){$dialog=$("#pickerDiv");$dialog.dialog({width:555,open:function(){$("#pickNoPhoto",$dialog).blur()}})}var $trigger=$(el),$frame=$("#"+EL_ID+"_frame"),$profilePhoto=$("#profilePhoto"),$fileInput=(!config.noDialog)?$("#photoUploadField"):$("#attachfile"),$uploadButton=$("#upload-new-photo"),$error=$("#upload_error");var initPicker=function(e){if(e){e.preventDefault()}getUploadedPhotos();if($.browser.msie){$fileInput.css({width:200})}if(!config.noDialog){$dialog.dialog("open")}$("div.messageSpace",$get("pickerDiv")).children().hide();$uploadButton.click(function(e){e.preventDefault();$(this).hide();$fileInput.show()});if($get(EL_ID+"_upload")){$get(EL_ID+"_upload").reset()}};if(!config.noDialog){$("#profileUploaderClose").click(function(e){$dialog.dialog("close")});$trigger.click(initPicker)}else{initPicker()}$(".J_fileInput",mainEl).change(handlePickerChange);var params;if(typeof(Chapter)!=="undefined"&&Chapter.id!=0){params={method:"makeGroupProfilePhoto",arg_member:Member.id,arg_chapter:Chapter.id,arg_memberPhotoId:0}}else{params={method:"makeMainProfilePhoto",arg_member:Member.id,arg_memberPhotoId:0}}$("#pickNoPhoto").click(function(e){e.preventDefault();$.ajax({type:"POST",url:APIURL,data:params,success:function(data){var urls={thumb:Meetup.Data.noPhotoImg,member:Meetup.Data.noPhotoImg,highres:Meetup.Data.noPhotoImg};if(config.isManagePhotosPage){updatePhotoListUI(urls)}checkForPhoto();$get("profilePhoto").src=Meetup.Data.newNoPhotoImg;$get("profilePhoto").style.backgroundColor="#eee";$("img.preview-photo").attr("src",Meetup.Data.noPhotoImg);$("img.big-preview-photo").attr("src",Meetup.Data.noPhotoImg);if($get("photo_prefs")&&$get("photoId")){$get("photoId").value=0;$get("photo_prefs").value="hide"}}})});$frame.bind("error",function(e,url){$error.hide();$profilePhoto.trigger("onajaxsuccess");$get(EL_ID+"_upload").reset()});$frame.bind("update",function(e,urls){$error.hide();$profilePhoto.trigger("onajaxsuccess");$profilePhoto.attr({src:urls.member});$profilePhoto.css({"background-color":"#eee"});$fileInput.hide();$uploadButton.show();updatePreviewPhotos(urls);if(config.isManagePhotosPage){updatePhotoListUI(urls)}if($get("photo_prefs")&&$get("photoId")){updateProfileEditUI(urls)}});$frame.bind("pending",function(){$profilePhoto.trigger("onajaxsuccess")});$(".hideMsg",mainEl).click(function(e){e.preventDefault();$(this).parent().hide()})};
