function ShowHideLayer(id) {
	var v = document.getElementById(id).style.visibility;
	if(v == "visible") {
		document.getElementById(id).style.visibility = "hidden";
	} else {
		document.getElementById(id).style.visibility = "visible";
	}
}

function WriteFlashObject() {
	var file 	= document.getElementById('marginal_videofile').value;
	var fo 		= document.getElementById('marginal_flashobject');
	
	var width 	= "640";
	var height	= "500";	
	
	fo.innerHTML = '<a href="javascript:StopVideo()"><img style="margin: 0px; padding: 0px;"  src="/fileadmin/templates/matrix42_mainTemplate_2009_FILES/videobox_close.gif" alt="Close"></a><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="videoplayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="FlashVars" value="filename='+file+'" /><param name="movie" value="/fileadmin/flash/videoplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <param name="wmode" value="opaque"><embed src="/fileadmin/flash/videoplayer.swf" quality="high" FlashVars="filename='+file+'" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque"/></object>';
}

function VideoOverlay(state) {
	if(state=="on") {
		var overlayDIV	= document.createElement("div");
		document.body.insertBefore(overlayDIV, document.body.firstChild);
		var neuBText 	= document.body.firstChild.setAttribute("id", "marginal_video_overlay");
		document.getElementById('marginal_video_overlay').style.height = document.body.offsetHeight; 
		
} else { // delete Div 
		document.body.firstChild.innerHTML = '';	
	  	var Knoten = document.body.firstChild;
		document.body.removeChild(Knoten);
	}
}

function EraseFlashObject() {
	var fo 		= document.getElementById('marginal_flashobject');
	fo.innerHTML = '';
	VideoOverlay('off');
}

function StartVideo() {
	ShowHideLayer('marginal_video');
	VideoOverlay('on');
	WriteFlashObject();
}

function StopVideo() {
	ShowHideLayer('marginal_video');
	EraseFlashObject();
}



/* JS for new Marginal  */



function MarginalVideo_Tracking(id, label) {
	return '<script type="text/javascript"> var google_conversion_id = '+id+';	var google_conversion_language = "de";	var google_conversion_format = "2";	var google_conversion_color = "ffffff";	var google_conversion_label = "'+label+'";	var google_conversion_value = 0;	</script><script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script><noscript><div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/'+id+'/?label='+label+'&amp;guid=ON&amp;script=0"/></div></noscript>';	
}



function MarginalVideo_ShowHideLayer(id) {
	var v = document.getElementById(id).style.visibility;
	if(v == "visible") {
		document.getElementById(id).style.visibility = "hidden";
	} else {
		document.getElementById(id).style.visibility = "visible";
	}
}

function MarginalVideo_WriteFlashObject(file,ratio) {
	var pu 		= document.getElementById('nmb_video-box-popup');
	var va		= document.getElementById('marginal_videoaspect');
	var tracking= '';
	
	// Tracking
	if(tracking.length > 0) {
		tracking = MarginalVideo_Tracking(id, label);	
	}
	
	if(ratio == "16:9") {
		var width 	= "800";
		var height	= "470";
		var player	= "videoplayer169.swf";	
		var style	= "width: 800px; height: 470px; margin-left: -400px;";
	} else  if (ratio == "4:3g") {
		var width 	= "800";
		var height	= "620";			
		var player	= "videoplayer43g.swf";	
		var style	= "width: 800px; height: 620px; margin-left: -400px;";
	} else  {
		var width 	= "640";
		var height	= "500";			
		var player	= "videoplayer43.swf";	
		var style	= "margin-left: -320px;";
	}

	// Set Style for PopUp
	pu.setAttribute("style", style, 1);

	pu.innerHTML = tracking + '<div id="nmb_video-box-inner" style="position: relative;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="videoplayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="FlashVars" value="filename='+file+'" /><param name="movie" value="/fileadmin/flash/'+player+'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="wmode" value="opaque"><embed src="/fileadmin/flash/'+player+'" quality="high" FlashVars="filename='+file+'" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  wmode="opaque"/></object></div>';
}


function MarginalVideo_VideoOverlay(state) {
	if(state=="on") {
		// Popup
		var popupDIV	= document.createElement("div");
		document.body.insertBefore(popupDIV, document.body.firstChild);
		var neuCText 	= document.body.firstChild.setAttribute("id", "nmb_video-box-popup");	
				
		// Overlay
		var overlayDIV	= document.createElement("div");
		document.body.insertBefore(overlayDIV, document.getElementById('nmb_video-box-popup'));
		var neuBText 	= document.body.firstChild.setAttribute("id", "nmb_marginal_video_overlay");
		var neuDText 	= document.body.firstChild.setAttribute("onClick", "MarginalVideo_StopVideo()");
		document.getElementById('nmb_marginal_video_overlay').style.height = document.body.offsetHeight; 
	} else { // delete Div 
		document.body.firstChild.innerHTML = '';	
	  	var Knoten1 = document.body.firstChild;
	  	var Knoten2 = document.body.firstChild.nextSibling;
		document.body.removeChild(Knoten1);
		document.body.removeChild(Knoten2);
	}
}

function MarginalVideo_StartVideo(file,ratio,id,label) {
	MarginalVideo_VideoOverlay('on');
	MarginalVideo_WriteFlashObject(file,ratio,id,label);
}

function MarginalVideo_StopVideo() {
	MarginalVideo_VideoOverlay('off');
}



