var popupWindow = new Class({
	options: {
		auto: true
	},
	initialize: function(options){
		this.setOptions(options);
		if(new String(self.location).match(/_popup/)){
			$$('body').toggleClass('popup');
		}
		if(! this.options.auto) return;
		$$('a[rel]').each(function(el){
			this.setLink(el);
		}.bind(this));
	},
	setLink: function(el){
		if(el.rel.match(/^popup(?:\[\d+?,\d+?\])?$/)){
			el.addEvent('click', function(e){ this.popup(e,el) }.bind(this) );
		}
	},
	popup: function(e,el){
		if(el.rel.match(/^popup(?:\[(\d+?),(\d+?)\])?$/)){
			var w = RegExp.$1 ? RegExp.$1 : 500;
			var h = RegExp.$2 ? RegExp.$2 : 500;
			window.open(el.href, 'popup', 'toolbar=yes,location=yes,directories=no,menubar=yes,scrollbars=yes,resizable=yes,width='+w+',height='+h).focus();
		}
		if(e.preventDefault){
			e.preventDefault();
			e.stopPropagation();
		}else{
			e.returnValue  = false;
			e.cancelBubble = true;
		}
	}
});
popupWindow.implement(new Options);
