var Ajax = { loadArtistData: function(name) { $('#search-container input').attr('disabled', 'disabled').blur(); $('#search-container img').show(); name = name.replace(' ', '+'); Ajax.setArchor('/artist/'+ name +'/'); $.get('/artist/'+ name +'/', function(data){ if (typeof data.error != 'undefined') { if (data.error == 'loading') { Ajax.loadArtistData(name); } else if (data.error == 404) { Ajax.load404Page(); } return false; } Pages.renderArtist(data); }) }, loadSearchPage: function() { Ajax.setArchor('/search/'); $.get('/demo/search.html', function(data){ $('#data-container').html(data); }) }, loadWheePage: function() { $.get('/demo/whee.html', function(data){ $('#data-container').html(data); }) }, load404Page: function() { $.get('/demo/404.html', function(data){ $('#data-container').html(data); }) }, setArchor: function(anchor) { window.location = '#'+ anchor; }, getAnchor: function() { var tmp = window.location.href.split('#'); if (typeof tmp[1] !== 'undefined') { return tmp[1]; } return ''; }, detectStartPage: function() { if (m = this.getAnchor().match(/\/artist\/(.+)\//)) { this.loadArtistData(m[1]); } else if (this.getAnchor() === '' || this.getAnchor().match(/\/search\//)) { this.loadSearchPage(); } else { this.load404Page(); } } } $(function(){ $('a.data.artist').live('click', function(){ Ajax.loadArtistData($(this).html()); return false; }); $('.search').live('click', function(){ Ajax.loadSearchPage(); return false; }); $('#search_form').live('submit', function(){ $('.autocomplete-container').remove(); Ajax.loadArtistData($('#search_field').val()); return false; }); })