/* Michael's Rolling Archives by Michael Heilemann - http://binarybonsai.com */ var asides_pagecount = Math.ceil( 0/3 ); function rollAsides(direction) { if (direction == 1 || direction == -1) { // Update the variables asides_position = asides_position + (direction * asides_offset); asides_pagenumber += direction; } else if (direction == 'home') { // Reset the variables asides_pagenumber = 1; asides_offset = 3; asides_position = 0; } $('rolling-asides-content').innerHTML = '
'; $('rolling-asides-pages').innerHTML = 'page ' + asides_pagenumber + ' of ' + asides_pagecount; // Make sure we don't allow people to go below page 1 if (asides_pagenumber < '2') { $('rolling-asides-next').className = 'inactive'; $('rolling-asides-next').onclick = null; } else { $('rolling-asides-next').className = null; $('rolling-asides-next').onclick = function() { rollAsides(-1); }; } // Make sure we don't allow people to go above pagecount. if (asides_pagenumber >= asides_pagecount) { $('rolling-asides-prev').className = 'inactive'; $('rolling-asides-prev').onclick = null; } else { $('rolling-asides-prev').className = null; $('rolling-asides-prev').onclick = function() { rollAsides(1); }; } // This part requires Prototype (http://prototype.conio.net/) new Ajax.Updater('rolling-asides-content', 'http://al-marayya594.org/wp/wp-content/plugins/k2-rolling-asides/rolling-asides.php', {method: 'get', parameters: 'offset=' + asides_position, onFailure: rollingAsidesError}); } function rollingAsidesError() { $('rolling-asides-content').innerHTML = 'Danger Will robinson! Danger!'; } function initRollAsides() { // Is only run onload. if (asides_pagecount > 0) { // There are posts $('rolling-asides-prev').onclick = function() { rollAsides(1); }; rollAsides('home'); } else { // No aside posts. Turn everything off. $('rolling-asides-content').innerHTML = 'There are no asides.'; $('rolling-asides-next').className = 'inactive'; $('rolling-asides-next').onclick = null; $('rolling-asides-prev').className = 'inactive'; $('rolling-asides-prev').onclick = null; } } // addLoadEvent() // Adds event to window.onload without overwriting currently assigned onload functions. // Function found at Simon Willison's weblog, added by Safirul Alredha. function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { oldonload(); func(); } } } addLoadEvent(initRollAsides); // run initRollArchive onLoad