/*
Script: Cookie.js
	Class for creating, loading, and saving browser Cookies.

License:
	MIT-style license.

Credits:
	Based on the functions by Peter-Paul Koch (http://quirksmode.org).
*/

var Cookie = new Class({

	Implements: Options,

	options: {
		path: false,
		domain: false,
		duration: false,
		secure: false,
		document: document
	},

	initialize: function(key, options){
		this.key = key;
		this.setOptions(options);
	},

	write: function(value){
		value = encodeURIComponent(value);
		if (this.options.domain) value += ';domain=' + this.options.domain;
		if (this.options.path) value += ';path=' + this.options.path;
		if (this.options.duration){
			var date = new Date();
			date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000);
			value += ';expires=' + date.toGMTString();
		}
		if (this.options.secure) value += ';secure';
		this.options.document.cookie = this.key + '=' + value;
		return this;
	},

	read: function(){
		var value = this.options.document.cookie.match('(?:^|;)\\s*' + this.key.escapeRegExp() + '=([^;]*)');
		return (value) ? decodeURIComponent(value[1]) : null;
	},

	dispose: function(){
		new Cookie(this.key, $merge(this.options, {duration: -1})).write('');
		return this;
	}

});

Cookie.write = function(key, value, options){
	return new Cookie(key, options).write(value);
};

Cookie.read = function(key){
	return new Cookie(key).read();
};

Cookie.dispose = function(key, options){
	return new Cookie(key, options).dispose();
};



/*** our code - the Sizer ***/

var Sizer = {
	normal:  function() { this._resize(11); },
	bigger:  function() { this._resize(14); },
	biggest: function() { this._resize(17); },

	_resize: function(pixNum) {
		document.body.style.fontSize = pixNum + 'px';
		Cookie.dispose('Sizer');
		Cookie.write('Sizer', pixNum, {duration: 0, domain: 'www.cluks-forum-bw.de', path: '/' } );
	},
	
	_restore: function() {
		var pixNum = Cookie.read('Sizer');
		if (pixNum > 0) {
			this._resize(pixNum);
		}
	}
};

window.addEvent('domready', function() { Sizer._restore(); } );




/* in the have a look - list selects all forums of a category */
function subselectForums(categoryId, subForums) {
	var checkbox = $('havealook-cat-' + categoryId);
	subForums.each(function(forumId) {
		if (forumId == 0) return;
		var forum = $('havealook-forum-' + forumId);
		if (!forum) {
			return;
		}
		if (checkbox.checked) {
			forum.checked = 'checked';
		} else {
			forum.checked = false;
		}
	});
}

function unselectCategory(categoryId, forumId) {
	if ($('havealook-forum-' + forumId).checked == false) {
		$('havealook-cat-' + categoryId).checked = false;
	}
}
