function centerPopup() {
	var popupBox = $( "popup-box" );
	var popupOverlay = $( "popup-overlay" );
	
	if(popupOverlay)
	{
		popupOverlay.setStyles( {
			"top": window.getScrollTop() + "px", 
			"height": window.getHeight() + "px" 
		} );
	}
	
	if(popupBox)
	{
		popupBox.setStyles( { 
			"top": ( window.getScrollTop() + Math.round( window.getHeight() / 2 - popupBox.getHeight() / 2 ) > 10 ) ? window.getScrollTop() + Math.round( window.getHeight()/2 - popupBox.getHeight()/2 ) : 10,
			"left": Math.round( window.getWidth() / 2 - popupBox.getWidth() / 2 )
		} );
	}
}

function showPopup( url, width, height, noScroll )
{
	var popupOverlay = new Element( "div", { 
		"id": "popup-overlay",
		"styles": {
			"position": "absolute",
			"background": "white",
			"width": "100%",
			"left": "0px",
			"visibility": "hidden",
			"z-index": "99"
		}
	} ).injectInside( document.body );
	
	var popupBox = new Element( "div", {
		"id": "popup-box",
		"styles": {
			"border": "4px solid #3268b2",
			"position": "absolute",
			"background": "white",
			"visibility": "hidden",
			"z-index": "100"
		}
	} ).injectInside( document.body );
	
	var elements = $A( $$( "object" ) );
	var popupOverlayTween = popupOverlay.get( "tween", { 
		property: "opacity", 
		duration: "normal" 
	} );
	
	popupOverlayTween.addEvent( "complete", function() {
	
		var popupIframe = new Element( "iframe", {
			"id": "popup-iframe",
			"src": url,
			"scrolling": ( $chk( noScroll ) ) ? "no" : "auto",
			"width": "100%",
			"height": "100%",
			"styles": {
				"border": 0
			}
		} ).injectInside( popupBox );

		popupIframe.addEvent( "load", function() {
			popupIframe.removeEvents( "load" );
			
			var popupBoxTween1 = popupBox.get( "tween", { duration: "normal" } );
			var popupBoxTween2 = popupBox.get( "tween", { duration: 800, transition: Fx.Transitions.Back.easeOut } );
			var popupBoxTween3 = popupBox.get( "tween", { duration: 800, transition: Fx.Transitions.Back.easeOut } );
			var popupBoxTween4 = popupBox.get( "tween", { duration: 800, transition: Fx.Transitions.Back.easeOut } );
			var popupBoxTween5 = popupBox.get( "tween", { duration: 800, transition: Fx.Transitions.Back.easeOut } );
			
			popupBoxTween1.start( "opacity", 0.0, 1.0 );
			popupBoxTween2.start( "width", 0, width );
			popupBoxTween3.start( "left", Math.round( window.getWidth() / 2 ), Math.round( window.getWidth() / 2 - width / 2 ) );
			popupBoxTween4.start( "height", 0, height );
			popupBoxTween5.start( "top", Math.round( window.getHeight() / 2 ), Math.round( window.getHeight() / 2 - height / 2 ) );
		} );
	
	} );
			
	//var fn = open ? "addEvent" : "removeEvent";
	
	centerPopup();
	
	elements.extend( $$( window.ActiveXObject ? "select" : "embed" ) );
	elements.each( function( el ) { el.style.visibility = "hidden"; } );
	
	window[ "addEvent" ]( "scroll", centerPopup )[ "addEvent" ]( "resize", centerPopup );
	
	popupOverlayTween.start( 0.0, 0.7 );
}

function closePopup() {
	var elements = $A( $$( "object" ) );
	elements.extend( $$( window.ActiveXObject ? "select" : "embed" ) );
	elements.each( function( el ) { el.style.visibility = ""; } );

	$( "popup-box" ).destroy();
	$( "popup-overlay" ).destroy();
}

function showCan( arg ) {
	showPopup( "html/" + arg + ".html", 700, 450, true );
}
