var Popup = Class.create( {
	popup: null,
	options: {
		url: null,
		width: 600,
		height: 500,
		name: '_blank',
		location: 'no',
		menubar: 'no',
		toolbar: 'no',
		status: 'yes',
		scrollbars: 'yes',
		resizable: 'yes',
		left: null,
		top: null,
		normal: false,
		center: true,
		focus: true
	},
	initialize: function( element, options )
	{
		Object.extend( this.options, options || {} );
		if ( this.options.normal )
		{
			this.options.menubar = 'yes';
			this.options.status = 'yes';
			this.options.toolbar = 'yes';
			this.options.location = 'yes';
		}
        var el = $( element );
        this.options.url = el.readAttribute( 'href' );
		/*
        //if ( Object.isElement( element ) && this.options.url == null && element.readAttribute( 'href' ) != null )        
        if ( el && this.options.url == null && el.readAttribute( 'href' ) != null )        
		{
			this.options.url = el.readAttribute( 'href' );
            //var hash = $H( element.readAttribute( 'href' ).toQueryParams() );
		}
        */
		this.options.width = this.options.width < screen.availWidth ? this.options.width : screen.availWidth;
		this.options.height = this.options.height < screen.availHeight? this.options.height : screen.availHeight;
	},
	open: function()
	{
		var openoptions = 'width=' + this.options.width + ','
						+ 'height=' + this.options.height + ','
						+ 'location=' + this.options.location + ','
						+ 'menubar=' + this.options.menubar + ','
						+ 'toolbar=' + this.options.toolbar + ','
						+ 'scrollbars=' + this.options.scrollbars + ','
						+ 'resizable=' + this.options.resizable + ','
						+ 'status=' + this.options.status;

		if ( this.options.center )
		{
			this.options.left = ( screen.availWidth - this.options.width ) / 2;
			this.options.top = ( this.options.height - this.options.height ) / 2;
		}
		if ( this.options.top != null )
		{
			openoptions+= ',top=' + this.options.top;
		}
		if ( this.options.left != null )
		{
			openoptions+= ',left=' + this.options.left;
		}        
        //window[ this.options.name ] = this.popup = window.open( this.options.url, this.options.name, openoptions );
        //alert( this.options.url );
        window.open( this.options.url, this.options.name, openoptions );
        /*
		if ( Object.isUndefined( window[ this.options.name ] ) || window[ this.options.name ].closed )
		{
			window[ this.options.name ] = this.popup = window.open( this.options.url, this.options.name, openoptions );
		}
		else
		{
			window[ this.options.name ].location.href = this.options.url;
		}
        */
		//this.popup = window[ this.options.name ];
        /*
		if ( this.popup )
		{
			if ( this.options.focus )
			{
				this.focus();
			}
			return true;
		}
		else
		{
			return false;
		}
        */
	},
	close: function()
	{
		if ( thispopup != null )
		{
			this.popup.close();
			window[ this.options.name ] = null;
		}
	},
	focus: function()
	{
		if ( this.popup != null )
		{
			this.popup.focus();
		}
	}
});
