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).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.isFavorite=function(t){f.length>0&&(f.filter(function(n){return n.ListDataID===parseInt(t.dataset.listdataid)}).length>0?(u.updateCounter(),n(t).toggleClass("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()));var i={listdataid:parseInt(t.dataset.listdataid)}};u.toggleFavorite=function(t,i){var e={listdataid:parseInt(t.dataset.listdataid)},f=n(t).hasClass("active");n.ajax({method:f?"DELETE":"PUT",url:"/favorite?_="+(new Date).getTime()+"&culture="+n("html").attr("lang"),data:JSON.stringify(e),context:t}).done(function(){u.updateCounter();u.getFavorites();n(this).toggleClass("active");f?(n(this).find(".add.text").show(),n(this).find(".remove.text").hide()):(n(this).find(".add.text").hide(),n(this).find(".remove.text").show());f&&n(this).data("delete")!=r&&n(this).parent().remove();typeof i=="function"&&i()})};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)