var Ajax = { referer: false, loadArtistData: function(name) { Search.showSpinner(); name = name.split(' ').join('+'); $.get('/artist/'+ name +'/', function(data){ if (typeof data.status != 'undefined') { if (data.status == 'loading') { Search.showArtistPics(data.pics); setTimeout(function() { Ajax.loadArtistData(name); }, 3000); } else if (data.status == 'corrected') { Ajax.loadArtistData(data.page); } else if (data.status == 'suggestions') { Search.hideSpinner(); Search.showSuggestions(data.values); } else if (data.status == 'error') { Ajax.load404Page(); } return false; } else { Ajax.setArchor('/artist/'+ name +'/'); Pages.renderArtist(data); beathaven.redrawScrollbar(); } }) }, loadSearchPage: function() { $.get('/search.html', function(data){ Ajax.setArchor('/search/'); Pages.renderSearch(data); }) }, loadSettingsPage: function() { $.get('/settings.html', function(data){ Ajax.setArchor('/settings/'); Pages.renderSettings(data); }) }, loadWheePage: function() { $.get('/demo/whee.html', function(data){ $('#data-container .inner').html(data); }) }, load404Page: function() { $.get('/demo/404.html', function(data){ $('#data-container .inner').html(data); beathaven.redrawScrollbar(); }) }, setArchor: function(anchor) { Ajax.referer = Ajax.getAnchor(); window.location.hash = '#'+ anchor; }, getAnchor: function() { return window.location.hash.substring(1); }, setTitle: function(title) { document.title = title +' @ BeatHaven'; }, detectPage: function() { if (m = Ajax.getAnchor().match(/\/artist\/(.+)\//)) { Ajax.loadArtistData(m[1]); } else if (Ajax.getAnchor() === '' || Ajax.getAnchor().match(/\/search\//)) { Ajax.loadSearchPage(); } else if (Ajax.getAnchor().match(/\/settings\//)) { Ajax.loadSettingsPage(); } else { Ajax.load404Page(); } } } $(function(){ $('a.data.artist').live('click', function(){ Ajax.loadArtistData($(this).html()); return false; }); $(window).bind('hashchange', Ajax.detectPage); })