var teamscope = { listEntries: null, gridEntries: null, expectedResults: 0, toolbar: function () { teamscope.views(); }, views: function () { $('#toolbar .view .grid').click(function () { var values = teamscope.getFiltersAndCategoryIds('#toolbar .categories li a.selected'); var filters = values.filters; var catURL = ''; if(filters.length > 0) { catURl = '&c=' + filters.join('+'); } var url = '/?v=g' + catURl; url = url.replace(/\/page\/([0-9]+)\//,'/'); window.location.href = url; /*var href = $(this).attr('href'); if ($('#entries').hasClass('grid')) { return false; } if (teamscope.gridEntries === null) { if (teamscope.listEntries === null) { teamscope.listEntries = $('#entries').html(); } $.get(href + "&a=1", function (data) { teamscope.gridEntries = data; $('#entries').html(teamscope.gridEntries); $('#entries').addClass('grid'); }); } else { $('#entries').html(teamscope.gridEntries); $('#entries').addClass('grid'); } $('#toolbar .view .list').removeClass('active'); $('#toolbar .view .grid').addClass('active'); teamscope.setViewCookie('g');*/ return false; }); $('#toolbar .view .list').click(function () { var values = teamscope.getFiltersAndCategoryIds('#toolbar .categories li a.selected'); var filters = values.filters; var catURL = ''; if(filters.length > 0) { catURl = '&c=' + filters.join('+'); } var url = '/?v=l' + catURl; url = url.replace(/\/page\/([0-9]+)\//,'/'); window.location.href = url; /*var href = $(this).attr('href'); if (!$('#entries').hasClass('grid')) { return false; } if (teamscope.listEntries === null) { if (teamscope.gridEntries === null) { teamscope.gridEntries = $('#entries').html(); } $.get(href + "&a=1", function (data) { teamscope.listEntries = data; $('#entries').html(teamscope.listEntries); $('#entries').removeClass('grid'); }); } else { $('#entries').html(teamscope.listEntries); $('#entries').removeClass('grid'); } $('#toolbar .view .grid').removeClass('active'); $('#toolbar .view .list').addClass('active'); teamscope.setViewCookie('l');*/ return false; }); }, /*setViewCookie: function (value) { var name = 'view'; var date = new Date(); if (value == 'l') { date.setDate(date.getDate() - 90); } else { date.setDate(date.getDate() + 90); } var expires = date.toGMTString(); var path = '/'; document.cookie = name + "=" + value + "; expires=" + expires + "; path=" + path; },*/ filterCategories: function () { $('#toolbar .filter .title a').click(function () { if ($('#toolbar .categories').css('display') == 'none') { teamscope.filters.show(); } else { teamscope.filters.hide(); } return false; }); $('#toolbar .cancel').click(function () { teamscope.filters.hide(); return false; }); $('#toolbar .categories li a').click(function () { $(this).toggleClass('selected'); teamscope.updateFilterCount(); return false; }); $('#toolbar .categories .filter-button').click(function () { if ($(this).attr('href') === '#') { return false; } }); }, disableFilter: function () { var button = $('#toolbar .categories .filter-button'); button.attr('href', '#'); button.addClass('disabled'); }, enableFilter: function (url) { var button = $('#toolbar .categories .filter-button'); button.attr('href', url); button.removeClass('disabled'); }, resetFilters: function () { //teamscope.search.reset(); teamscope.disableFilter(); $('#toolbar .categories li a.selected').removeClass('selected'); $('#toolbar .categories .actions .expected').removeClass('loading').text(''); $('#toolbar .categories').slideUp(); }, getFiltersAndCategoryIds: function (links) { var filters = []; var categoryIds = []; $(links).each(function (i, elem) { elem = $(elem); filters.push(elem.attr('rel')); categoryIds.push(elem.attr('id').substring(4)); }); return { filters: filters, categoryIds: categoryIds }; }, updateFilterCount: function () { $('#toolbar .categories .actions .expected').addClass('loading').text(''); var values = teamscope.getFiltersAndCategoryIds('#toolbar .categories li a.selected'); var filters = values.filters; var categoryIds = values.categoryIds; if (teamscope.filterRequest) { teamscope.filterRequest.abort(); } if (teamscope.filterTimeout) { clearTimeout(teamscope.filterTimeout); } if (filters.length > 0) { var message = ''; var url = '/?c=' + filters.join('+'); teamscope.enableFilter(url); //teamscope.search.updateCategoryIds(categoryIds); /*teamscope.filterTimeout = setTimeout(function () { teamscope.filterTimeout = null; teamscope.filterRequest = $.ajax({ url: "/wp-content/themes/teamscope/filter-count.php?" + filters.join('+'), success: function (count) { if (count == 0) { teamscope.disableFilter(); message = '0 Expected Results'; } else if (count == 1) { message = '1 Expected Result'; } else { message = count + ' Expected Results'; } teamscope.expectedResults = count; $('#toolbar .categories .actions .expected').removeClass('loading').html(message); } }); }, 500);*/ } else { //teamscope.search.reset(); teamscope.disableFilter(); $('#toolbar .categories .actions .expected').removeClass('loading').text(''); } } }; teamscope.filters = { show: function () { teamscope.selectedCategories.hide(); $('#toolbar .categories').slideDown(); var title = $('#toolbar .title'); title.addClass('open'); title.find('span').text('Hide'); //title.find('strong').addClass('selected'); return false; }, hide: function () { teamscope.resetFilters(); teamscope.selectedCategories.show(); $('#toolbar .categories').slideUp(); var title = $('#toolbar .title'); title.removeClass('open'); title.find('span').text('Show'); //title.find('strong').removeClass('selected'); return false; }, update: function (categoryIds) { var categories = $('#toolbar .categories'); categories.find('a.selected').removeClass('selected'); $.each(categoryIds, function (index, value) { categories.find('#cat-' + value).addClass('selected'); }); } }; teamscope.selectedCategories = { init: function () { $('#toolbar .selected-categories a.cat').click(function (event) { event.preventDefault(); teamscope.selectedCategories.updatePage(this.id); var li = $(this).parent(); li.fadeOut(function () { li.remove(); //teamscope.search.updateHeight(); }); return false; }); //teamscope.search.filtersHint(); }, updatePage: function (notCategoryId) { teamscope.selectedCategories.loading(); var selector = '#toolbar .selected-categories .cat'; if (notCategoryId != null) { selector += ":not('#" + notCategoryId + "')"; } var values = teamscope.getFiltersAndCategoryIds(selector); var filters = values.filters; var categoryIds = values.categoryIds; //teamscope.search.updateCategoryIds(categoryIds); if (teamscope.selectedCategories.filterRequest) { teamscope.selectedCategories.filterRequest.abort(); } if (teamscope.selectedCategories.filterTimeout) { clearTimeout(teamscope.selectedCategories.filterTimeout); } if (filters.length > 0) { teamscope.selectedCategories.filterTimeout = setTimeout(function () { teamscope.selectedCategories.filterTimeout = null; var url = '/?c=' + filters.join('+'); window.location.href = url; /*teamscope.selectedCategories.filterRequest = $.ajax({ url: url + '&a=1', success: function (data) { $('#toolbar .view .grid').attr('href', url + '?v=g'); $('#toolbar .view .list').attr('href', url + '?v=l'); teamscope.gridEntries = null; teamscope.listEntries = null; $('#entries').html(data); teamscope.selectedCategories.completed(); }, error: function (XMLHttpRequest, textStatus, errorThrown) { var status = XMLHttpRequest.status; if (status == 404) { $('#entries').html('
No results were found for your search.
'); } else { $('#entries').html('There was a problem trying to retrieve the posts. Please try refreshing the page.
'); } $('#toolbar .selected-categories .reset').removeClass('loading'); teamscope.selectedCategories.completed(); } });*/ }, 100); } else { window.location.href = '/'; } }, loading: function () { /*$('#entries').css({ visibility: 'hidden' });*/ $('#toolbar .selected-categories .reset').addClass('loading'); }, completed: function () { $('#entries').hide().css({ visibility: 'visible' }).fadeIn(function () { $('#toolbar .selected-categories .reset').removeClass('loading'); }); }, hide: function () { var selectedCategories = $('#toolbar .selected-categories'); if (selectedCategories.length > 0) { var values = teamscope.getFiltersAndCategoryIds('#toolbar .selected-categories .cat'); teamscope.filters.update(values.categoryIds); teamscope.updateFilterCount(); selectedCategories.hide(); //teamscope.search.updateHeight(); } }, show: function () { var selectedCategories = $('#toolbar .selected-categories'); if (selectedCategories.length > 0) { var values = teamscope.getFiltersAndCategoryIds('#toolbar .selected-categories .cat'); //teamscope.search.updateCategoryIds(values.categoryIds); selectedCategories.fadeIn(); //teamscope.search.updateHeight(); } } }; teamscope.testimonials = { init: function () { var testimonials = $('.testimonials li'); if (testimonials.length > 1) { var array = $.makeArray(testimonials); var num = Math.floor(Math.random() * array.length); testimonials.hide(); $(array[num]).show(); } } }; teamscope.oldBrowserCheck = function () { if ($.browser.msie && parseInt($.browser.version) < 7 && !window.XMLHttpRequest) { $('body').prepend('