var fotoOnload=function(){$("div.moveFotoBlock a:first").click(function(){$("#move_foto_form").parent().toggle();return false});function B(I){var H=$("#stars input").data("rating");var G=Math.round(I)-1;G=G<0?0:G;H.current=$(H.stars[G]);$("#stars input").data("rating",H).rating("draw")}$("#stars input").rating({required:true,callback:function(H){var I={rate:H};var J=$("#user_rating").text();$("#user_rating").text("Подождите...").addClass("proceed");var G=$("#stars span.url").text();$.post(G,I,function(K){if(K.errors.length>0){alert(K.errors[0]);$("#user_rating").text(J).removeClass("proceed");B(parseFloat($("div.ratingCount span").text()));return }B(K.data.avg_rate);$("div.ratingCount span").text(K.data.avg_rate.toFixed(1));$("#num_votes").html("всего голосов: <strong>"+K.data.num_votes+"</strong>");$("#user_rating").html("ваша оценка: <strong>"+K.data.rate+"</strong>").removeClass("proceed")},"json")}}).parent().show();var E=$("#stars input").data("rating"),A=E.stars,D=E.readOnly;$(A).unbind("click").click(function(){var G=false;if($("#user_rating").text().search(/\d/)!=-1){G=true;if(D||!confirm("Вы действительно хотите изменить свой голос?")){return false}}$(this).rating("select")});$("#stars a:eq(10)").css("text-indent","3px");$("a.exifShow").click(function(){var H=this.href;var G=$(this).next("span.processBlock:first");if($("#fotoExifData:empty").length){G.show();var I=$("#fotoExifData").load(H,function(){G.hide();I.show()});return false}$("#fotoExifData").toggle();return false});function C(G){var G=G||null;if(!G){return[]}return $.grep($(G).val().replace(/[^\da-zа-яё ,-]/gi,"").toLowerCase().split(/\s*,\s*/),function(H){H=$.trim(H);return(H.length>0&&H.length<32)})}$("div.tagsEdit a:first").click(function(){$("#tag_form").parent().toggle().find("input[type=text]:first:visible").focus();return false});$("#add_tags").click(function(){var G=[],H=C("#fresh_tags");$("#tags_container span").each(function(J){G.push($.trim($(this).text().toLowerCase()))});H=unique(H,G);var I="";$.each(H,function(){if($.trim(this).length){I+=sprintf('<span class="tagName" onclick="$(this).remove();">{$item}</span>',this.toString())}});$("#tags_container").append(I);$("#fresh_tags").val("")});$("#fresh_tags").keypress(function(G){if(G.which==13){$("#add_tags").click();return false}});var F={success:function(I){if(I.errors.length>0){return alert(I.errors[0])}var G=C("#tag_form input[name=plain_tags]"),H=[];$.each(G,function(){H.push(sprintf('<a href="/tag/{$item}/">{$item}</a>',this,this))});$("#fotoTags span.tagsList").html(H.join(", "));$("#fotoTags span.tagsTitle").html(H.length?"Метки: ":"");$("#tag_form").find("input[type=button], input[type=submit]").attr("disabled","").end().find(".proceed").hide()},dataType:"json"};$("#tag_form").ajaxForm(F).bind("form-pre-serialize",function(){var G=[];$("#tags_container span").each(function(H){G.push($.trim($(this).text()))});$(this).find("input[name=plain_tags]").val(G.join(", ")).end().find("input[type=button], input[type=submit]").attr("disabled","disabled").end().find(".proceed").show()});$("#resetTags").click(function(){var G=C("#tag_form input[name=plain_tags]"),H="";$.each(G,function(){if(this.length){H+=sprintf('<span class="tagName" onclick="$(this).remove();">{$item}</span>',this)}});$("#tags_container").html(H);$("#closeTagForm").click();return false});$("#closeTagForm").click(function(){$("#tag_form").parent().hide()});$("#complain_form select").change(requireSelectForSubmit).trigger("change");$("#write_comment, #leave_comment").click(function(){if($(this).parent().next("#comment_form").length){$("#comment_form").toggle()}else{$("#comment_form").insertAfter($(this).parent()).show()}$("#comment_form").find("input[name=reply_to]").val("").end().find("textarea").focus();$("#commentsBlock ul").find("li:empty").remove();return false});$("#comment_form :reset").click(function(){if($(this).next(":hidden").val()){$(this).parents("li:first").toggle()}else{$(this).parent().toggle()}});$("a.reply_comment").click(function(){var I=$("#commentsBlock ul");var G=$(this).parents("li");var J=G.attr("id").replace(/\D/g,"");var H=$("#comment_form input[name=reply_to]").val()==J;if(H){$("#comment_form").parent().toggle()}else{$("#comment_form").find("input[name=reply_to]").val(J).end().insertAfter(G).show().wrap("<li></li>")}$("#comment_form").find("textarea").focus();I.find("li:empty").remove();return false});$("a.delete_comment").click(function(){if(confirm("Вы действительно хотите удалить этот комментарий?")){var G=this;$(this).next("span.processBlock").show();$.getJSON(this.href,function(H){if(H.errors.length){alert(H.errors[0]);return false}$(G).hide().parents("li").addClass("is_deleted").find("div.descr").html("<div class='red_label'>комментарий удалён</div>").end().end().siblings("a.restore_comment").show().end().siblings("span.processBlock").hide()})}return false});$("a.restore_comment").click(function(){if(confirm("Вы действительно хотите восстановить этот комментарий?")){var G=this;$(this).next("span.processBlock").show();$.getJSON(this.href,function(H){if(H.errors.length){alert(H.errors[0]);return false}$(G).hide().parents("li").removeClass("is_deleted").end().siblings("a.delete_comment").show().end().siblings("span.processBlock").hide()})}return false});$("#bookmark").click(function(){var G=this;this.clicked=this.clicked||0;if(this.clicked++>=3){return false}$(this).next("span.processBlock").show();$.getJSON(this.href,function(H){$(G).next("span.processBlock").hide();if(H.errors.length){alert(H.errors[0]);return false}if($(G).hasClass("addBookmark")){$(G).removeClass().addClass("removeBookmark").attr("href",$(G).attr("href").replace(/=add/,"=remove")).find("span").attr("title","Убрать из закладок")}else{$(G).removeClass().addClass("addBookmark").attr("href",$(G).attr("href").replace(/=remove/,"=add")).find("span").attr("title","Добавить в закладки")}});return false})};if(typeof (jsx)!="undefined"){jsx.require(["main","jquery.rating"],function(){fotoOnload();jsx.loaded("foto")})}else{$(fotoOnload)};