var GenericPopupWindow = Class.create();
GenericPopupWindow.default_width = 600;
GenericPopupWindow.default_height = 500;
GenericPopupWindow.scrolling = false;
GenericPopupWindow.prototype = {
	initialize: function( el ){
		this.el = el;
		//super fancy regular expression width and height for popup class. -James
		this.classes = this.el.readAttribute('class');
		if(this.classes != null){
			var myRe = /(pop_w_)[0-9]*/; //looks for a class name like pop_w_300 to set width to 300
			var myRe2 = /(pop_h_)[0-9]*/; //looks for a class name like pop_h_300 to set width to 300
			var tempRe = myRe.exec(this.classes);
			var tempRe2 = myRe2.exec(this.classes);
			if(tempRe != null && tempRe2 != null){
				this.width = tempRe[0].replace(tempRe[1],'');
				this.height = tempRe2[0].replace(tempRe2[1],'');
			} else {
				this.width = null;
				this.height = null;
			}
		} else {
			this.width = null;
			this.height = null;
		}
		this.winCount = 0;
		this.widthHeight = (this.el.hasAttribute('rel') ? this.el.attributes['rel'].value : String(GenericPopupWindow.default_width) + "x" + String(GenericPopupWindow.default_height)).split('x');
		if(this.width == null){
			this.width = ( this.el.hasAttribute('rel') ? this.widthHeight[0] : this.el.readAttribute('win_width') );
		}
		if(this.height == null){
			this.height = ( this.el.hasAttribute('rel') ? this.widthHeight[1] : this.el.readAttribute('win_height') );
		}
		this.scrolling = ( this.el.hasAttribute('scrolling') ? this.el.attributes['scrolling'].value : GenericPopupWindow.scrolling );
		Event.observe( this.el, 'click', this.clicked.bindAsEventListener( this ) );
	},
	clicked: function( event ){
		if(this.scrolling == '1'){
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1,scrollbars=1");
		} else {
			window.open(this.el.href, "win"+this.winCount++, "width="+this.width+",height="+this.height+",resizable=1");
		}
		try{
			Event.stop( event );
		}catch( e ){}
	}
}

GenericPopupWindow.FindPopups = function(){
	$$( "a.PopupWin" ).each( function(el){ new GenericPopupWindow(el); } );
}

Event.observe( window, 'load', GenericPopupWindow.FindPopups );
