function alerter(expr) {
	var w = window.open("about:blank");
	w.document.innerHtml = "<p>" + expr + "</p>";
}



function testActiveX() {
	var player;
	var hasActiveX=false;
	try {
		if (window.ActiveXObject) { 
			hasActiveX = true; 
			player = new ActiveXObject("WMPlayer.OCX.7");
		}
	}
	catch (oError) { }
	return hasActiveX;
}

function testGeckoActiveX() {
	var player;
	var hasActiveX=false;
	try {
		if (window.GeckoActiveXObject) { 
			hasActiveX = true; 
			player = new GeckoActiveXObject("WMPlayer.OCX.7");
		}
	}
	catch (oError) { }
	return hasActiveX;
}

function testforactivex () {
	var player;
	var plugin;
	var hasActiveX=false;
	try {
		if (window.ActiveXObject) { 
			hasActiveX = true; 
			player = new ActiveXObject("WMPlayer.OCX.7");
		} 
		else if (window.GeckoActiveXObject){ 
			hasActiveX = true;
			player = new GeckoActiveXObject("WMPlayer.OCX.7");
		}
	}
	catch (oError) { } 
	try	{
		if (navigator.mimeTypes) { 
			plugin = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin; 
		}
	}
	catch (oError) { } 
	var message = "Your browser does" + (hasActiveX ? "" : " not") + " support ActiveX.\n"; 
	message += "The Windows Media Player ActiveX control is"+ (player ? "" : " not") +" installed.\n"; 
	message += "The Windows Media Player Plugin "+ (plugin ? "is" : "is not") +" installed.\n"; 
	alert(message); 
}

function videoblock_onclick(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3)
		targ = targ.parentNode;
	while (targ.tagName != "A")
		targ = targ.parentNode;

	var x = document.getElementById("blockvideoshow_vobject_" + targ.id.substr(targ.id.length - 2));
	if (x == null)
		return true;
	if (x.style.display != "" && x.style.display != "block")
		x.style.display = "";
	if (x.style.visibility != "" && x.style.visibility != "visible")
		x.style.visibility = "";
	switch (targ.id.substr(0, targ.id.length - 2)) {
		case "blockvideoshow_vplay_":
			x.controls.play();
			break;
		case "blockvideoshow_vpauze_":
			x.controls.pause();
			break;
		case "blockvideoshow_vstop_":
			x.controls.stop();
			break;
		default:
			return true;
	}
	return false;
}

function video_init() {
	var elmsDiv = document.getElementsByTagName("object");
	var arrsBlockID = new Array();
	for (var i = 0; i < elmsDiv.length; i++)
	{
		var re = /blockvideoshow_vobject_(\S+$)/gm;
		var res = re.exec(elmsDiv[i].id);
		//alert(elmsDiv[i].id + " - " + res);
		if (res != null)
			arrsBlockID.push(res[1]);
	}
	for (var i = 0; i < arrsBlockID.length; i++) {
		var videoblock_play = document.getElementById("blockvideoshow_vplay_" + arrsBlockID[i]);
		videoblock_play.onclick = videoblock_onclick;
		var videoblock_pauze = document.getElementById("blockvideoshow_vpauze_" + arrsBlockID[i]);
		videoblock_pauze.onclick = videoblock_onclick;
		var videoblock_stop = document.getElementById("blockvideoshow_vstop_" + arrsBlockID[i]);
		videoblock_stop.onclick = videoblock_onclick;
	}
	return false;
}

var UMO = {

	requiredAttrParams: ["movie", "width", "height"],
	optionalAttrEmb: [],
	optionalAttrObj: ["id", "align", "style"],
	//optionalAttrParams: ["AutoStart", "AutoSize", "DisplaySize", "TransparentAtStart", "EnableContextMenu", "ShowControls", "ShowStatusBar", "animationatstart"],
	optionalAttrParams: ["autoStart", "stretchToFit", "windowlessVideo", "enableContextMenu", "uiMode"],

	is_w3cdom: (typeof document.getElementById != "undefined" && typeof document.getElementsByTagName != "undefined" && (typeof document.createElement != "undefined" || typeof document.createElementNS != "undefined")),

	foList: [],
	eventFunction: null,

	testActiveX: function() {
		var player;
		var hasActiveX=false;
		try {
			if (window.ActiveXObject) { 
				hasActiveX = true; 
				player = new ActiveXObject("WMPlayer.OCX.7");
			}
		}
		catch (oError) { }
		return hasActiveX;
	},

	testGeckoActiveX: function() {
		var player;
		var hasActiveX=false;
		try {
			if (window.GeckoActiveXObject) { 
				hasActiveX = true; 
				player = new GeckoActiveXObject("WMPlayer.OCX.7");
			}
		}
		catch (oError) { }
		return hasActiveX;
	},

	create: function(FO, id, eventFunction) {
		if (!UMO.is_w3cdom) return;
		UMO.foList[id] = UMO.updateFO(FO);
		UMO.createStyleRule("#" + id, "visibility:hidden;");
		UMO.domLoad(id);
		if (typeof(eventFunction) == "function")
			UMO.eventFunction = eventFunction;
	},

	updateFO: function(FO) {
		if (typeof FO.xi != "undefined" && FO.xi == "true") {
			if (typeof FO.ximovie == "undefined") FO.ximovie = UMO.ximovie;
			if (typeof FO.xiwidth == "undefined") FO.xiwidth = UMO.xiwidth;
			if (typeof FO.xiheight == "undefined") FO.xiheight = UMO.xiheight;
		}
		else {
			FO.xi = false;
		}
		FO.domLoaded = false;
		return FO;
	},

	domLoad: function(id) {
		var timer = setInterval(function() { // doesn't work in IE/Mac
			if((document.getElementsByTagName("body")[0] != null || document.body != null) &&  document.getElementById(id) != null) {
				UMO.main(id);
				clearInterval(timer);
			}
		}, 250);
		if (typeof document.addEventListener != "undefined") {
			document.addEventListener("DOMContentLoaded", function() { UMO.main(id); clearInterval(timer); } , null); // Mozilla only
		}
	},

	main: function(id) {
		var FO = UMO.foList[id];
		if (FO.domLoaded) return; // for Mozilla, only execute once
		UMO.foList[id].domLoaded = true;
		//document.getElementById(id).style.visibility = "hidden";
		if (UMO.hasRequiredAttrParams(id)) {
			UMO.writeFlashObject(id);
		}
		//var xx = document.getElementById(id);
		//alert(xx.id);
		document.getElementById(id).style.visibility = "visible";
		if (UMO.eventFunction != null)
			UMO.eventFunction();
	},

	createStyleRule: function(selector, declaration) {
		return;
		if (UMO.is_ie && UMO.is_mac) return; // bugs in IE/Mac
		var head = document.getElementsByTagName("head")[0]; 
		var style = UMO.createElement("style");
		if (!(UMO.is_ie && UMO.is_win)) {
			var styleRule = document.createTextNode(selector + " {" + declaration + "}");
			style.appendChild(styleRule); // bugs in IE/Win
		}
		style.setAttribute("type", "text/css");
		style.setAttribute("media", "screen"); 
		head.appendChild(style);
		if (UMO.is_safari && UMO.is_XML) { head.innerHTML += ""; } // force Safari repaint for MIME type application/xhtml+xml
		if (UMO.is_ie && UMO.is_win && document.styleSheets && document.styleSheets.length > 0) {
			var lastStyle = document.styleSheets[document.styleSheets.length - 1];
			if (typeof lastStyle.addRule == "object") {
				lastStyle.addRule(selector, declaration);
			}
		}
	},

	createElement: function(el) {
		return (typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", el) : document.createElement(el);
	},

	hasRequiredAttrParams: function(id) {
		var FO = UMO.foList[id];
		for (var i = 0; i < UMO.requiredAttrParams.length; i++) {
			if (typeof FO[UMO.requiredAttrParams[i]] == "undefined") return false;
		}
		return true;
	},

	writeFlashObject: function(id) {
		var el = document.getElementById(id);
		if (typeof el.innerHTML == "undefined") return;
		var FO = UMO.foList[id];
		if (UMO.testActiveX() != true && UMO.testGeckoActiveX() != true) {
			try	{ // older versions of Gecko only support innerHTML get and not set
				el.innerHTML = "ufo-test";
			}
			catch (e) {}
			if (el.innerHTML != "ufo-test") {
				while(el.hasChildNodes()) {
					el.removeChild(el.firstChild);
				}
				var embed = UMO.createElement("embed");
				embed.setAttribute("type", "application/x-mplayer2");
				embed.setAttribute("pluginspage", "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/");
				embed.setAttribute("src", FO.movie);
				embed.setAttribute("width", FO.width);
				embed.setAttribute("height", FO.height);
				for (var i = 0; i < UMO.optionalAttrEmb.length; i++) {
					if (typeof FO[UMO.optionalAttrEmb[i]] != "undefined") {
						embed.setAttribute(UMO.optionalAttrEmb[i], FO[UMO.optionalAttrEmb[i]]);
					}
				}
				for (var i = 0; i < UMO.optionalAttrParams.length; i++) {
					if (typeof FO[UMO.optionalAttrParams[i]] != "undefined") {
						embed.setAttribute(UMO.optionalAttrParams[i], FO[UMO.optionalAttrParams[i]]);
					}
				}	
				el.appendChild(embed);
			}
			else {
				var embHTML = "";
				for (var i = 0; i < UMO.optionalAttrEmb.length; i++) {
					if (typeof FO[UMO.optionalAttrEmb[i]] != "undefined") {
						embHTML += ' ' + UMO.optionalAttrEmb[i] + '="' + FO[UMO.optionalAttrEmb[i]] + '"';
					}
				}
				for (var i = 0; i < UMO.optionalAttrParams.length; i++) {
					if (typeof FO[UMO.optionalAttrParams[i]] != "undefined") {
						embHTML += ' ' + UMO.optionalAttrParams[i] + '="' + FO[UMO.optionalAttrParams[i]] + '"';
					}
				}
				el.innerHTML = '<embed type="application/x-mplayer2" src="' + FO.movie + '" width="' + FO.width + '" height="' + FO.height + '" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"' + embHTML + '></embed>';
			}
		}
		else {
			var objAttrHTML = "";
			for (var i = 0; i < UMO.optionalAttrObj.length; i++) {
				if (typeof FO[UMO.optionalAttrObj[i]] != "undefined") {
					objAttrHTML += ' ' + UMO.optionalAttrObj[i] + '="' + FO[UMO.optionalAttrObj[i]] + '"';
				}
			}
			var objParamHTML = "";
				var arrx = new Array();
			for (var i = 0; i < UMO.optionalAttrParams.length; i++) {
				if (typeof FO[UMO.optionalAttrParams[i]] != "undefined") {
					objParamHTML += '<param name="' + UMO.optionalAttrParams[i] + '" value="' + FO[UMO.optionalAttrParams[i]] + '" />';
				}
					arrx.push(UMO.optionalAttrParams[i] + ": " + FO[UMO.optionalAttrParams[i]]);
			}//
			//alert(objParamHTML)
			//	alert(arrx.join("\r\n"));
			var protocol = (window.location.protocol == "https:" ? "https:" : "http:");
			el.innerHTML = '<object classid="CLSID:6bf52a52-394a-11d3-b153-00c04f79faa6"' + objAttrHTML + ' type="video/x-ms-wma" width="' + FO.width + '" height="' + FO.height + '" codebase="' + protocol + 'activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"><param name="filename" value="' + FO.movie + '" /><param name="url" value="' + FO.movie + '" />' + objParamHTML + '</object>';
		}
		//alert(el.innerHTML);
	}

}

//addEvent(window, "load", video_init);

