function filterEvents() { if (window.location.hash.split("#")[1]) { //if there are filters var filters = window.location.hash.split("#")[1].split("&"); $("#events-tab a").each(function() { var display = new Boolean(false); var relArr = $(this).attr("rel").split(" "); $.each(relArr, function(i, v){ if ($.inArray(v, filters)!=-1) { // if the value is in the filters array display = true; } }); if (display == false) $(this).parent().parent().fadeOut(); else $(this).parent().parent().fadeIn(); }); } else { $("#events-tab tr").fadeIn(); } } $(document).ready(function() { if (window.location.hash.split("#")[1]) { var filters = window.location.hash.split("#")[1].split("&"); $.each($(".filters a"), function(i, v) { var category = $(v).attr("href").split("#")[1]; if ($.inArray(category, filters)!=-1) { // if the value is in the filters array $(v).parent().addClass("selected"); } }); } filterEvents(); $(".filters a").each(function() { $(this).click(function(event) { event.preventDefault(); $(this).parent().addClass("selected"); var filter = $(this).attr("href").split("#")[1]; var hash = window.location.hash; if (!hash) { window.location.hash = filter; } else { var arr = hash.split("#")[1].split("&"); var removeIndex = $.inArray(filter, arr); if (removeIndex!=-1) { //if filter is located in array, remove it arr.splice(removeIndex,1); $(this).parent().removeClass("selected"); } else { //else, just add the element in arr.push(filter); } window.location.hash = arr.join("&"); } filterEvents(); }); }); }); $('nav.primary > ul > li > ul a').click(function(e) { return; $('nav.primary >ul > li > ul').fadeOut('fast'); window.location.replace($(e.target).attr('href')); window.location.reload(); });