var bOverlayed = true;
var FO = null;

function getStyle(elem, w3cStyleProp, ieStyleProp) {
	if (elem.currentStyle) {
		var y = elem.currentStyle[ieStyleProp];
	} else if (window.getComputedStyle) {
		var y = document.defaultView.getComputedStyle(elem, null).getPropertyValue(w3cStyleProp);
	}
	return y;
}

function selectPlayer(player) {
	var playerId = "TAB" + player;
	Tab.activateTab(playerId);
	document.getElementById("videoPlayer").style.display = "block";
	closePlayerSelect();
	
}

function closePlayerSelect() {
	iSteps = 25;
	psbox = document.getElementById("videoPlayerSelect");
	psbox.innerHTML = "";

	iInitWidth = iWidth = parseInt(getStyle(psbox, "width", "width"));
	iInitHeight = iHeight = parseInt(getStyle(psbox, "height", "height"));

	collapse();
}

function collapse() {
	iWidth -= iInitWidth/iSteps;
	iHeight -= iInitHeight/iSteps;

	psbox.style.width = iWidth + "px";
	psbox.style.height = iHeight + "px";

	if (iWidth > 0 && iHeight > 0) {
		window.setTimeout("collapse()", 15);
	} else {
		psbox.style.display = "none";
		bOverlayed = false;
	//	window.status = "is weg";
	}
}

function createFO(videoFileName) {
	if (FO == null) {
		FO = {
			movie: "/files/flvplayer.swf",
			width: "300",
			height: "260",
			majorversion: "7",
			build: "0",
			bgcolor: "#000000",
			flashvars: "file=" + videoFileName + "&showdigits=true&autostart=true&volume=100"
		};
	}
}

function createPlayer(id) {
	if (bOverlayed) {
		window.setTimeout("createPlayer('"+id+"')", 5);
	} else {

		var box = document.getElementById(id + "AREA");
		var player = id.substr(3);
		var code = null;
		
		if (player == "flv") {
			// create div with id...
			code = 
			'<p id="flvplayer">' +
			'<a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> ' +
			'to see this video.</p>';

			box.innerHTML = code;
			createFO(files[player]);
			UFO.create(FO, "flvplayer");
			
		} else if (player == "mov") {
			code = 
			'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="320" height="256">' +
				'<param name="src" value="' + files[player] + '">' +
				'<param name="AutoPlay" value="true">' +
				'<param name="Controller" value="true">' +
				'<param name="loop" value="false">' +
				'<param name="scale" value="aspect">' +
				'<embed src="' + files[player] + '" width="320" height="256" type="video/quicktime" pluginspace="http://www.apple.com/quicktime/download/" autoplay="true" controller="true" loop="false" scale="aspect" /> ' +
			'</object>';
			
			box.innerHTML = code;
		} else if (player == "wmv") {
			code = 
			'<object id="mediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"' +
				'width="320" height="285" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">' +
				'<param name="src" value="' + files[player] + '">' +
				'<param name="fileName" value="' + files[player] + '">' +
				'<param name="animationatStart" value="true">' +
				'<param name="transparentatStart" value="false">' +
				'<param name="autoStart" value="true">' +
				'<param name="showControls" value="true">' +
				'<embed src="' + files[player] + '" type="application/x-mplayer2"' +
					'pluginspage="http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx"' +
					'width="320" height="285" filename="' + files[player] + '"' +
					'showcontrols="true" animationatstart="true" transparentatstart="false" autostart="true"' +
					'showstatusbar="true"/">' +
				'</embed>' +
			'</object>';
			
			box.innerHTML = code;
		}

		
	}
}

function removePlayer(id) {
	document.getElementById(id + "AREA").innerHTML = '';
}

function Tab() {
	this.activeTab;
	this.tabs = new Array();
}

Tab.prototype.appendTab = function(caption, id) {
	this.tabs.push([caption, id]);
}

Tab.prototype.setActiveTab = function(id) {
	this.activeTab = id;
}

Tab.prototype.hoverTab = function(id) {
//	document.getElementById(id).className = "tabhover";
}

Tab.prototype.leaveTab = function(id) {
	newclass = this.activeTab == id ? "tabactive" : "tabnormal";
	document.getElementById(id).className = newclass;
}

Tab.prototype.activateTab = function(id) {
	// reset old tab
	if( typeof this.activeTab != "undefined" ) {
		document.getElementById(this.activeTab).className = "tabnormal";
		document.getElementById(this.activeTab + "AREA").style.display = "none";
		removePlayer(this.activeTab);
	}

	// set new tab
	document.getElementById(id).className = "tabactive";
	document.getElementById(id + "AREA").style.display = "block";
	this.activeTab = id;
	createPlayer(id);
}

Tab.prototype.paint = function() {
	try {
	document.write('<ul class="tabbar">');
	for (i = 0; i < this.tabs.length; ++i)	{
		className = this.tabs[i][1] == this.activeTab ? "tabactive" : "tabnormal";
		document.write('<li><a href="javascript:void(0)" id="' + this.tabs[i][1] + '" class="' + className + '" onmouseover="Tab.hoverTab(this.id)" onmouseout="Tab.leaveTab(this.id)" onclick="Tab.activateTab(this.id)">' + this.tabs[i][0] + '</a></li>');
	}
	document.write("</ul>");
	} catch(e) {
		alert(e.description);
	}
}