(function($){
	var pos = location.hostname.lastIndexOf('.', location.hostname.lastIndexOf('.') -1);
	var defaults = {
		expires: 3,
		path:    '/',
		domain:  (pos) ? location.hostname.substr(pos +1) : location.hostname,
		secure:  ''
	};

	$.fn.extend({
		toggleLiterature: function(id, aClass, hOption) {
			aId = this.validLiteratureArray(id);

			if ($(this).hasClass(aClass[0])) {
				$(this).removeClass(aClass[0]);
				$(this).addClass(aClass[1]);
				aId.push(id);
			}
			else {
				$(this).removeClass(aClass[1]);
				$(this).addClass(aClass[0]);
			}
				
			id = aId.join(',');
			this.setLiterature(id, hOption);
		},
		validLiteratureArray: function(id) {
			if ($.cookie('lt')) {
				return $.grep($.cookie('lt').split(','), function(n) {
					return (n.match(/[0-9]+/g) == n && n != id);
				});
			}
			else {
				return [];
			}
		},
		setLiterature: function(id, hOption) {
			hOption = $.extend(defaults, hOption);
			$.cookie('lt', id, hOption);
		},
		addLiterature: function(id, hOption) {
			aId = this.validLiteratureArray(id);
			aId.push(id);
			this.setLiterature(aId.join(','), hOption);
		},
		deleteLiterature: function(id, hOption) {
			aId = this.validLiteratureArray(id);
			this.setLiterature(aId.join(','), hOption);
		},
		resetLiterature: function() {
			aId = this.validLiteratureArray();
			for (n in aId) {
				this.deleteLiterature(aId[n]);
			}
		}
	});
})(jQuery);

