
// Let's figure out how busy you've been...
// var pagecount = Math.ceil(269 / 10);

function rollArchive(direction) {
	if (direction == 1 || direction == -1) {
		pagenumber += direction;
		new Effect.Appear('rollload', {duration: .2});
	} else if (direction == 'home') {
		pagenumber = 1;
	}

	checkRollingElements();


		new Ajax.Updater({success: 'primarycontent'}, 'http://www.keditasmasi.com/wp-content/themes/3k2redux/theloop.php', {method: 'get', parameters: 'paged='+pagenumber+'&rollingarchives=1', onSuccess: rollSuccess, onFailure: rollError});

}


function rollGotoPage(gotopage) {
	pagenumber = (gotopage - 1);
	rollArchive(1);
}


function rollSuccess() {
	rollRemoveLoad();
	if (pagenumber > 1) {								// If we've moved into the archives,
		setCookie('rollpage', pagenumber);				// set a cookie so we can return to that page.
	} else if (pagenumber = 1) {
		deleteCookie('rollpage');
	}
}


function rollError() {
	$('rollnotices').innerHTML = 'Error! <a href="javascript:initRollingArchives()">Reset</a>';
}


function rollRemoveLoad() {
	new Effect.Fade('rollload', {duration: .2});
}


// Needs to be run when a direction is picked, but not when you click the link the notice provides. FIX IT
function rollRemoveNotices() {
	new Effect.Fade($('rollnotices'));
	$('rollnotices').innerHTML = null;
}


function checkRollingElements() {
$('rollpages').innerHTML = pagenumber+'/'+pagecount;
}


function initRollingArchives() {
	pagenumber = 1;

 	checkRollingElements();
	rollRemoveLoad();

	/*if (getCookie('rollpage') != null) {
		$('rollnotices').innerHTML = 'This session you were last seen on <a href="javascript:rollGotoPage('+getCookie('rollpage')+');">page '+getCookie('rollpage')+'</a>. <img src="http://www.keditasmasi.com/wp-content/themes/3k2redux/images/transparent.gif" alt="Reset" onclick="Effect.Fade($(\'rollnotices\')); deleteCookie(\'rollpage\');" />';
		new Effect.Highlight('rollnotices');
	} else {
		$('rollnotices').style.display = 'none';
	}*/

	$('rollnotices').style.display = 'none';

	if (pagecount > 1) {

	} else {
		$('rollingarchives').style.display = 'none';
	}

	$('rollingarchives').style.display = null;  // Show Rolling Archives
}


// Initialize the Rolling Archives
Event.observe(window, 'load', initRollingArchives, false);
