(function($){
"use strict";
$(document).ready(function (){
$(document).on('click', '.hongo-compare', function(){
var _this=$(this);
$('.hongo-compare-popup').css('visibility','visible').css('opacity','1');
_this.find('.compare-text').text(hongoAddons.compare_added_text);
_this.find('i').attr('data-original-title', hongoAddons.compare_added_text);
var productId=$(this).attr('data-product_id');
if(productId!=''&&productId!=undefined){
var cookie_name='hongo-compare'+hongoAddons.site_id;
var productIds=getHongoAddonsCookie(cookie_name);
if(productIds!=''&&productIds!=undefined){
productIds=productIds.split(',');
if($.inArray(productId, productIds)=='-1'){
productIds.push(productId);
}}else{
productIds=new Array();
productIds.push(productId);
}
setHongoAddonsCookie(cookie_name, productIds, '1');
$.ajax({
type: 'POST',
url: hongoAddons.ajaxurl,
data: {
'action':'compare_details',
'productid':productId
},
beforeSend: function(){
_this.addClass('loading');
},
success:function(response){
if($('#hongo_compare_popup').length > 0){
$('#hongo_compare_popup').html(response);
$(".compare-table li:odd").addClass('odd');
$(".compare-table li:even").addClass('even');
$('.hongo-compare-product-filter-opt').on('click', function(){
if($(this).hasClass('active')){
$(this).removeClass('active');
}else{
$(this).addClass('active');
}});
_this.removeClass('loading');
$('#hongo_compare_popup').imagesLoaded().progress(function(){
var max_height=0;
$('#hongo_compare_popup').find('.content-left ul.compare-table li').each(function(index){
max_height=$(this).height();
$('.content-right .compare-table').find('li:eq(' + index + ')').each(function(i){
if(max_height < $(this).height()){
max_height=$(this).height();
}});
$('.compare-table').find('li:eq(' + index + ')').height(max_height);
});
});
if($.inArray('jquery-magnific-popup', hongoAddons.disable_scripts) < 0){
$.magnificPopup.close();
$.magnificPopup.open({
items: {
src: '#hongo_compare_popup',
type: 'inline'
},
fixedContentPos: true,
mainClass: 'mfp-fade compare-details-popup-wrap hongo-mfp-bg-white hongo-compare-popup',
callbacks: {
elementParse: function(item){
hongoAddonsCompareProductFilterCSS();
hongoAddonsCustomHorizontalScroll('.compare-popup-main-content .content-right');
hongoAddonsCustomVerticalScroll('.compare-popup-main-content');
$(document.body).trigger('hongo_addons_compare_details_open_popup');
}}
});
}}
}});
}});
$(document).on('click', 'a.hongo-compare-product-remove', function(){
var compare_loader=null;
var cart_button_object=$(this);
var productId=cart_button_object.attr('data-product_id');
if(productId!=''&&productId!=undefined){
if(confirm(hongoAddons.compare_remove_message) ){
var cookie_name='hongo-compare'+hongoAddons.site_id;
var productIds=getHongoAddonsCookie(cookie_name);
if(productIds!=''&&productIds!=undefined){
cart_button_object.parents('li.list-details').append('<div class="hongo-loader"></div>');
productIds=productIds.split(',');
productIds.splice(productIds.indexOf(productId), 1);
var cookie_name='hongo-compare'+hongoAddons.site_id;
setHongoAddonsCookie(cookie_name, productIds, '1');
cart_button_object.parents('li').remove();
$('.hongo-compare[data-product_id='+productId+']').find('.compare-text').text(hongoAddons.compare_text);
$('.hongo-compare[data-product_id='+productId+']').find('i').attr('data-original-title', hongoAddons.compare_text);
hongoAddonsCompareProductFilterCSS();
hongoAddonsCustomHorizontalScroll('.compare-popup-main-content .content-right');
hongoAddonsCustomVerticalScroll('.compare-popup-main-content');
if(getHongoAddonsCookie(cookie_name).length==0&&$.inArray('jquery-magnific-popup', hongoAddons.disable_scripts) < 0){
$('#hongo_compare_popup').magnificPopup('close');
}
cart_button_object.find('.hongo-loader').remove();
}}
}});
$(document).on('click', 'a.hongo-popup-cart-button', function(){
var cart_button_object=$(this);
var productId=cart_button_object.attr('data-product_id');
if(productId!=''&&productId!=undefined){
setTimeout(function(){
cart_button_object.parents('li').find('.hongo-popup-cart-button').fadeOut();
}, 100);
}});
$(document).on('click', '.hongo-compare-filter', function(){
var filter_button_object=$(this);
var $checkboxes=$('.hongo-compare-product-filter-opt.active');
var countCheckedCheckboxes=$checkboxes.length;
if(countCheckedCheckboxes >=2){
if(!($('.compare-error-msg').hasClass('display-none')) ){
$('.compare-error-msg').addClass('display-none');
}
filter_button_object.parents('.hongo-compare-popup').find('.list-details').addClass('display-none');
$.each($($checkboxes), function(){
$(this).parents('.list-details').removeClass('display-none');
});
hongoAddonsCompareProductFilterCSS();
if($.inArray('hongo-mcustomscrollbar', hongoAddons.disable_scripts) < 0){
$(".compare-popup-main-content .content-right").mCustomScrollbar("update");
}}else{
$('.compare-error-msg').removeClass('display-none');
clearTimeout(filter_link);
filtermessage();
}});
$(document).on('click', '.hongo-compare-reset', function(){
$('ul.compare-lists-wrap li').removeClass('display-none');
$('.hongo-compare-product-filter-opt').removeClass('active');
$('.compare-popup-main-content .content-right').css('width', '');
hongoAddonsCompareProductFilterCSS();
if($.inArray('hongo-mcustomscrollbar', hongoAddons.disable_scripts) < 0){
$(".compare-popup-main-content .content-right").mCustomScrollbar("update");
}});
$(document).on('hongo_quick_view_product_details_open_popup', function(){
hongoAddonsCompareProductFilterCSS();
hongoAddonsCustomHorizontalScroll('.compare-popup-main-content .content-right');
});
var filter_link=null;
function filtermessage(){
filter_link=setTimeout(function(){
$('.compare-error-msg').addClass('display-none');
}, 3000);
}});
function hongoAddonsCompareProductFilterCSS(){
var t=$('.compare-lists-wrap'),
tW=0;
$('li.list-details:not(.display-none)', t).each(function(){
tW +=$(this).outerWidth(true);
});
t.css('width', tW + t.outerWidth(true) - t.width());
}
function hongoAddonsCustomHorizontalScroll(key){
if(typeof key==="undefined"||key===null||key===''){
key='.compare-popup-main-content .content-right, .top-sidebar-scroll, .size-guide-content';
}
if($.inArray('hongo-mcustomscrollbar', hongoAddons.disable_scripts) < 0){
$(key).mCustomScrollbar({
axis:"x",
scrollInertia: 100,
scrollButtons:{
enable:false
},
keyboard:{
enable: true
},
mouseWheel:{
enable:false,
scrollAmount:200
},
advanced:{
updateOnContentResize:true, 
autoExpandHorizontalScroll:true, 
}});
}}
function hongoAddonsCustomVerticalScroll(key){
if(typeof key==="undefined"||key===null||key===''){
key='.compare-popup-main-content';
}
if($.inArray('hongo-mcustomscrollbar', hongoAddons.disable_scripts) < 0){
$(key).mCustomScrollbar({
axis:"y",
scrollInertia: 100,
scrollButtons:{
enable:false
},
keyboard:{
enable: true
},
mouseWheel:{
enable:true,
scrollAmount:200
},
advanced:{
updateOnContentResize:true, 
autoExpandHorizontalScroll:true, 
}});
}}
function setHongoAddonsCookie(cname, cvalue, exdays){
var d=new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires=(exdays!=0&&exdays!='') ? d.toUTCString():0;
document.cookie=cname + "=" + cvalue + ";expires=" + expires + ";path=/";
}
function getHongoAddonsCookie(cname){
var name=cname + "=";
var decodedCookie=decodeURIComponent(document.cookie);
var ca=decodedCookie.split(';');
for(var i=0; i <ca.length; i++){
var c=ca[i];
while (c.charAt(0)==' '){
c=c.substring(1);
}
if(c.indexOf(name)==0){
return c.substring(name.length, c.length);
}}
return "";
}})(jQuery);