new_friends_list=false;fip=true;loading=false;function order(){for(var b="return ",c,d,e=1;e<arguments.length;e+=2){c=arguments[e];d=arguments[e+1]=="D"?1:-1;b+="(x."+c+" < y."+c+") ? "+d+" : ";b+="(x."+c+" > y."+c+") ? "+(0-d)+" : "}b+="0;";arguments[0].sort(new Function("x","y",b))}
function fullOrder(){me=friends.shift();order(friends,"tags","D","name","A");first_friends=[];last_friends=[];j=g=0;for(i in friends)if(friends[i].tags>0&&i<=3){first_friends[j]=friends[i];first_friends[j].bold=1;j++}else{last_friends[g]=friends[i];last_friends[g].bold=0;g++}order(last_friends,"name","A");friends=last_friends;first_friends.reverse();for(i in first_friends)friends.unshift(first_friends[i]);friends.unshift(me)}function balloon_show(b){b="#"+b;$(b).css("display","")}
function setPosition(b){pos_next=reverse_order[b+1]?b+1:1;pos_prev=reverse_order[b-1]?b-1:total_photos}function setShare(){$(".wm-thumb").html(photo_src);$("#s_p").attr("value",photo_id);$("#sharePhoto").jqm({trigger:".triggerSharePhoto",onShow:function(b){ft_gtv.stop();b.w.show()},onHide:function(b){ft_gtv.start();b.o.remove();b.w.hide()}})}
function slideShow(){stop=pos_actual;inicio=0;i=1;slide=true;showStop();for(time=3E3;inicio!=stop;){if(i==1)inicio=parseInt(pos_actual);inicio=inter=reverse_order[parseInt(inicio)+1]?parseInt(inicio)+1:1;time=i*3E3;timeout=setTimeout("changePhoto('next')",time);timeouts[i]=timeout;i++}try{_gaq.push(["_trackPageview","/events/photos/slideshow-pic"])}catch(b){}$("#start").attr("href","#");setTimeout("showStart()",time)}
function showStart(){$("#start").attr("class","btn-ph play");st_el=document.getElementById("start");st_el.onclick=function(){slideShow();return false}}function showStop(){$("#start").attr("class","btn-ph pause");st_el=document.getElementById("start");st_el.onclick=function(){stopSlide();return false}}function stopSlide(){if(timeouts)for(i in timeouts)a=clearTimeout(timeouts[i]);slide=false;showStart()}function tryStop(){slide&&stopSlide()}
function getFriends(b){if(new_friends_list){ft_trigger_tag("#img_photo_"+photo_id);stopSlide()}else{$("#loading-friends").show();$.getJSON("/album_get_friends.php",function(c){friends=c;fullOrder();ft_fslm=new jQuery.searchlist(friends);ft_fslc=$("#ft_autocomplete").searchcontrol(ft_fslm);ft_fslv=$("#ft_search_view").searchview(ft_fslm,{formatItem:ft_format_friend_item});ft_fslv.bind("singleMatch",function(d){ft_multiple_matches(ft_clear_checks)}).bind("noMatches",function(d){ft_no_matches(function(){})});
ft_fslv.bind("multipleMatches",function(d){ft_multiple_matches(ft_clear_checks)}).bind("noMatches",function(d){ft_no_matches(function(){})});$(".tag_me").bind("click",ft_finish_tag);$(".ft_cancel_tag").bind("click",ft_cancel_tag);$(".ft_cancel").bind("click",ft_cancel_tag);$(".ft_finish_tag").bind("click",ft_finish_tag);$("#nexthref").bind("click",ft_check_tag);$("#prevhref").bind("click",ft_check_tag);ft_trigger_tag("#img_photo_"+photo_id);stopSlide();$("#loading-friends").remove()})}new_friends_list=
true}
function setTags(){tags=total_tags[photo_id];flag=false;for(i in ft_ptms){flag=true;break}$(".ft_photo").attr("id","img_photo_"+photo_id);$(".ft_photo").attr("pid",photo_id);$(".ft_trigger").attr("pid",photo_id);$("#msg-who").attr("style","display: none;");$("#msg-who").attr("class","box-msg box-notice ft_tag_notice_"+photo_id);$(".tag_messages").attr("id","tag_captions_"+photo_id);$(".ft_trigger").unbind("click");if(flag){ft_ptms.updateTags(tags);ft_gtv.restart(ft_ptms)}else{ft_ptms=new jQuery.PhotoTagLists(tags);ft_pointer=
new jQuery.Pointer({side:ft_pointer_size});ft_fslcont=$("#photo-tagbox");ft_eid=$("#ft_email_div");ft_gtv=new jQuery.PhotoTagPhotoView(ft_ptms,{pointerSize:ft_pointer_size,ulClass:"info-ph mar-bottom fr-400",formatItemHTML:ft_format_tag_html,emptyCaptionHTML:ft_empty_caption_tag})}$(".ft_trigger").bind("click",function(b){getFriends(b)})}
function editDesc(b){$.post(pages_album_edit_photo_description,{a:album_id,p:photo_id,d:b,fpid:fpid},function(c){$(".description").html(c);$(".description").show();photo_descs[photo_id]=c})}
function remove_photo(b,c){if(c){total_photos-=1;delete photo_order[b];new_photo_order=[];new_reverse_order=[];lc=1;for(lpid in photo_order){new_photo_order[lpid]=lc;new_reverse_order[lc]=lpid;lc+=1}photo_order=new_photo_order;reverse_order=new_reverse_order;delete photo_urls[b];delete photo_descs[b];delete photo_widths[b];delete photo_heights[b];delete photo_srcs[b];delete total_tags[b];delete total_messages[b];delete new_photo_order;delete new_reverse_order;$.get(pages_url+"pages_album_edit.php",
{a:album_id,dp:b,fpid:fpid},function(d){if(total_photos==0)location.href=pages_url+"pages_albums.php?fpid="+fpid;$(".total_photos").html(total_photos);pos_actual>1?changePhoto("prev"):changePhoto()})}}function setComments(){messages=total_messages[photo_id];$("#comments").html("");loadComments(album_id,photo_id,"#comments",messages);$("#board_cant_msgs").html(String(messages.length))}function showLoading(b){b?$("#photo_loading").show():$("#photo_loading").hide()}
function loadPhoto(b,c){if(c){showLoading(true);loading=true}$("body").append('<img id="preload_'+b+'" style="display: none;">');setTimeout(function(){loading=false},3E3);$("#preload_"+b).load(function(){var d=false;if(c){showLoading(false);setPhoto();if(!d){preloaded.push(b);d=true}loading=false}d||preloaded.push(b)});$("#preload_"+b).attr("src",photo_urls[b])}
function preloadPhotos(b){for(r=i=1;i<3;i++){if(reverse_order[b+i])next_id=reverse_order[b+i];else{next_id=reverse_order[r];r++}jQuery.inArray(next_id,preloaded)==-1&&loadPhoto(next_id,false)}}
function setPhoto(){photo_url=photo_urls[photo_id];photo_descr=photo_descs[photo_id];photo_src=photo_srcs[photo_id];$(".ft_photo").attr("src",photo_url);$("#post_id").attr("value",photo_id);if(photo_descr){$(".description").html(photo_descr);$("#photo_description").val(photo_descr)}else{$(".description").empty();$("#photo_description").val("")}setTags();setComments();setShare();$(".photo_upload_date").html(photo_upload_date[photo_id]);$("#pos").html(photo_order[photo_id]);total_edits[photo_id]?$(".edit_link").show():
$(".edit_link").hide();$("#edit_description").hide();total_names[photo_id].id==""?$("#virtual_user_by_txt").hide():$("#virtual_user_by_txt").show();$("#virtual_user_by").attr("href",sonico_url+"profile.php?u="+total_names[photo_id].id);$("#virtual_user_by").html(total_names[photo_id].name);sp_report?$("#a_abuse_report").attr("src",sonico_url+"layers/pages_block_user.php?fpid="+fpid+"&uid="+total_names[photo_id].id):$("#a_abuse_report").attr("href",sonico_url+"report.php?t="+report_type_page_photo+
"&g="+fpid+"&c1="+album_id+"&c2="+photo_id);$("#c_photo_share").attr("href","/publico/photo_page_share.php?a="+album_id+"&p="+photo_id+"&fpid="+fpid);if(total_edits[photo_id]){$("#c_delete").show();$("#c_abuse_report").hide()}else{$("#c_delete").hide();$("#c_abuse_report").show()}}
function changePhoto(b){$(".stopTrigger").bind("click",stopSlide);if(!loading){if(b=="next")pos_actual=pos_next;if(b=="prev")pos_actual=pos_prev;setPosition(pos_actual);next_id=reverse_order[pos_next];prev_id=reverse_order[pos_prev];photo_id=reverse_order[pos_actual];window.location.hash=photo_id;if(top.frames.frameContent)top.location.hash=escape(self.location.href);document.createElement("img").setAttribute("src",pages_url+"pages_stats.php?action=5&fpid="+fpid);faviconUtils.change("http://static.ak.sonico.com/favicon.ico");
$(".ft_photo").attr({src:gray_pixel,width:photo_widths[photo_id],height:photo_heights[photo_id]});jQuery.inArray(photo_id,preloaded)==-1?loadPhoto(photo_id,true):setPhoto();preloadPhotos(pos_actual);fip=false}};

