////////////////////////////////////////////////////////////////////
// FILE:         modalsizefixer.js
//------------------------------------------------------------------
// PACKAGE:      modalsizefixer
// NAME:         ModalSizeFixer!
// DESCRIPTION:  ModalSizeFixer! ...fix modal size in Joomla!
// VERSION:      1.0.4
// CREATED:      March 2008
// MODIFIED:     March 2008
//------------------------------------------------------------------
// AUTHOR:       NoNumber! (Peter van Westen)
// E-MAIL:       peter@nonumber.nl
// WEBSITE:      http://www.nonumber.nl
//------------------------------------------------------------------
// COPYRIGHT:    (C) 2008-2010 - NoNumber! - All Rights Reserved
// LICENSE:      http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
////////////////////////////////////////////////////////////////////

if ( typeof SqueezeBox != "undefined" ) {
	SqueezeBox.handlers.iframe = function(url) {
		// >>> ADDED BY : NoNumber! (Peter van Westen)
		// Prevents Modal Window from sizing to more than browser size
			windowWidth = this.options.size.x;
			windowHeight = this.options.size.y;
			if( typeof( window.innerWidth ) == 'number' ) {
				//Non-IE
				windowWidth = window.innerWidth - 16;
				windowHeight = window.innerHeight - 16;
			} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
				//IE 6+ in 'standards compliant mode'
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				//IE 4 compatible
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			maxBoxWidth = this.options.size.x;
			maxBoxHeight = this.options.size.y;
			if(windowWidth) { maxBoxWidth =  windowWidth - (this.options.marginInner.x * 2) }
			if(windowHeight) { maxBoxHeight =  windowHeight - (this.options.marginInner.y * 2) }
			if(maxBoxWidth < this.options.size.x){ this.options.size.x = maxBoxWidth; }
			if(maxBoxHeight < this.options.size.y){ this.options.size.y = maxBoxHeight; }
		// <<< ADDED BY : NoNumber! (Peter van Westen)
		return new Element('iframe', {
			'src': url,
			'frameBorder': 0,
			'width': this.options.size.x,
			'height': this.options.size.y
		});
	};
}