// ACHTUNG: flashembed.min.js muss eingebunden sein
// ACHTUNG: ufo.js und mp3player.js müssen eingebunden sein

var iTBAnker = "#";
var iTBWindowMinHeight = 400;
var iTBWindowMinWidth = 700;
var iTBFLVMovie = null;
var iTBUFOPlayer = null;

function iTB_ShowFLV(value, FLVID, FLVFile, Anker)
{
	iTB_Show(value, Anker);

	if(FLVFile != null)
	{
		iTB_addFLVMovie(FLVID, FLVFile);
	}
	var iTBWindow = document.getElementById("iTB_window");
	iTB_Position(iTBWindow);
}

function iTB_ShowUFO(value, UFOID, UFOFile, Anker, colors)
{
	iTB_Show(value, Anker);

	if(UFOID != null)
	{
		iTB_addUFOPlayer(UFOID, UFOFile, colors);
	}
	var iTBWindow = document.getElementById("iTB_window");
	iTB_Position(iTBWindow);
}

function iTB_Show(value, Anker)
{
	var iTBWindow = document.getElementById("iTB_window");
	var iTBOverlay = document.getElementById("iTB_overlay");
	if (typeof document.body.style.maxHeight === "undefined") //if IE 6
	{
		document.body.style.cssText = "height: 100%; width: 100%;";
		if (document.getElementById("iTB_HideSelect") === null) 
		{
			var iframe = document.createElement("iframe");
			iframe.id = "iTB_HideSelect";
			document.body.appendChild(iframe);
			
			iTBOverlay = document.createElement("div");
			iTBOverlay.id = "iTB_overlay";
			iTB_addEventHandler(iTBOverlay, "click", iTB_Remove);
			document.body.appendChild(iTBOverlay);
			
			iTBWindow = document.createElement("div");
			iTBWindow.id = "iTB_window";
			document.body.appendChild(iTBWindow);
		}
	}
	else //all others
	{
		if(document.getElementById("iTB_overlay") === null)
		{
			iTBOverlay = document.createElement("div");
			iTBOverlay.id = "iTB_overlay";
			iTB_addEventHandler(iTBOverlay, "click", iTB_Remove);
			document.body.appendChild(iTBOverlay);
			
			iTBWindow = document.createElement("div");
			iTBWindow.id = "iTB_window";
			document.body.appendChild(iTBWindow);
		}
	}
	
	if(iTB_detectMacXFF())
	{
		iTBOverlay.className = "iTB_overlayMacFFBGHack";
	}
	else
	{
		iTBOverlay.className = "iTB_overlayBG";
	}
	
	if(value === null)
	{
		value = "";
	}
	
	iTBWindow.innerHTML = "<div id='iTB_closeWindow'><a href='" + (Anker != null ? Anker : iTBAnker) + "' id='iTB_closeWindowButton' title='schlie&szlig;en'>X schlie&szlig;en</a></div>" + 
		value;
	
	var iTBCloseButton = document.getElementById("iTB_closeWindowButton");
	iTB_addEventHandler(iTBCloseButton, "click", iTB_Remove);
	
	iTB_Position(iTBWindow);
}

function iTB_Position(iTBWindow)
{
	var pageSize = iTB_getPageSize;
	var x = pageSize[0] - 100;
	var y = pageSize[1] - 100;
	
	var width = iTBWindowMinWidth;
	var height = iTBWindowMinHeight;
	
	width = (width > x ? x : width);

	iTBWindow.style.cssText = "width: " + width + "px;";
	
	height = (iTBWindow.clientHeight > height ? iTBWindow.clientHeight : height);
	height = (height > y ? y : height);
	
	iTBWindow.style.cssText = "width: " + width + "px;" +
								"height: " + height + "px;" +
								"margin: -" + parseInt((height / 2), 10) + "px " + 
									parseInt((width / 2), 10) + "px " + 
									"0px " + 
									"-" + parseInt((width / 2), 10) + "px;";
}

function iTB_getPageSize()
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function iTB_Remove() 
{
	var iTBOverlay = document.getElementById("iTB_overlay");
	var iTBWindow = document.getElementById("iTB_window");
	var iTBHideSelect = document.getElementById("iTB_HideSelect");
	var iTBCloseButton = document.getElementById("iTB_closeWindowButton");
	
	if(iTBFLVMovie != null)
	{
		iTBFLVMovie.Reset();
	}
	if(iTBUFOPlayer != null)
	{
		ap_stopAll(iTBUFOPlayer);
		iTBUFOPlayer = null;
	}
	
	if (iTBCloseButton != null)
	{
		iTB_removeEventHandler(iTBCloseButton, "click", iTB_Remove);
	}
	if (iTBOverlay != null)
	{
		iTB_removeEventHandler(iTBOverlay, "click", iTB_Remove);
		iTBOverlay.parentNode.removeChild(iTBOverlay);
	}
	if (iTBWindow != null)
	{
		iTBWindow.innerHTML = "";
		iTBWindow.parentNode.removeChild(iTBWindow);
	}
	if (iTBHideSelect != null)
	{
		iTBHideSelect.parentNode.removeChild(iTBHideSelect);
	}
	return false;
}

function iTB_detectMacXFF()
{
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1)
	{
		return true;
	}
}

function iTB_addEventHandler(elem, eventName, handler, useCapture)
{
	var isExplorer = ((navigator.userAgent.indexOf("MSIE 6") > -1) ||(navigator.userAgent.indexOf("MSIE 7") > -1) || (navigator.userAgent.indexOf("MSIE 8") > -1)) && (navigator.userAgent.indexOf("Opera") == -1) && (navigator.platform.indexOf("Win") == 0);
	var handlerRetVal = null;
	if (typeof useCapture === "undefined")
	{
		useCapture = false;
	}
	if (isExplorer)
	{
		handlerRetVal = elem.attachEvent("on"+eventName, handler);
	}
	else
	{
		handlerRetVal = elem.addEventListener(eventName, handler, useCapture);
	}
	return handlerRetVal;
}

function iTB_removeEventHandler(elem, eventName, handler, useCapture)
{
	var isExplorer = ((navigator.userAgent.indexOf("MSIE 6") > -1) ||(navigator.userAgent.indexOf("MSIE 7") > -1) || (navigator.userAgent.indexOf("MSIE 8") > -1)) && (navigator.userAgent.indexOf("Opera") == -1) && (navigator.platform.indexOf("Win") == 0);
	if (typeof useCapture === "undefined")
	{
		useCapture = false;
	}
	if (isExplorer)
	{
		elem.detachEvent("on"+eventName, handler);
	}
	else
	{
		elem.removeEventListener(eventName, handler, useCapture);
	}
}

function iTB_addFLVMovie(id, file)
{
	iTBFLVMovie = flashembed(
		id,
		{
			src: '/include/player/FlowPlayerDark.swf', width: 320, height: 260
		},
		{
			config: 
			{
				videoFile: file, 
				initialScale: 'scale', 
				hideControls: false, 
				autoPlay: false, 
				loop: false,
				autoBuffering: false
			}
		}
	);
}

function iTB_addUFOPlayer(id, file, colors)
{
	var colors = (colors ? colors : "bg=0x7D99CB&leftbg=0x00268F&rightbg=0x7D99CB&rightbghover=0x00268F&lefticon=0xFFFFFF&righticon=0x00268F&righticonhover=0xFFFFFF&text=0x00268F&slider=0x00268F&loader=0xFFFFFF&track=0xFFFFFF&border=0x00268F");
	
	iTBUFOPlayer = id;
	UFO.create(
		{ 
			movie:"/include/player/player.swf",
			id:"audio" + id,
			width:"250",
			height:"24",
			majorversion:"7",
			build:"0",
			bgcolor:"#FFFFFF",
			wmode:"transparent",
			flashvars:"playerID=1&soundFile=" + file + "&autostart=no&loop=no&" + colors
		},
		id
	);
}

function iTB_Warten(prmSec)
{
	prmSec *= 100;
	var eDate = null;
	var eMsec = 0;
	var sDate = new Date();
	var sMsec = sDate.getTime();

	do {
		eDate = new Date();
		eMsec = eDate.getTime();
	} while ((eMsec-sMsec)<prmSec);
}
