(function(){
	var PopupWindow = new Class({
		
		setOptions: function(options)
		{
			this.options = Object.extend({
				width: 800,
				height: 580,
				top: 25,
				left: 25,
				scrollbars: 'yes',
				resizable: 'yes',
				status: 'yes',
				toolbar: 'yes',
				location: 'yes',
				menubar: 'yes'
			}, options || {});
		},
		
		initialize: function(aLink, aName, options)
		{
			this.theLink = $(aLink);
			this.theHref = this.theLink.getProperty('href');
			this.theName = aName || '_blank';
			this.setOptions(options);
			
			this.theLink.addEvent('click', function(e){ return this.OpenWin(e) }.bind(this));
		},
		
		OpenWin: function(e)
		{
			var event = (!e) ? window.event : e;
			if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
			
			var theOptions = '';
			for(theOption in this.options)
			{
				theOptions += ","+theOption+"="+this.options[theOption];
			}
			theOptions = theOptions.substring(1,theOptions.length);
			
			var theWin = window.open(this.theHref, this.theName, theOptions);
			if(theWin) theWin.focus();
			return false;
		}
		
	})
	
	SetPopups = function()
	{
		$$('a.popup').each(function(anEl){
			var theRel = anEl.getProperty('rel')
			var theOptions = {};
			var theName = "_blank";
			if(theRel)
			{
				var theSplitRel = theRel.split(";");
				for(var i=0; (theEntry=theSplitRel[i]); i++)
				{
					var thePair = theEntry.split(":");
					if("name"==thePair[0])
					{
						theName = thePair[1];
						continue;
					}
					theOptions[thePair[0]] = thePair[1];
				}
			}
			new PopupWindow(anEl,theName,theOptions);
		});
	}
	window.addEvent('domready',SetPopups);
}());