(function(d){if(d){var m=[null,null,null,null,null,null],j=0,n="",c="",p="",l="",e="",h="",b="",o="",a=false;var k=function(){if(a){return}var s=p;if(j>0){s+=" ("+j+")"}var r=jQuery(".compareButton");r.attr("title",s);r.each(function(){jQuery(this)[0].disabled=false});var q=jQuery("#compareItemsButton");q.html(s);q.each(function(){jQuery(this)[0].disabled=(j<2)});jQuery("#clearComparedItemsButton").each(function(){jQuery(this)[0].disabled=(j<2)});if(j>0){jQuery("#compareItems").show()}else{jQuery("#compareItems").hide()}};var i=function(q){m=[null,null,null,null,null,null];j=0;n=q.emptyImgSrc;c=q.emptyImgAlt;p=q.baseButtonLabel;l=q.confirmation;e=q.openUrl;h=q.openHelpUrl;b=q.addUrl;o=q.removeUrl;k()};var g=function(r){var q=j;m[q]={id:r.id,category:r.category,boxId:r.boxId};j++;return q};var f=function(q){jQuery("#compareItemsProduct"+q.index).each(function(){var r=jQuery(this)[0];r.src=q.src;r.alt=q.alt});jQuery("#compareItemsClear"+q.index).show()};d.compare={initialize:function(r){i(r);for(var s=0;s<3;s++){jQuery("#compareItemsClear"+s).click(new Function("app.compare.removeProduct({index: "+s+"})"))}jQuery("#compareItemsButton").click(function(){window.location.href=r.openUrl});jQuery(".compareButton").click(function(){window.location.href=r.openUrl});jQuery("#clearComparedItemsButton").click(function(){a=true;jQuery("#compareItems").hide();for(var w=j-1;w>=0;w--){d.compare.removeProduct({index:w})}a=false;k()});var t=jQuery("input:checkbox[checked]");var v=function(w){for(var x=0;x<t.length;x++){var y=jQuery(t[x]).data("data");if(y!=null&&y.id===w){return y.boxId}}};for(var s=0;s<r.products.length;s++){var u=r.products[s];var q=g({id:u.id,category:u.category,boxId:v(u.id)});f({index:q,src:u.imgSrc,alt:u.imgAlt})}k()},addProduct:function(s){if(j>=3){if(!confirm(l)){jQuery("#"+s.boxId).each(function(){jQuery(this)[0].checked=false});return}d.compare.removeProduct({index:0})}var q=function(){var t=g(s);jQuery(s.img).each(function(){var u=jQuery(this)[0];f({index:t,src:u.src,alt:u.alt})});k()};var r=function(){jQuery("#"+s.boxId).each(function(){jQuery(this)[0].checked=false})};jQuery.ajax({type:"POST",url:b,data:{pid:s.id,cgid:s.cgid},dataType:"json",success:function(t){if(t.success===true){q()}else{r()}},failure:function(t){r()}})},getProductCount:function(q){var r;jQuery.ajax({type:"POST",url:q,data:"",dataType:"json",success:function(s){if(s.success===true){r=s.count}else{r=0}},failure:function(s){r=0}});return r},removeProduct:function(u){var t=null;if(u.index!=null){t=u.index}else{for(var v=0;v<j;v++){if(m[v].id===u.id){t=v}}}var s=m[t];var r=function(){for(var x=t;x<j-1;x++){m[x]=m[x+1];jQuery("#compareItemsProduct"+(x+1)).each(function(){var y=jQuery(this)[0];jQuery("#compareItemsProduct"+x).each(function(){var z=jQuery(this)[0];z.src=y.src;z.alt=y.alt})})}var w=j-1;m[w]=null;j--;jQuery("#"+s.boxId).each(function(){jQuery(this)[0].checked=false});jQuery("#compareItemsProduct"+w).each(function(){var y=jQuery(this)[0];y.src=n;y.alt=c});jQuery("#compareItemsClear"+w).hide();k()};var q=function(){jQuery("#"+s.boxId).each(function(){jQuery(this)[0].checked=true})};jQuery.ajax({type:"POST",url:o,data:{pid:s.id,cgid:s.cgid},dataType:"json",async:false,success:function(w){if(w.success===true){r()}else{q()}},failure:function(w){q()}})}}}else{alert("app namespace is not loaded yet!")}})(app);
