(function(a,e,f,h){function b(a){this.el=a;this.ids=[];this.init()}a.fn.favorite=function(){return a.favorite=new b(a(this))};b.prototype.init=function(){var a;if(a=e.getCookie("fav"))this.ids=a.split("-");this.ids.length&&this.el.show().children("span").text(this.ids.length)};b.prototype.show=function(){var g=[],d=h.get(),c,b;for(c in d)for(b in this.ids)d[c][17]==this.ids[b]&&g.push(c);f.searchFlats(g);this.active=!0;this.el.children("a").addClass("factive");a("#content a.back.favorite").length||
a("#content .nav:first").prepend(a('<a class="js back favorite">\u0412\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043f\u043e\u0438\u0441\u043a\u0443</a>').click(function(){a.favorite.hide();return!1}))};b.prototype.hide=function(){this.active=!1;f.history();this.el.children("a").removeClass("factive");a("a.back.favorite").remove()};b.prototype.add=function(a){this.ids.push(a);e.setCookie("fav",this.ids.join("-"),99);this.el.show().children("span").text(this.ids.length)};b.prototype.rm=
function(b){var d=[],c;for(c in this.ids)this.ids[c]!=b&&d.push(this.ids[c]);this.ids=d;this.el.children("span").text(this.ids.length);e.setCookie("fav",d.join("-"),99);d.length||(this.el.hide(),a("#flats").length&&this.hide());this.active&&this.show()};b.prototype.appendTo=function(b){if(!b.children("a.favorite").length){var d=b.attr("data-id"),c="",e;for(e in this.ids)if(d==this.ids[e]){c="factive";break}b.append(a('<a class="favorite"></a>').attr("data-id",d).click(function(){a(this).hasClass("factive")?
(a(this).removeClass("factive").attr("title","\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435"),a.favorite.rm(parseInt(a(this).attr("data-id")))):(a(this).addClass("factive").attr("title","\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e"),a.favorite.add(parseInt(a(this).attr("data-id"))))}).addClass(c).attr("title",c?"\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0437 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e":
"\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435"))}}})(jQuery,utils,search,flats);
