// Copyright ©2006, Rudolf Ruland, ruland@fit.fraunhofer.de
// Do not use this file without permission.

var startClip = getURLParam('play');

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function stopQT(name){
	clip = eval('document.' + name + '_clip');
	if (clip) {
		try {
			clip.SetAutoPlay(false);
			clip.Stop();
		} catch (e) {
			setTimeout('stopQT(\'' + name + '\')', 100);
		}
	}
}

function playQT(name){
	clip = eval('document.' + name + '_clip');
	if (clip) {
		try {
			clip.SetAutoPlay(true);
			clip.Play();
		} catch (e) {
			setTimeout('playQT(\'' + name + '\')', 100);
		}
	}
}

function controlQT(name){
	clip = eval('document.' + name + '_clip');
	if (clip.GetAutoPlay()) {
		stopQT(name)
	} else {
		playQT(name)
	}
}

function startQT(name){
	clip = eval('document.' + name + '_clip');
	if (clip) {
		playQT(name);
	} else {
		setTimeout('startQT(\'' + name + '\')', 100);
	}
}

function streamQT_html(name, width, height, film, image){
	
	if (startClip == name){

//		startClip = '';
//		src = image;
		src = 'http://mediamail.ami-communities.eu/images/dot.gif'
		html = QT_GenerateOBJECTText_XHTML(src, width, height, '',
//			'qtsrc', 				src,
			'qtnext1',				'<' + film + '> T<myself>',
			'type', 				'video/quicktime',
			'scale',				'tofit',
			'kioskmode',			'true',
			'cache',				'false',
			'qtsrcdontusebrowser', 	'true',
			'controller', 			'true',
			'enablejavascript',		'true',
			'href', 				'javascript:controlQT(\'' + name + '\')',
			'autoplay',				'true',
			'name', 				name + '_clip');
//		html += '<script type="text/javascript">document.'+ name + '_clip.Play()</script>'

	} else {
		html = '<a href="javascript:void(0)" onmouseover="status=\'' + name + '\';return true" onmouseout="status=\'\';return true" onclick="startClip=\'' + name + '\'; streamQT(\'' + name + '\', \'' + width + '\', \'' + height + '\', \'' + film + '\', \'' + image + '\'); return true">'
		     + '<img src="' + image + '" width="' + width + '" height="' + height + '" border="0" alt="click to start" title="click to start" />'
		     + '</a>'
	}
	return html;
}

function streamQT(name, width, height, film, image){
	if (startClip == name){
//		document.getElementById(name + '_clip').Play()
//		setTimeout('document.'+ name + '_clip.Play()', 1000);
//		setTimeout('controlQT(\'' + name + '\')', 2000);
//		startQT(name);
	}
	box = document.getElementById(name)
	box.innerHTML = '';
	box.innerHTML = streamQT_html(name, width, height, film, image);
}

/*****************************************************************************/

function filmQT(title, name, width, height, film, image){
	startClip = name
    return openWin(
		streamQT_html(name, width, height, film, image),
		title,
		'foto','width='+width+',height='+height, 0);
}

function openLoc(winUrl,winTitle,winName,winFeatures, winRefresh) {
    win = window.open('', winName, winFeatures);
    win.location.href = winUrl;
    win.focus();
    return void(0);
}
	
function openWin(winCode,winTitle,winName,winFeatures, winRefresh) {
    win = window.open('', winName, winFeatures);
    win.document.title = winTitle;
    win.document.write('<head>\n');
    if (winRefresh > 0){
        win.document.write('<meta http-equiv="refresh" content="');
        win.document.write(winRefresh);
        win.document.write('">\n');
    }     
    win.document.write('<title>');
    win.document.write(winTitle);
    win.document.write('</title>\n');
    win.document.write('</head>\n');
    win.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="white">\n');
    win.document.write(winCode);
    win.document.write('\n</body>\n</html>');
    win.document.close();
    win.focus();
    return void(0);
}

function foto(img, title, width, height){
    return openWin(
		'<img src="'+img+'" alt="" title="">',
		title,
		'foto','width='+width+',height='+height, 0);
}

function filmWMP(video, title, width, height){
    return openWin('<object                                                                     \n' +
'		id="WinMediaPlayer" width="'+width+'" height="'+height+'"                       \n' +
'		CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"                            \n' +
'		standby="....Loading"                                                           \n' +
'		type="application/x-oleobject">                                                 \n' +
'	<PARAM NAME="FileName" VALUE="'+video+'">                                               \n' +
'	<PARAM NAME="AnimationAtStart" VALUE="true">                                            \n' +
'	<PARAM NAME="Loop" VALUE="true">                                                        \n' +
'	<PARAM NAME="AutoRewind" VALUE="true">                                                  \n' +
'	<PARAM NAME="AutoStart" VALUE="true">                                                   \n' +
'	<PARAM NAME="Autosize" VALUE="true">                                                    \n' +
'	<PARAM NAME="ControlType" VALUE="-1">                                                   \n' +
'	<PARAM NAME="ShowAudioControls" VALUE="-1">                                             \n' +
'	<PARAM NAME="ShowCaptioning" Value="0">                                                 \n' +
'	<PARAM NAME="ShowDisplay" VALUE="0">                                                    \n' +
'	<PARAM NAME="ShowControls" VALUE="0">                                                   \n' +
'	<PARAM NAME="ShowGotoBar" VALUE="0">                                                    \n' +
'	<PARAM NAME="ShowPositionControls" VALUE="1">                                           \n' +
'	<PARAM NAME="ShowStatusBar" VALUE="false">                                              \n' +
'	<PARAM NAME="ShowTracker" VALUE="false">                                                \n' +
'	<PARAM NAME="TransparentAtStart" VALUE="True"><embed                                    \n' +
'		src="'+video+'"                                                                 \n' +
'		name="siegschwelle"                                                             \n' +
'		width="'+width+'"                                                               \n' +
'		height="'+height+'"                                                             \n' +
'		type="video/x-ms-asf-plugin"                                                    \n' +
'		pluginspage="http://www.microsoft.com/windows/windowsmedia/download/default.asp"\n' +
'		AnimationAtStart="true"                                                         \n' +
'       Loop="true"                                                                     \n' +
'		AutoRewind="true"                                                               \n' +
'		AutoStart="true"                                                                \n' +
'		Autosize="true"                                                                 \n' +
'		ControlType="-1"                                                                \n' +
'		ShowAudioControls="0"                                                           \n' +
'		ShowCaptioning="0"                                                              \n' +
'		ShowDisplay="0"                                                                 \n' +
'		ShowControls="0"                                                                \n' +
'		ShowGotoBar="0"                                                                 \n' +
'		ShowPositionControls="1"                                                        \n' +
'		ShowStatusBar="false"                                                           \n' +
'		ShowTracker="false"                                                             \n' +
'		TransparentAtStart="true"></embed></object>                                     \n' +
'',
		title,
		'film','width='+width+',height='+height, 0);
}