var GenericPopupWindow = Class.create();
GenericPopupWindow.default_width = 600;
GenericPopupWindow.default_height = 500;
GenericPopupWindow.scrolling = false;
GenericPopupWindow.prototype = {
	initialize: function( el ){
		this.el = el;
		this.winCount = 0;
		this.width = ( this.el.hasAttribute('win_width') ? this.el.attributes['win_width'].value : GenericPopupWindow.default_width );
		this.height = ( this.el.hasAttribute('win_height') ? this.el.attributes['win_height'].value : GenericPopupWindow.default_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); } );
}
var GenericPopupWindowCompliant = Class.create({
	initialize: function( el ){
		this.el = el;
		this.default_width = 600;
		this.default_height = 500;
		this.scrolling = false;
		this.winCount = 0;
		
		//super fancy regular expression width and height for popup class. -James
		this.classes = this.el.readAttribute('class');
		if(this.classes != null && this.classes.indexOf('pop_w') > 0){
			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;
		}
		if(this.width == null){
			this.width = ( this.el.hasAttribute('win_width') ? this.el.attributes['win_width'].value : GenericPopupWindow.default_width );
		}
		if(this.height == null){
			this.height = ( this.el.hasAttribute('win_height') ? this.el.attributes['win_height'].value : GenericPopupWindow.default_height );
		}
		this.scrolling = ( this.el.hasAttribute('scrolling') ? this.el.attributes['scrolling'].value : this.scrolling );
		this.scrolling = this.el.hasClassName('scrolling') ? true : this.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 ){}
	}	
});
if(parseFloat(Prototype.Version) >= 1.6) {
	//if we have prototype 1.6 than we use this event because it's faster!
	document.observe("dom:loaded", function() {
		$$( "a.PopupWin" ).each( function(el){ new GenericPopupWindowCompliant(el); } );
	});
} else {
	//otherwise use the old prototype popup that works in pt versions less than 1.6
	Event.observe( window, 'load', GenericPopupWindow.FindPopups );
}
