
(function ($) {
    $.fn.filterable = function (settings) {
        settings = $.extend({
            useHash: true,
            animationSpeed: 250,
            show: {
                width: 'show',
                opacity: 'show'
            },
            hide: {
                width: 'hide',
                opacity: 'hide'
            },
            useTags: true,
            tagSelector: '#filtro-categorias a',
            selectedTagClass: 'activo',
            allTag: 'todos'
        }, settings);

        return $(this).each(function () {
            $(this).bind("filter", function (e, tagToShow) {
                if (settings.useTags) {
                    $(settings.tagSelector).parent().removeClass(settings.selectedTagClass);
                    $(settings.tagSelector + '[href=' + tagToShow + ']').parent().addClass(settings.selectedTagClass)
                }
                $(this).trigger("filteritem", [tagToShow.substr(1)])
            });

            $(this).bind("filteritem", function (e, classToShow) {
                if (classToShow == settings.allTag) {
                    $(this).trigger("show")
                } else {
                    $(this).trigger("show", ['.' + classToShow]);
                    $(this).trigger("hide", [':not(.' + classToShow + ')'])
                }
                if (settings.useHash) {
                    location.hash = '#' + classToShow
                }
            });


            $(this).bind("show", function (e, selectorToShow) {
                $(this).children(selectorToShow).animate(settings.show, settings.animationSpeed)
            });

            $(this).bind("hide", function (e, selectorToHide) {
                $(this).children(selectorToHide).animate(settings.hide, settings.animationSpeed)
            });


            if (settings.useHash) {
                if (location.hash != '') $(this).trigger("filter", [location.hash]);
                else $(this).trigger("filter", ['#' + settings.allTag])
            }

            if (settings.useTags) {
                $(settings.tagSelector).click(function () {
                    $('#filtro-productos').trigger("filter", [$(this).attr('href')]);
                    $(settings.tagSelector).removeClass('activo');
                    $(this).addClass('activo')
                })
            }
        })
    }
})(jQuery);
$(document).ready(function () {
    $('#filtro-productos').filterable();
	$('#linkID').click(function(){
		$('#filtro-productos').trigger('filter', [ '#promocion1' ]);
	});
});


