//################################################################################################################################################################
//Version 2.2

// History
// - 2008/12/15 Version 1, div.
// 2008/12/15 Version 2 initial with Flash Version detection which works with Numbers with two or more digits, Robert Kunde
// 2009/02/10 Version 2.1 parseInt(versionIndex), parseInt(inVersion), Robert Kunde
// 2009/11/13 Version 2.2 wmode="transparent", Stefan Fischer
//################################################################################################################################################################

function newWindow(url, width, height){
	var params = 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,scrollbars=no,status=no,menubar=no,resizable=no'
	window.open(url, 'Popup', params);
}


function switchTextPage(nr){
	if (document.getElementById) {
		if (pagesAr) {
			nr = parseInt(nr, 10);
			if (nr != "NaN") {
				nr = nr - 1
				if (pagesAr.length >= nr) {
					showDiv(pagesAr[nr]);
				}
			}
		}
	}
}


function makePreviewMode(inStr){
	inStr = inStr.replace('Mode=1', 'Mode=0&ran=' + Math.round(Math.random() * 10000000));
	return (inStr);
}

/*############ Flash Detection ############*/

/*#### read Flash version from FireFox ####*/
function flashVersionRegEx(data){
	var regex = /.*[a-zA-Z][^0-9](.*[0-9][^a-zA-Z])..*/;
	regex.exec(data);
	versionNumber = RegExp.$1;
	pointSearch = versionNumber.indexOf(".");
	versionNumber = versionNumber.substring(0, pointSearch);
	return versionNumber;
}

/*#### check XML, if true re-set min. version of Flash ####*/
function flashXml(i_path, i_name, i_width, i_height, i_bgcolor, i_fb, i_link, i_usemap, i_pagelink){
	if (i_link) {
		i_minVersion = 9;
	}
	else {
		i_minVersion = 9;
	}
	return (insertFlashXml(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_fb, i_link, i_usemap, i_pagelink));
}

/*#### added XML path to link ####*/
function insertFlashXml(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_fb, i_link, i_usemap, i_pagelink){
	if (i_path) {
		if (i_link) {
			i_link = "?xmlpath=" + escape(i_link);
			
			var linkarray = i_link.split("/");
			i_link = linkarray.join("%2F");
			i_path = i_path + i_link;
		}
	}
	if (!i_usemap) {
		i_usemap = "";
	}
	insertFlash(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_fb, i_usemap, i_pagelink);
}

/*#### insert Flash object to page####*/
function insertFlash(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_fb, i_usemap, i_pagelink){
	var flv = i_path.search(/flvpath/);
	var mp3 = i_path.search(/mp3path/);
	if ((flv != -1) || (mp3 != -1)) {
		if (md == 'high' && Modernizr.video && Modernizr.video.h264) {
			var videoSrc = i_path.split("&");
			var videoPath = videoSrc[1];
			videoPath = videoPath.replace(/flvpath=/g, "");
			videoPath = videoPath.replace(/mp3path=/g, "");
			var html = "";
			var type = videoPath.search(/\.mp3/);
			if (type != -1) {
				html += '<audio src="' + videoPath + '" controls="controls" width="' + i_width + '" height="auto" style="margin-bottom:10px;width:' + i_width + 'px !important;min-height:32px;">' +
				'	<img src="' +
				i_fb +
				'" width="' +
				i_width +
				'" height="' +
				i_height +
				'" border="0" usemap="#' +
				i_usemap +
				'"><br />' +
				'</audio>';
			}
			else {
				var format = videoPath.search(/\.mp4/);
				if (format != -1) {
					html += '<video controls="controls" width="' + i_width + '" height="auto" preload="auto" poster="' + i_fb + '" style="margin-bottom:10px;">' +
					'	<source src="' +
					videoPath +
					' " type="video/mp4" />' +
					'	<img src="' +
					i_fb +
					'" width="' +
					i_width +
					'" height="' +
					i_height +
					'" border="0" usemap="#' +
					i_usemap +
					'"><br />' +
					'</video>';
				}
				else {
					html += '<img src="' + i_fb + '" width="' + i_width + '" height="' + i_height + '" border="0" usemap="#' + i_usemap + '" style="margin-bottom:10px;"><br />' +
					'<div class="link"><a style="font-size:75%;" href="' +
					videoPath +
					'" target="_black">Video abspielen</a></div>';
				}
			}
			document.write(html);
		}
		else if (md == 'pc' && (i_path.length > 1) && isFlash(i_minVersion)) {
			if (i_pagelink) {
				if (i_path.indexOf("?") > 0) {
					i_pagelink = "&path=" + escape(i_pagelink);
				}
				else {
					i_pagelink = "?path=" + escape(i_pagelink);
				}
				
				var linkarray = i_pagelink.split("/");
				i_pagelink = linkarray.join("%2F");
				i_path = i_path + i_pagelink;
			}
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
			document.write(' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"');
			document.write(' id="' + i_name + '" width="' + i_width + '" height="' + i_height + '">');
			document.write(' <param name="movie" value="' + i_path + '" />');
			document.write(' <param name="quality" value="high" />');
			document.write(' <param name="allowFullScreen" value="true" /> ');
			document.write(' <param name="menu" value="false" />');
			document.write(' <param name="bgcolor" value="#' + i_bgcolor + '" />');
			document.write(' <param name="wmode" value="transparent" />');
			document.write('<embed src="' + i_path + '"');
			document.write(' name="' + i_name + '" wmode="transparent" swLiveConnect="true" width="' + i_width + '" height="' + i_height + '"');
			document.write(' quality="high" menu="false" allowFullScreen="true" bgcolor="#' + i_bgcolor + '"');
			document.write(' type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
			document.write('</embed>');
			document.write('</object>');
		}
		else if (Modernizr.video && Modernizr.video.h264) {
			//document.write('<img src="' + i_fb+'" width="'+i_width+'" height="'+i_height+'" border="0" usemap="#'+i_usemap+'"><br />');
			//flashXml('/rbsMobile/content/language1/scripts/flv_player.swf?flvpreview=&flvpath=http://schulpreis.bosch-stiftung.de/content/language1/film/flv/DSP_Hauptpreis_Hindelang.flv', "Flash", 450, 175,"ffffff", '/rbsMobile/content/language1/images_w450/Afrika_Galerie_Gruppe.jpg','','A30835');
			var videoSrc = i_path.split("&");
			var videoPath = videoSrc[1];
			videoPath = videoPath.replace(/flvpath=/g, "");
			videoPath = videoPath.replace(/mp3path=/g, "");
			var html = "";
			var type = videoPath.search(/\.mp3/);
			if (type != -1) {
				html += '<audio src="' + videoPath + '" controls="controls" width="' + i_width + '" height="auto" style="margin-bottom:10px;width:' + i_width + 'px !important;min-height:32px;">' +
				'	<img src="' +
				i_fb +
				'" width="' +
				i_width +
				'" height="' +
				i_height +
				'" border="0" usemap="#' +
				i_usemap +
				'"><br />' +
				'</audio>';
			}
			else {
				var format = videoPath.search(/\.mp4/);
				if (format != -1) {
					html += '<video controls="controls" width="' + i_width + '" height="auto" preload="auto" poster="' + i_fb + '" style="margin-bottom:10px;">' +
					'	<source src="' +
					videoPath +
					' " type="video/mp4" />' +
					'	<img src="' +
					i_fb +
					'" width="' +
					i_width +
					'" height="' +
					i_height +
					'" border="0" usemap="#' +
					i_usemap +
					'"><br />' +
					'</video>';
				}
				else {
					html += '<img src="' + i_fb + '" width="' + i_width + '" height="' + i_height + '" border="0" usemap="#' + i_usemap + '" style="margin-bottom:10px;"><br />' +
					'<div class="link"><a style="font-size:75%;" href="' +
					videoPath +
					'" target="_self">Video abspielen</a></div>';
				}
			}
			document.write(html);
		}
		else {
			var videoSrc = i_path.split("&");
			var videoPath = videoSrc[1];
			videoPath = videoPath.replace(/flvpath=/g, "");
			videoPath = videoPath.replace(/mp3path=/g, "");
			var html = "";
			html += '<img src="' + i_fb + '" width="' + i_width + '" height="' + i_height + '" border="0" usemap="#' + i_usemap + '" style="margin-bottom:10px;"><br />' +
			'<div class="link"><a style="font-size:75%;" href="' +
			videoPath +
			'" target="_self">Video abspielen</a></div>';
			
			document.write(html);
		}
	}
	else {
		if ((i_path.length > 1) && isFlash(i_minVersion) && (md == 'pc')) {
			if (i_pagelink) {
				if (i_path.indexOf("?") > 0) {
					i_pagelink = "&path=" + escape(i_pagelink);
				}
				else {
					i_pagelink = "?path=" + escape(i_pagelink);
				}
				
				var linkarray = i_pagelink.split("/");
				i_pagelink = linkarray.join("%2F");
				i_path = i_path + i_pagelink;
			}
			document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
			document.write(' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"');
			document.write(' id="' + i_name + '" width="' + i_width + '" height="' + i_height + '">');
			document.write(' <param name="movie" value="' + i_path + '" />');
			document.write(' <param name="quality" value="high" />');
			document.write(' <param name="allowFullScreen" value="true" /> ');
			document.write(' <param name="menu" value="false" />');
			document.write(' <param name="bgcolor" value="#' + i_bgcolor + '" />');
			document.write(' <param name="wmode" value="transparent" />');
			document.write('<embed src="' + i_path + '"');
			document.write(' name="' + i_name + '" wmode="transparent" swLiveConnect="true" width="' + i_width + '" height="' + i_height + '"');
			document.write(' quality="high" menu="false" allowFullScreen="true" bgcolor="#' + i_bgcolor + '"');
			document.write(' type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
			document.write('</embed>');
			document.write('</object>');
		}
		else {
			document.write('<img src="' + i_fb + '" width="' + i_width + '" height="' + i_height + '" border="0" usemap="#' + i_usemap + '"><br />');
		}
	}
}

/*#### check for Flash Plugin in browser ####*/
function isFlash(inVersion){
	FlashMode = 0;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
		versionIndex = flashVersionRegEx(navigator.plugins["Shockwave Flash"].description);
		versionIndex = parseInt(versionIndex);
		inVersion = parseInt(inVersion);
		if (versionIndex >= inVersion) {
			FlashMode = 1;
		}
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.userAgent.indexOf("Windows 95") >= 0 || navigator.userAgent.indexOf("Windows 98") >= 0 || navigator.userAgent.indexOf("Windows NT") >= 0)) {
		theStr = 'FlashMode = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.' + inVersion + '"))) \n';
		document.write('<script language=VBScript\> \n');
		document.write('on error resume next \n');
		document.write(theStr);
		document.write('</script\> \n');
	}
	return FlashMode;
}

