

var Catalog = {
    init: function() {
        this.tooltip();
    },
    productVote: function(e, productId) {
        if (e.preventDefault) {
            e.preventDefault();
        } else {
            e.returnValue = false;
        }

        var likeCount = $('.like' + productId).length;
        if (likeCount < 1) {
            return false;
        }
        var oldVal = 0;
        if (likeCount == 1) {
            oldVal = parseInt($('.like' + productId).text(), 10);
        } else {
            oldVal = parseInt($('.like' + productId).eq(1).text(), 10);
        }
        $.post('frontend/index/vote/format/json', {'product_id': productId}, function(data) {
            if (data.result) {
                $('.like' + productId).text(oldVal+1).fadeOut().fadeIn();
            }}, 'json');
    },
    tooltip: function() {
        if (!$.tools) {
            return;
        }
        $('.selectedTag a').tooltip({
            effect: 'slide',
            offset: [0,0]
        });
        var api = $('.selectedTag a:last').data('tooltip');
        if (!api) {
            return;
        }
        api.show();
        setTimeout(function(){
            api.hide();
            //api.show = function() {};
        }, 5000);
    }
};

$(document).ready(function(){
    Catalog.init();
});
