var Concepts2Go=Concepts2Go||{};Concepts2Go.Cms=Concepts2Go.Cms||{},function(n,t,i,r){var u=function(n){var u=this,f=[];u.updateCounter=function(){n.getJSON("/favorites/count?_="+(new Date).getTime()+"&culture="+n("html").attr("lang"),function(i){var r=parseInt(i),u=!0;typeof t.C2GFavorites_ShowCount!="undefined"&&(u=t.C2GFavorites_ShowCount(r));u?(n("span[data-favorites-counter]").text(r),n("span[data-favorites-counter]").show()):n("span[data-favorites-counter]").hide()})};u.getFavorites=function(){n.getJSON("/favorite?_="+(new Date).getTime()+"&culture="+n("html").attr("lang"),function(n){f=n})};u.init=function(){u.getFavorites();n(i).on("click touch","[data-favorite]",function(){u.toggleFavorite(this)});n(t).on("load",function(){u.updateFavorites()})};u.updateFavorites=function(){n.getJSON("/favorites/visible?_="+(new Date).getTime()+"&culture="+n("html").attr("lang"),function(t){t&&u.updateCounter();n("[data-favorite]").each(function(){t?u.isFavorite(n(this)[0]):n(this).remove()});u.checkListItems(n(".favorites ul"))})};u.isFavorite=function(t){f.length>0&&(f.filter(function(n){return n.ListDataID===parseInt(t.dataset.listdataid)}).length>0?(u.updateCounter(),n(t).addClass("active"),n(t).find(".add.text").hide(),n(t).find(".remove.text").show()):(n(t).removeClass("active"),n(t).find(".add.text").show(),n(t).find(".remove.text").hide()))};u.checkListItems=function(t){n(".favorites .noItems").hide();var i=t.closest("ul");i.find("li").length===0&&(i.remove(),n(".favorites .noItems").show())};u.toggleFavorite=function(i,f){var o={listdataid:parseInt(i.dataset.listdataid)},e=n(i).hasClass("active");n.ajax({method:e?"DELETE":"PUT",url:"/favorite?_="+(new Date).getTime()+"&culture="+n("html").attr("lang"),data:JSON.stringify(o),context:i}).done(function(){var o,s;u.updateCounter();u.getFavorites();n(this).toggleClass("active");e?(n(this).find(".add.text").show(),n(this).find(".remove.text").hide()):(n(this).find(".add.text").hide(),n(this).find(".remove.text").show());i.dataset.showpopup!==r&&(o=n('<div id="favoritepopup" class="favoritePopup"><\/div>').appendTo(i),e?n('<div class="content animated fadeInUp"><span>{0}<\/span><\/div>'.replace("{0}",i.dataset.popupdeleted)).appendTo(o):n('<div class="content animated fadeInDown"><span>{0}<\/span><\/div>'.replace("{0}",i.dataset.popupadded)).appendTo(o),o.show(function(){t.setTimeout(function(){n("#favoritepopup").remove()},2e3)}));e&&n(this).data("delete")!==r&&(s=n(this).closest("ul"),n(this).closest("li").remove(),u.checkListItems(s));typeof f=="function"&&f()})};typeof ko!="undefined"&&ko!==null&&(ko.bindingHandlers.favoriteVisible={init:function(t){var i=n.Deferred();i.done(function(i){i.then(function(i){i||n(t).remove()})});i.resolve(n.getJSON("/favorites/visible"))}});u.init()};Concepts2Go.Cms.Favorites=new u(n)}(jQuery,window,document)