/* -*- mode: c; tab-width: 8; c-basic-offset: 8 -*- */

var animID = -1;

function doAnim () {
	var str = document.body.style.backgroundPosition;
	var offset = str.substring (0, str.indexOf ('px'));
	offset = (Number (offset) + 1) % 200;
	document.body.style.backgroundPosition = offset + 'px ' + offset + 'px';
}

function startAnim () {
	document.body.style.backgroundPosition = '0px 0px';
	animID = window.setInterval ('doAnim ()', 500);
}

function stopAnim () {
	if (animID != -1) {
		document.body.style.backgroundPosition = '0px 0px';
		window.clearInterval (animID);
		animID = -1;
	}
}

function bookSetActiveStyleSheet(title) {
	setActiveStyleSheet(title);
	if (title == 'Leaves') {
		startAnim ();
	} else {
		stopAnim ();
	}
}

window.onload = function(e) {
	var cookie = cookieRead("style_bookm");
	var title = cookie ? cookie : getPreferredStyleSheet();
	bookSetActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	cookieCreate("style_bookm", title, 365);
}

var cookie = cookieRead("style_bookm");
var title = cookie ? cookie : getPreferredStyleSheet();
bookSetActiveStyleSheet(title);

