$(document).ready(function() {
    var dropDownTimeout;
    var showTimeout;
    $('.mfirst').mousemove(function() {
        clearTimeout(dropDownTimeout);
    }).mouseleave(function() {
       clearTimeout(showTimeout);
       dropDownTimeout = setTimeout(function() {
        $('.drop-menu').fadeOut(300);
       }, 700);
    }).mouseenter(function() {
        showTimeout = setTimeout(function() {
           $('.drop-menu').fadeIn(300);
        }, 400);
    });
    
    $('.drop-menu').mouseenter(function() {
        clearTimeout(dropDownTimeout);
    }).mouseleave(function() {
       clearTimeout(showTimeout);
       dropDownTimeout = setTimeout(function() {
        $('.drop-menu').fadeOut(300);
       }, 700);
    });
});


var itemSelection = {
    color: -1,
    value: 0,
    
    init: function() {
        $('.filterItem').hide().removeClass("b-active");
        $('.filterItem.showDefault').show(300, function() { $(this).addClass("b-active"); })
    },
    selectColor: function(value, e) {
        $('.color1').removeClass('colorSelected');
        $('.color1Link').removeClass('colorSelected');
        $(e).addClass('colorSelected');
        this.color = value;
        this.render();
        return false;
    },
    
    selectValue: function(value) {
        this.value = value;
        this.render();
        return false;
    },
    
    render: function() {
        /* $('.filterItem').css('opacity', 1).css('display', 'block').animate({'opacity': 0}, 300); */
        $('.filterItem').animate({'opacity': 0}, 300, function() { $('.filterItem').removeClass("b-active"); })
        setTimeout(function() {
            $('.filtersNotFound').hide();
            $('.filterItem').hide();
        }, 300);
        var showClass = '.filterItem';
        if (this.color != -1) {
            showClass += '.filterColor' + this.color;
        } else {
            showClass += '.showDefault'
        }
        if (this.value != 0) {
            showClass += '.filterValue' + this.value;
        }
        setTimeout(function() {
            if ($(showClass).length == 0) {
                $('.filtersNotFound').css('opacity', 0).show().addClass("b-active").animate({'opacity': 1}, 300);
            } else {
                $(showClass).css('opacity', 0).show().addClass("b-active").animate({'opacity': 1}, 300);
            }
        }, 400);
        /* $(showClass).show(); */
        return false;
    }
};

function doShowAll(catId) {
    $('.cat' + catId + ':hidden').css('opacity', 0).show().animate({'opacity': 1}, 300)
    
    $('.plustCat' + catId).hide();
    return false;
}
