modalView = function() {

	var defaultPosX = 167;
	var defaultPosY = 112;

	getModalViewDOMElement = function() {
		if (document.getElementById('modalview') == null) {
			var oElement = document.createElement('div');
			oElement.setAttribute('id', 'modalview');
			oElement.innerHTML += '\n\
	<div id="modalview-overlay"></div>\n\
	<table width="100%" height="100%"><tr><td align="center" valign="middle">\n\
	<div id="modalview-content">\n\
		<div id="modalview-close-button" class="close-button"></div>\n\
		<div id="modalview-content-container" class="border"></div>\n\
		<div id="modalview-content-footer"></div>\n\
	</div></td></tr></table>\n\
	';
			document.body.appendChild(oElement);
		}

		return document.getElementById('modalview');
	};

	var oModalView = getModalViewDOMElement();

	getWindowSize = function() {
		var width = 0, height = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			width = document.body.clientWidth;
			height = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			width = document.documentElement.clientWidth;
			height = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			width = document.body.clientWidth;
			height = document.body.clientHeight;
		}

		return {
			'width': width,
			'height': height
		};
	}

	getDocumentWidth = function() {
		if (document.body.scrollWidth)
			return document.body.scrollWidth;
		var w = document.documentElement.offsetWidth;
		if (window.scrollMaxX)
			w += window.scrollMaxX;
		return w;
	};

	getDocumentHeight = function() {
		if (document.body.scrollHeight)
			return document.body.scrollHeight;
		return document.documentElement.offsetHeight;
	};

	setElementAttribute = function(element, attributeName, attributeValue, defaultValue) {
		if (attributeValue != null && typeof attributeValue != 'undefined') {
			element.setAttribute(attributeName, attributeValue);
		} else if (defaultValue != null && typeof defaultValue != 'undefined') {
			element.setAttribute(attributeName, defaultValue);
		}
	};

	createParam = function(paramName, paramValue, defaultValue) {
		var elementValue = '';
		if (paramValue != null && typeof paramValue != 'undefined') {
			elementValue = paramValue;
		} else if (defaultValue != null && typeof defaultValue != 'undefined') {
			elementValue = defaultValue;
		}
		element = document.createElement('param');
		element.setAttribute('name', paramName);
		element.setAttribute('value', elementValue);
		return element;
	}

	getElementTypeFromName = function(filename) {
		getExtension = function(filename) {
			// Filter any ?'s off the filename'
			var index = filename.lastIndexOf('?');
			if (index > -1) {
				filename = filename.substr(0, index);
			}
			index = filename.lastIndexOf('.');
			return (index > -1) ? filename.substr(index + 1, filename.length) : '';
		}

		if (filename.substr(0, 1) == '#') {

			return 'inline';

		} else {

			switch (getExtension(filename)) {
				case 'swf':
					return 'flash';
				case 'bmp': case 'gif': case 'jpeg': case 'jpg': case 'png':
					return 'image';
				case 'asf': case 'asx': case 'avi': case 'mp3': case 'wav': case 'wma': case 'wmv':
					return 'windowsmedia';
				default:
					return 'iframe';
			}

		}

	}

	oModalView.show = function(properties) {
		var modalView = document.getElementById('modalview');
		var modalViewContent = document.getElementById('modalview-content');
		var modalViewContentContainer = document.getElementById('modalview-content-container');
		var modalViewFooter = document.getElementById('modalview-content-footer');

		var elementTypes = {
			'flash': 'embed',
			'windowsmedia': 'embed',
			'image': 'img',
			'iframe': 'iframe'
		};

		if (typeof properties['type'] == 'undefined') {
			properties['type'] = getElementTypeFromName(properties['src']);
		}

		if (typeof properties['footer-text'] != 'undefined' && properties['footer-text'] != '') {
			modalViewFooter.innerHTML = properties['footer-text'];
			modalViewFooter.style.display = 'block';
		} else {
			modalViewFooter.style.display = 'none';
		}

		modalViewContentContainer.className = (properties['border'] == 'true' ? 'border' : 'noborder');

		modalView.style.display = 'block';
		modalViewContent.style.left = '0px';

		if (properties['type'] != 'inline') {
			var element = document.createElement(elementTypes[properties['type']]);

			element.onload = 'window.onresize()';

			setTimeout('window.onresize()', 500);

			switch (properties['type']) {
				case 'flash':
					setElementAttribute(element, 'allowfullscreen', properties['allowfullscreen'], 'true');
					setElementAttribute(element, 'autoplay', properties['autoplay'], 'true');
					setElementAttribute(element, 'height', properties['height']);
					setElementAttribute(element, 'quality', properties['quality'], 'high');
					setElementAttribute(element, 'src', properties['src']);
					setElementAttribute(element, 'type', 'application/x-shockwave-flash');
					setElementAttribute(element, 'width', properties['width']);
					break;
				case 'image':
					setElementAttribute(element, 'alt', properties['alt']);
					setElementAttribute(element, 'width', properties['width']);
					setElementAttribute(element, 'height', properties['height']);
					setElementAttribute(element, 'src', properties['src']);
					break;
				case 'windowsmedia':
					setElementAttribute(element, 'autorewind', 'true');
					setElementAttribute(element, 'autosize', 'true');
					setElementAttribute(element, 'autostart', properties['autostart'], 'true');
					setElementAttribute(element, 'height', properties['height']);
					setElementAttribute(element, 'loop', properties['loop'], 'false');
					setElementAttribute(element, 'pluginspage', 'http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/');
					setElementAttribute(element, 'showcontrols', properties['showcontrols'], 'false');
					setElementAttribute(element, 'showstatusbar', properties['showcontrols'], 'false');
					setElementAttribute(element, 'src', properties['src']);
					setElementAttribute(element, 'type', 'application/x-mplayer2');
					setElementAttribute(element, 'width', properties['width']);
					break;
				case 'iframe':
				default:
					setElementAttribute(element, 'width', properties['width']);
					setElementAttribute(element, 'height', properties['height']);
					setElementAttribute(element, 'frameBorder', 0);
					setElementAttribute(element, 'src', properties['src']);
					break;
			}
		} else {
			var element = document.getElementById(properties['src'].substr(1, properties['src'].length));
			element.oldNextSibling = element.nextSibling;
			element.oldParentNode = element.parentNode;
			element.oldParentNode.removeChild(element);
			element.oldStyleDisplay = element.style.display;
			element.style.display = '';
		}

		modalViewContentContainer.appendChild(element);

		document.getElementById('modalview-close-button').onclick = function() {
			modalView.style.display = 'none';
			stopAutoblend = false;
			element.parentNode.removeChild(element);
			//modalViewContentContainer.innerHTML = '';

			window.onresize = null;

			if (properties['type'] == 'inline') {
				// Return the element to its previous parent
				element.oldParentNode.insertBefore(element, element.oldNextSibling);
				element.style.display = element.oldStyleDisplay;

				// Call onclose handler, if defined
				if (typeof element.onclose == 'function') {
					element.onclose();
				}
			} else {
				// Make sure IE stops playback of any player components
				element.src = '';
				element.filename = '';
			}
		}

		modalViewOverlay = document.getElementById('modalview-overlay');

		window.onresize = function() {
			modalViewOverlay.style.width = Math.max(getWindowSize().width, getDocumentWidth())  + 'px';
			modalViewOverlay.style.height = Math.max(getWindowSize().height, getDocumentHeight()) + 'px';

			modalViewContent.style.left = ((typeof properties.left == 'undefined') ? ((typeof defaultPosX == 'undefined') ? (getWindowSize().width / 2 - modalViewContent.clientWidth / 2) : defaultPosX) : properties.left) + 'px';
			modalViewContent.style.top = ((typeof properties.top == 'undefined') ? ((typeof defaultPosY == 'undefined') ? 140 : defaultPosY) : properties.top) + 'px';
		// was modalViewContent.style.left = ((typeof defaultPosY == 'undefined') ? ((typeof properties.top == 'undefined') ? (getWindowSize().height / 2 - modalViewContent.clientHeight / 2) : properties.top) : defaultPosY) + 'px';
		}

		window.onresize();
		if (typeof element.onshow != 'undefined') {
			element.onshow();
		}
	};

	return oModalView;
};