//show Box position=relative top=0
function showBoxPosRelTop0(selector){
	if (document.getElementById(selector)) {
		document.getElementById(selector).style.position = "relative";
		document.getElementById(selector).style.top = "0";
	}
}

function makePreviewMode(inStr){
	inStr = inStr.replace('Mode=1', 'Mode=0&ran=' + Math.round(Math.random() * 10000000));
	return (inStr);
}

jQuery.fn.outerHTML = function(){
	return $('<div>').append(this.eq(0).clone()).html();
};

/*############ Flash Detection ############*/

/*#### read Flash version from FireFox ####*/
function flashVersionRegExNew(data){
	var regex = /.*[a-zA-Z][^0-9](.*[0-9][^a-zA-Z])..*/;
	regex.exec(data);
	var versionNumber = RegExp.$1;
	var pointSearch = versionNumber.indexOf(".");
	versionNumber = versionNumber.substring(0, pointSearch);
	return versionNumber;
}

/*#### added XML path to link ####*/
function insertFlashXmlNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_link, 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;
		}
	}
	insertFlashNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_pagelink);
}


/*#### added XML path to link (Video / Audio Player) ####*/
function insertFlashVideoAudioNewXmlNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_link, 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;
		}
	}
	insertFlashVideoAudioNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_pagelink);
}

/*#### insert Flash object to page####*/
function insertFlashNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_pagelink){
	var d = "";
	if ((i_path.length > 1) && isFlashNew(i_minVersion)) {
		if (document.getElementById(i_name + '_div')) {
			//hide fallback		
			$("#" + i_name + "_fallback").hide();
			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;
			}
			d += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
			d += ' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"';
			d += ' id="' + i_name + '" width="' + i_width + '" height="' + i_height + '">';
			d += ' <param name="movie" value="' + i_path + '" /> ';
			d += ' <param name="quality" value="high" /> ';
			d += ' <param name="allowFullScreen" value="true" /> ';
			d += ' <param name="menu" value="false" /> ';
			d += ' <param name="bgcolor" value="#' + i_bgcolor + '" /> ';
			d += ' <param name="wmode" value="transparent" />';
			d += '<embed src="' + i_path + '"';
			d += ' name="' + i_name + '" wmode="transparent" swLiveConnect="true" width="' + i_width + '" height="' + i_height + '"';
			d += ' quality="high" menu="false" allowFullScreen="true" bgcolor="#' + i_bgcolor + '"';
			d += ' type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
			d += '</embed>';
			d += '</object>';
			document.getElementById(i_name + '_div').innerHTML = d;
		}
	}else{
		document.getElementById(i_name + '_fallback').style.display = 'block';
	}
}

/*#### insert Flash object to page (Video / Audio Player) ####*/
function insertFlashVideoAudioNew(i_minVersion, i_path, i_name, i_width, i_height, i_bgcolor, i_pagelink){
	var d = "";
	if ((i_path.length > 1) && isFlashNew(i_minVersion)) {
		if (document.getElementById(i_name + '_div')) {
			//hide fallback
			$("#" + i_name + "_fallback").hide();
			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;
			}
			d += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
			d += ' codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0"';
			d += ' id="' + i_name + '" width="' + i_width + '" height="' + i_height + '">';
			d += ' <param name="movie" value="' + i_path + '" /> ';
			d += ' <param name="quality" value="high" /> ';
			d += ' <param name="allowFullScreen" value="true" /> ';
			d += ' <param name="menu" value="false" /> ';
			d += ' <param name="bgcolor" value="#' + i_bgcolor + '" /> ';
			d += ' <param name="wmode" value="transparent" />';
			d += '<embed src="' + i_path + '"';
			d += ' name="' + i_name + '" wmode="transparent" swLiveConnect="true" width="' + i_width + '" height="' + i_height + '"';
			d += ' quality="high" menu="false" allowFullScreen="true" bgcolor="#' + i_bgcolor + '"';
			d += ' type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">';
			d += '</embed>';
			d += '</object>';
			document.getElementById(i_name + '_div').innerHTML = d;
		}
	} else {
		if ((Leonhardt.video && Leonhardt.video.h264) || (Leonhardt.audio && Leonhardt.audio.mp3)) {
			var videoSrc = i_path.split("&");
			var videoPreview = videoSrc[1];
			videoPreview = videoPreview.replace(/mediapreview=/g, "");
			var videoPath = videoSrc[0];
			videoPath = videoPath.replace(/mediapath=/g, "");
			videoPath = videoPath.replace(/\/flashplayer\/media_player\.swf\?/g, "");
			var html = "";
			var type = videoPath.search(/\.mp3/);
			if (type != -1) {
				if (Leonhardt.audio && Leonhardt.audio.mp3) {
					$("#" + i_name + "_fallback").hide();
					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="' +
					videoPreview +
					'" alt="" />' +
					'</audio>';
					document.getElementById(i_name + '_div').innerHTML = html;
				} else {
					$("#" + i_name).hide();
					$("#" + i_name + "_fallback").show();
				}
			} else {
				$("#" + i_name + "_fallback").hide();
				var format = videoPath.search(/\.mp4/);
				if ((format != -1) && Leonhardt.video && Leonhardt.video.h264) {
					html += '<video controls="controls" width="' + i_width + '" height="auto" preload="auto" poster="' + videoPreview + '" style="margin-bottom:10px;">' +
					'	<source src="' +
					videoPath +
					' " type="video/mp4" />' +
					'</video>';
					document.getElementById(i_name + '_div').innerHTML = html;
				} else {
					$("#" + i_name).hide();
					$("#" + i_name + "_fallback").show();
				}
			}
		} else {
			$("#" + i_name).hide();
			$("#" + i_name + "_fallback").show();
		}
	}
}

/*#### check for Flash Plugin in browser ####*/
function isFlashNew(inVersion){
	FlashMode = 0;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
		var versionIndex = flashVersionRegExNew(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;
}

