var pAndD;
function popWrapper() {
	var data = $A( arguments );
	pAndD = new PopAndDim( data[4], data[5] );
	pAndD.showDark();
	var pd = new PopDiv( data[1], data[2], data[3], data[5], data[6], data[7] );
	pAndD.addPopDiv( pd );
} 
function PopAndDim( opacity, transitionTime ) {
	if ( opacity < 0 ) this.opacity = 0;
	else if ( opacity > 1 ) this.opacity = 1;
	else this.opacity = opacity;
	this.transitionTime = transitionTime;
	this.curZ = 9999;
	this.dark = (function() {
		var dims = xDocSize();
		var d = new Element( 'div', {id:'darkDiv'} );
		d.setStyle( {  position:'absolute', 
			overflow:'hidden', 
			zIndex:'9999', 
			top:'0px', 
			left:'0px', 
			backgroundColor:'#000', 
			height:dims.h + 'px', 
			width:dims.w + 'px', 
			'z-index':this.curZ} );
		document.body.appendChild( d );
		d.hide();
		return d;
		})();
	this.popColl = new Array();
}
PopAndDim.prototype.showDark = function() { 
	var dims = xDocSize();
	this.dark.setStyle( {height:dims.h + 'px', width:dims.w + 'px'} );
	Effect.Appear( this.dark, {to:this.opacity, duration:this.transitionTime} ); 
}
PopAndDim.prototype.hideDark = function() {
	if ( this.popColl.length == 0 ) {
		Effect.Fade( this.dark, {duration:this.transitionTime} );
	}
}
PopAndDim.prototype.refreshDark = function() {
	var dims = xDocSize();
	this.dark.setStyle( {height:dims.h + 'px', width:dims.w + 'px'} );
}
PopAndDim.prototype.addPopDiv = function( aPopDiv ) {
	this.popColl.push( aPopDiv );
	aPopDiv.pop.setStyle( {zIndex:++this.curZ} );
	document.body.appendChild( aPopDiv.pop );
	this.aPopDiv = aPopDiv;
	PopDiv.position( aPopDiv );
	aPopDiv.pop.hide ();
}
PopAndDim.prototype.hidePopDiv = function( aPopDiv ) {
	aPopDiv.hidePop();
	for ( var i=0; i<this.popColl.length; i++ ) {
		if ( this.popColl[i].content.id == aPopDiv.content.id ) this.popColl.splice( i, 1 );
	}
	this.hideDark();
}
PopAndDim.prototype.removePopDiv = function( aPopDiv ) {
	aPopDiv.hidePop();
	aPopDiv.pop.remove();
	for ( var i=0; i<this.popColl.length; i++ ) {
		if ( this.popColl[i].content.id == aPopDiv.content.id ) this.popColl.splice( i, 1 );
	}
	this.hideDark();
}
PopAndDim.prototype.scanPopDivColl = function ( aString ) {
	for ( var i = 0; i < this.popColl.length; i++ ) {
		if ( this.popColl [ i ].content.id == aString ) return pAndD.popColl [ i ]; 
	}
	return null;
} 
function xDocSize () {
	var b = document.body
	var e = document.documentElement;
	var esw = 0, eow = 0, bsw = 0, bow = 0, esh = 0, eoh = 0, bsh = 0, boh = 0;
	if ( e ) {
		esw = e.scrollWidth;
		eow = e.offsetWidth;
		esh = e.scrollHeight;
		eoh = e.offsetHeight;
	}
	if ( b ) {
		bsw = b.scrollWidth;
		bow = b.offsetWidth;
		bsh = b.scrollHeight;
		boh = b.offsetHeight;
	}
	return { w : Math.max ( esw, eow, bsw, bow ), h : Math.max ( esh, eoh, bsh, boh ) };
}
function PopDiv ( aHeight, aWidth, someContent, aTime, ajaxDiv, ajaxUrl ) {
	var _l1 = this;
	this.height = aHeight;
	this.width = aWidth;
	this.content = someContent;
	this.ajaxDiv = ajaxDiv;
	this.ajaxUrl = ajaxUrl;
	this.transTime = aTime;
	this.pop = new Element ( 'div' );
	this.pop.setStyle ( { position : 'absolute', background : '#fff', width : this.width + 'px' } );
	this.pop.writeAttribute ( { id : this.pop.identify () } );
	this.pop.appendChild ( this.content );
	this.content.show ();
	var pop = this.pop;
	var onLoad = function ( e )
	{
		//Effect.ScrollTo ( pop );
		PopDiv.position ( pAndD.aPopDiv );
		pop.show ();
	};
	var updater = new Ajax.Updater ( this.ajaxDiv, this.ajaxUrl, { method : 'get', evalScripts : true, onComplete : onLoad } );
}
PopDiv.position = function ( aPopDiv ) {
	var vpScrollOffs = document.viewport.getScrollOffsets ();
	var vpDims = document.viewport.getDimensions ();
	var popDims = aPopDiv.pop.getDimensions ();
	var l = vpScrollOffs [ 0 ] + ( vpDims.width - popDims.width ) / 2;
	var t = vpScrollOffs [ 1 ] + ( vpDims.height - popDims.height ) / 2;
	aPopDiv.pop.setStyle ( { left : l + 'px' } );
	if ( popDims.height > vpDims.height ) {
		aPopDiv.pop.setStyle ( { top : '35px' } );
		$ ( 'darkDiv' ).setStyle ( { position : 'fixed' } );
	} else {
		aPopDiv.pop.setStyle ( { top : t + 'px' } );
		$ ( 'darkDiv' ).setStyle ( { position : 'absolute' } );
	}
}
PopDiv.prototype.showPop = function () {
	//var updater = new Ajax.Updater ( this.ajaxDiv, this.ajaxUrl, { method : 'get', evalScripts : true } );
	//this.pop.show ();
}
PopDiv.prototype.hidePop = function () {
	this.pop.hide ();
}