var componentEmbeds = {
	init: function() {
		if (typeof(swfobject) != 'undefined') {
			// get all component embed divs
			var oaComponentEmbeds = document.getElementsByClassName('component-embed');

			// iterate through all of them
			while (oaComponentEmbeds.length > 0) {
				// get or calculate all necessary data
				var iLengthBeforeEmbed = oaComponentEmbeds.length;
				var saIdMatches = oaComponentEmbeds[0].id.match(/ce-(\d+)-(standalone|live-demo|preview|fullscreen)-(transparent|window)-([\d\w_-]+)/);
				var saClassMatches = oaComponentEmbeds[0].className.match(/^component-embed (.+\.swf)$/);

				if (saIdMatches && saIdMatches[1] && saIdMatches[2] && saIdMatches[3] && saClassMatches && saClassMatches[1]) {
					var iComponentId = saIdMatches[1];
					var sEmbedType = saIdMatches[2];
					var sWmode = saIdMatches[3];
					var sComponentPermalink = saIdMatches[4];
					var sSwfName = saClassMatches[1];

					var pathToSwf = window.serverConfigs.docRoot + '/' + window.serverConfigs.dir.itemsData + '/components/' + sComponentPermalink + '/swfs/' + sEmbedType + '/';
					var width = height = 0;

					switch (sEmbedType) {
						case 'standalone':
							width = 500;
							height = 260;
						break;
						case 'live-demo':
							width = 600;
							height = window.serverConfigs.liveDemoHeight ? window.serverConfigs.liveDemoHeight : 865;
						break;
						case 'preview':
							width = 600;
							height = 300;
						break;
						case 'fullscreen':
							width = '100%';
							height = '100%';
						break;
					}

					// move the text (item preview) from the component embed div to the bottom of the swmt-details (item details) div, if it exists
					var oSwmtDetails = document.getElementById('swmt-details');
					if (oSwmtDetails) {
							for (var i = 0; i < oaComponentEmbeds[0].childNodes.length; i++) {
								oSwmtDetails.appendChild(oaComponentEmbeds[0].childNodes[i].cloneNode(true));
								document.getElementById('component-preview').style.display = 'block';
							}
					}

					// embed swf by replacing the whole component embed div with the embed code
					swfobject.embedSWF(
						pathToSwf + sSwfName,
						oaComponentEmbeds[0].id,
						width, height, '9.0.0', false,
						{ folderPath: pathToSwf },
						{ scale: 'noscale', salign: 'tl', wmode: sWmode, allowScriptAccess: 'always', allowFullScreen: true },
						null
					);

					// in IE, the component embed divs are not replaced with swfs; so after the embed is finished, the placeholder element needs to be removed manually
					if (iLengthBeforeEmbed == oaComponentEmbeds.length) {
						oaComponentEmbeds.splice(0, 1);
					}
				}
			}
		};
	}
};