var $ms = jQuery.noConflict(); $ms(document).ready(function() { $ms('#ts-submit').removeClass('visible').addClass('hidden'); var continents = $ms(".continent"); $ms.each(continents, function(i, n){ $ms(n).click(function() { var contName = $ms(n).attr('id'); $ms('#countryList').html(""); var url = "http://www.theurbangrocer.com/wp-content/plugins/MapSearch/MapSearch.php"; var json_url = "http://www.theurbangrocer.com/wp-content/plugins/MapSearch/MapSearch.php?ajax=1&ajaxcontinent=" + contName; $ms.getJSON(json_url, function(data) { $ms('#search-cont').html(""); $ms('#search-count').html(""); $ms('#searcharea').html(data.continent); $ms('#search-cont').html(data.results); }); var restrictUrl = '?continent=' + contName + '&cr=1'; $ms.post(url, {restrictedUrl: restrictUrl}, function(data){ var restrictAnchor = '(Restrict By Country)'; $ms('#count_restrict').html(restrictAnchor); }); var target = $ms('#countryList'); var targetOffset = target.offset().top - 70; $ms('html,body').animate({scrollTop: targetOffset}, 1000); return false; }); }); $ms('#count_restrict').click(function() { var restrict = -1; var cont = ""; if($ms("#count_restrict a").text()=="(Restrict By Country)"){ $ms("#count_restrict a").text("(Search The Whole Continent)"); restrict = 1; var url = "http://www.theurbangrocer.com/wp-content/plugins/MapSearch/MapSearch.php"; $ms.post(url, {restricted: restrict}, function(data){ $ms('#search-count').html(""); $ms('#countryList').html(data); }); }else{ restrict = -1; $ms("#count_restrict a").text("(Restrict By Country)"); $ms('#countryList').html(""); var json_url = "http://www.theurbangrocer.com/wp-content/plugins/MapSearch/MapSearch.php?restricted=" + restrict; $ms.getJSON(json_url, function(data) { $ms('#search-cont').html(""); $ms('#search-count').html(""); $ms('#searcharea').html(data.continent); $ms('#search-cont').html(data.results); }); } return false; }); $ms('#countryList a').click(function() { var restrict = -1; var cr = $ms(this).html(); alert(cr); $ms('#countryList').html(''); $ms("#count_restrict a").text("(Restrict By Country)"); return false; }); });