new_friends_list=false;fip=true;loading=false;function order(){var param="return ",dato,orden;for(var i=1;i<arguments.length;i+=2){dato=arguments[i];orden=(arguments[i+1]=="D")?1:-1;param+="(x."+dato+" < y."+dato+") ? "+orden+" : ";param+="(x."+dato+" > y."+dato+") ? "+(0-orden)+" : "}param+="0;";arguments[0].sort(new Function("x","y",param))}function fullOrder(){me=friends.shift();order(friends,"tags","D","name","A");first_friends=new Array();last_friends=new Array();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(show){show="#"+show;$(show).css("display","")}function setPosition(position){if(reverse_order[position+1]){pos_next=position+1}else{pos_next=1}if(reverse_order[position-1]){pos_prev=position-1}else{pos_prev=total_photos}}function setShare(){$(".wm-thumb").html(photo_src);$("#s_p").attr("value",photo_id);$("#sharePhoto").jqm({trigger:".triggerSharePhoto",onShow:function(hash){ft_gtv.stop();hash.w.show()},onHide:function(hash){ft_gtv.start();hash.o.remove();hash.w.hide()}})}function slideShow(){stop=pos_actual;inicio=0;i=1;slide=true;showStop();time=3000;while(inicio!=stop){if(i==1){inicio=parseInt(pos_actual)}if(reverse_order[parseInt(inicio)+1]){inter=parseInt(inicio)+1}else{inter=1}inicio=inter;time=i*3000;timeout=setTimeout("changePhoto('next')",time);timeouts[i]=timeout;i++}try{_gaq.push(["_trackPageview","/events/photos/slideshow-pic"])}catch(err){}$("#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(){if(slide){stopSlide()}}function getFriends(e){if(!new_friends_list){$("#loading-friends").show();$.getJSON("/album_get_friends.php",function(data){friends=data;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(e){ft_multiple_matches(ft_clear_checks)}).bind("noMatches",function(e){ft_no_matches(function(){})});ft_fslv.bind("multipleMatches",function(e){ft_multiple_matches(ft_clear_checks)}).bind("noMatches",function(e){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()})}else{ft_trigger_tag("#img_photo_"+photo_id);stopSlide()}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=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})}else{ft_ptms.updateTags(tags);ft_gtv.restart(ft_ptms)}$(".ft_trigger").bind("click",function(e){getFriends(e)})}function editDesc(value){$.post(pages_album_edit_photo_description,{a:album_id,p:photo_id,d:value,fpid:fpid},function(data){$(".description").html(data);$(".description").show();photo_descs[photo_id]=data})}function remove_photo(photo_id,action){if(action){total_photos-=1;delete photo_order[photo_id];new_photo_order=new Array();new_reverse_order=new Array();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[photo_id];delete photo_descs[photo_id];delete photo_widths[photo_id];delete photo_heights[photo_id];delete photo_srcs[photo_id];delete total_tags[photo_id];delete total_messages[photo_id];delete new_photo_order;delete new_reverse_order;$.get("pages_album_edit.php",{a:album_id,dp:photo_id,fpid:fpid},function(data){if(total_photos==0){location.href="pages_albums.php?fpid="+fpid}$(".total_photos").html(total_photos);if(pos_actual>1){changePhoto("prev")}else{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(show){if(show){$("#photo_loading").show()}else{$("#photo_loading").hide()}}function loadPhoto(photo_id,wait){if(wait){showLoading(true);loading=true}$("body").append('<img id="preload_'+photo_id+'" style="display: none;">');setTimeout(function(){loading=false},3000);$("#preload_"+photo_id).load(function(){var added=false;if(wait){showLoading(false);setPhoto();if(!added){preloaded.push(photo_id);added=true}loading=false}if(!added){preloaded.push(photo_id)}});$("#preload_"+photo_id).attr("src",photo_urls[photo_id])}function preloadPhotos(position){for(i=1,r=1;i<3;i++){if(reverse_order[position+i]){next_id=reverse_order[position+i]}else{next_id=reverse_order[r];r++}if(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").empty();$("#photo_description").val("")}else{$(".description").html(photo_descr);$("#photo_description").val(photo_descr)}setTags();setComments();setShare();$(".photo_upload_date").html(photo_upload_date[photo_id]);$("#pos").html(photo_order[photo_id]);if(total_edits[photo_id]){$(".edit_link").show()}else{$(".edit_link").hide()}$("#edit_description").hide();if(total_names[photo_id]["id"]==""){$("#virtual_user_by_txt").hide()}else{$("#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"]);if(sp_report){$("#a_abuse_report").attr("src",sonico_url+"layers/pages_block_user.php?fpid="+fpid+"&uid="+total_names[photo_id]["id"])}else{$("#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","photo_page_share.php?a="+album_id+"&p="+photo_id+"&fpid="+fpid);if(!total_edits[photo_id]){$("#c_delete").hide();$("#c_abuse_report").show()}else{$("#c_delete").show();$("#c_abuse_report").hide()}}function changePhoto(pos){$(".stopTrigger").bind("click",stopSlide);if(!loading){if(pos=="next"){pos_actual=pos_next}if(pos=="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)}var image=document.createElement("img");image.setAttribute("src",sonico_url+"publico/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]});if(jQuery.inArray(photo_id,preloaded)==-1){loadPhoto(photo_id,true)}else{setPhoto()}preloadPhotos(pos_actual);fip=false}};