CX.Controls.MyPhotos=Class.create(function(){var h=CX.url_root()+"/my/photo",g="profilePhoto:",a=/\bprofilePhoto:(\w+)\b/;
function c(j,i,l){if(j=="index"){return h+"s";
}var k=j=="new"?h+"/new":h+"/"+i+"/"+j;
if(l){k+="?"+(typeof(l)=="string"?l:l.toQueryString());
}return k;
}function f(j,m){var k=[$("my_photo_tag0"),$("my_photo_tag1")];
for(var l=0;
l<k.length;
l++){if(k[l]&&k[l].hasClassName(g+j)){m(k[l]);
}}}function d(j){var i;
if(j.className&&(i=a.exec(j.className))){return i[1];
}}function b(m,j,l){var i=d(l);
if(i){m.change(j,i);
}else{if(l.parentNode.className&&l.parentNode.className.indexOf("photo-action")>=0){if(m._onAction){return m._onAction(j,l);
}var k=$("modal_dialog_message");
new Ajax.Updater(k,l.href+"?personas="+(1<<j),{method:"get",oncomplete:Element.undim.curry(k),evalScripts:true});
k.dim({cssNames:"big-waiting"});
}}return true;
}return{initialize:function(j){if(!j){j={};
}this._onDisplay=j.onDisplay;
this._onAction=j.onAction;
var k,i=j.onClose;
if(this._autoExport=j.autoExport){k=this.exportTo.bind(this,this._autoExport[0],this._autoExport[1]);
}this._onClose=k?(i?(function(){k();
i();
}):k):i;
},display:function(){if(this._onDisplay){this._onDisplay.apply(this,arguments);
}else{var i={method:"get",evalScripts:true};
CX.modalDialog(null,{url:c("index"),options:i},{force:true,close:this._onClose});
}return this;
},exportTo:function(){for(var l=0;
l<2;
l++){var n=arguments[l];
if(!Object.isArray(n)||!n.length){continue;
}var m=$("my_photo_tag"+l);
for(var k=0;
k<n.length;
k++){var o=$(n[k]);
if(o.nodeName=="IMG"){o.src=m.src;
}else{o.update(m.title||"");
}}}},refresh:function(j,i){f(j,function(k){k.src=k.src.gsub(/\/([^\/\.]+\.[^\/]+)\/[^\/\.]+$/,"/#{1}/"+i);
});
return this;
},select:function(j,k){var i=d($("my_photo_tag"+j));
CX.DropdownPicker.open(k,$("change_photo_menu"),{standalone:true,"class":(i&&i!="none")?"my-photos-list":"my-photos-list no-photo-selected",onselect:b.curry(this,j)});
return this;
},change:function(j,i){if($("my_photo_tag"+j).hasClassName("profilePhoto:"+i)){return;
}var k=$("my_photo"+j);
new Ajax.Updater(k,c("select",i,"persona="+j),{oncomplete:Element.undim.curry(k),evalScripts:true});
k.dim({cssNames:"big-waiting"});
return this;
},edit:function(i){var j="editPhotoFrame_SAFARI_"+(new Date()).getTime();
CX.modalDialog(null,'<iframe frameborder="no" width="750" height="575" id="'+j+'" name="'+j+'" src="'+c("edit",i)+'"></iframe>',{force:true});
return this;
}};
}());
ASSET_MANIFEST=["/javascripts/cx/app/my/photos.js"];
try{GLOBAL_ASSET_MANIFEST=GLOBAL_ASSET_MANIFEST.concat(ASSET_MANIFEST);
}catch(e){GLOBAL_ASSET_MANIFEST=ASSET_MANIFEST;
}
