window.onload = function() { var myDivs = document.getElementsByClassName('items'); var myLinks = document.getElementsByClassName('itemhead'); var myAccordion = new fx.Accordion(myLinks, myDivs, {opacity: true, duration: 100}); myAbout = new fx.Height('about', {duration: 425}); myAccordion.showThisHideOpen = function(toShow){ this.elements.each(function(el, i){ if (el.offsetHeight > 0 && el != toShow) this.clearAndToggle(el); }.bind(this)); setTimeout(function(){this.clearAndToggle(toShow) ;}.bind(this), this.options.delay); }; } function activateSearch() { if ($('searchform')) { $('s').value = 'Search...'; // Default text in the search box var o = document.createElement('div'); // Old search results div var n = document.createElement('div'); // New search results div $('searchform').onsubmit = function() { doSearch();return false; }; $('s').onfocus = focusS; // Function to clear the default search box text on focus var s = $('search-results'); var f = $('searchform'); o.id = 'old-search-results'; n.id = 'current-search-results'; s.appendChild(n); s.appendChild(o); o.style.height = '0'; o.style.overflow = 'hidden'; n.style.height = '0'; n.style.overflow = 'hidden'; is_searching = false; } } function doSearch() { // If we're already loading, don't do anything if (is_searching) return false; s = $F('s'); // Same if the search is blank if (s == '' || s == 'Search...') return false; is_searching = true; c = $('current-search-results'); o = $('old-search-results'); o.innerHTML = c.innerHTML; c.style.height = '0'; o.style.height = 'auto'; // Setup the parameters and make the ajax call pars = 's=' + escape(s) + '&ajax'; var myAjax = new Ajax.Request('http://joshuajgreene.com/blog/', {method: 'get', parameters: pars, onComplete:doSearchResponse}); } function doSearchResponse(response) { $('current-search-results').innerHTML = response.responseText; var oldSearch = new fx.Height('old-search-results',{duration: 250}); oldSearch.toggle(); var newSearch = new fx.Height('current-search-results',{duration: 250, onComplete:resetForm}); newSearch.toggle(); } function resetForm() { is_searching = false; } function focusS() { if ($F('s') == 'Search...') $('s').value = ''; } Event.observe(window, 'load', activateSearch, false);