	var display_width;
	var display_height;
	var display_x;
	var display_y;
	var display_mode = 'normal';

	var redirector_address	= 'rtmp://streaming001.htz.broadcast.tneg.de/nrwtvOnDemand/';
	var video_file				= '/none/';
	var video_hq_file			= '';

	var player_dest = "/videoarchiv/broadcast.tneg.de/player/Broadcaster.swf";
	function start() {
		initApp();
		initVideoPlayer();			
	}


	function initVideoPlayer() {

		display_width	= $('#player').width();
		display_height	= $('#player').height();
		position			= $('#player').position();
		display_x			= $('#player').position().top;
		display_y			= $('#player').position().left;

		var so = new SWFObject(player_dest,"coreplayer","100%","100%","9");
		so.addParam("allowscriptaccess","always");
		so.addParam("allowfullscreen","true");
		so.addParam("wmode", "transparent");
		so.addVariable("redirector_address", redirector_address);
		so.addVariable("video_file", video_file);
		so.addVariable("video_hq_file", video_hq_file);
		
		if (dev == true) {
			vol = 1;
		} else {
			vol=75;
		}	
		so.addVariable("video_volume",vol);
		so.addVariable("language", "");
	//	so.addVariable("debug",true);
		so.write("STAGE");
	}


	function switchFullbrowser() {
		if (display_mode == 'normal') {
			$('#player').css("width","100%");
			$('#player').css("height","100%");
			$('#player').css('top','0px');
			$('#player').css('left','0px');
			display_mode='fullscreen';
			$('#debug').html($('#debug').html()+ "<br>DisplayMode: " + display_mode);
		} else {
			$('#player').css("width",display_width);
			$('#player').css("height",display_height);
			$('#player').css('top',display_x);
			$('#player').css('left',display_y);
			display_mode='normal';
			$('#debug').html($('#debug').html()+ "<br>DisplayMode " + display_mode);
		}
	}


	function getVoDPlayer() {
		var movieName = "coreplayer";
		 if (navigator.appName.indexOf("Microsoft") != -1) {
			 return window[movieName];
		 } else {
			 return document[movieName];
		 }
	 }


	//das AdObject wird initialisiert und aus dem js vom Bannerserver gefuettert
	var AdvertVideoObject = null;
	var VideoObject = null;
	var actionscript_status = false
	var advert_status = false

	//wenn Flash/AS sich meldet und das ADObj gesetzt ist, dann wird das werbevideo an AS uebergeben und abgespielt
	/*
	function as_ready(val) {
		actionscript_status = true;
		if (val == "ASready") {
			$('#debug').html($('#debug').html() + "<br>FlashApplikation ist einsatzbereit<br>" );
			checkAdvertStart();
			initLiveStream();
			if (video_obj != undefined) 	$('#meldungen').fadeOut(1000,function() {$('#meldungen').html('');start_video(video_obj);});
		}
	}*/
	
	//wenn Flash/AS sich meldet und das ADObj gesetzt ist, dann wird das werbevideo an AS uebergeben und abgespielt
	function as_ready(val) {
		actionscript_status = true;
		if (val == "ASready") {
			$('#debug').html($('#debug').html() + "<br>FlashApplikation ist einsatzbereit<br>" );
			if (video_obj != undefined) {
				window.setTimeout("$('#meldungen').fadeOut(1000,function() {$('#meldungen').html('');start_video(video_obj);});",550);
			}
		}
	}

	

	function setAdvertFromBannerServer(VObj) {
		AdvertVideoObject = VObj;
		advert_status = true;
		$('#debug').html($('#debug').html() + "Befehl vom Bannerserver erhalten<br>WerbeVideo: "+AdvertVideoObject.ad_location+AdvertVideoObject.ad_file+"<br><br>" );
		checkAdvertStart();
	}

	function checkAdvertStart() {
		if (advert_status==true && actionscript_status == true) {
			$('#debug').html($('#debug').html() + "Werbung wird geschaltet <br>" );
			if (AdvertVideoObject != null) {
				getVoDPlayer().setAdvertise(AdvertVideoObject);
			}
		}
	}

	//wenn Flash/AS sich meldet und das ADObj gesetzt ist, dann wird das werbevideo an AS uebergeben und abgespielt
	function advertise_done(val) {
		if (val == "preroll_played") {
			$('#werbehinweis').fadeOut(1000,function() {$('#werbehinweis').html('');});
		}
	}
	function advertise_start(val) {
		if (val == "preroll_started") {
			$('#werbehinweis').html('<div>Werbe-Video</div>');
			$('#werbehinweis').fadeIn();
		}
	}
	
	var video_obj;
	function initVideo(item,location,file,hq_file) {
		video_obj = {
				video_location: location,
				video_file: file,
				video_hq_file: hq_file
			};
		
		if (actionscript_status == true) {
			start_video(video_obj);
			$('#livestream_btn .sendung .image img').attr('src','http://nrw.tv/static/gfx/videoarchiv/live-gelb.png');
			$('#livestream_btn .sendung .title').css('color','#ffffff');
			$('#video_traeger').children().removeClass('active');
			$(item).parent().parent().toggleClass('active');
		} else {
			var info = '<div>Bitte gedulden sie sich noch einen Moment bis der Flashplayer geladen ist.</div>';			
			$('#meldungen').html(info);
			$('#meldungen').fadeIn(300);
		}		
	}

	function start_video(VObj) {
		try {
			VideoObject = VObj;
			//debug("start Video</div> Videolocation: "+VideoObject.video_location+ "<br>VideoFile: "+VideoObject.video_file+ "<br>High Quality: "+VideoObject.video_hq_file);
			getVoDPlayer().startVideo(VideoObject);
		} catch (e) {
			//$('#debug').html($('#debug').html() +"<br>" + e);
		}
	}
	

	function initLiveStream() {
		$('#video_traeger').children().removeClass('active');
		 video_obj = {
			video_location: 'rtmp://streaming001.htz.broadcast.tneg.de/redirect/nrwtv/',
			video_hq_file: '',
			video_file: 'nrwtv/nrwtv.flv',
			type:'live'	
		};
		 
		if (actionscript_status == true) {
			$('#livestream_btn .sendung .image img').attr('src','http://nrw.tv/static/gfx/videoarchiv/live-gruen.png');
			$('#livestream_btn .sendung .title').css('color','#4C990E');
			start_video(video_obj);	
		}
		var info = '<div style="height: 35px;" id="info_show"><div style="position: absolute; top: 0px; left: 0px;"><img alt="Sendungs-Logo" src="http://www.nrw.tv/static/gfx/videoarchiv/logo-nrwtv30x30.png"></div><div style="position: absolute; top: 10px; left: 38px; font-weight: bold; color: rgb(255,255,255);">NRW.TV Livestream</div></div><div id="info_title"></div><div class="SchriftMittel" id="info_subtitle">Das aktuelle Programm von NRW.TV</div><div id="info_desc">NRW.TV ist der private 24 Stunden-Landessender f&uuml;r Nordrhein-Westfalen. Der Sender erreicht rund 4,2 Millionen Haushalte. Ausserdem sendet NRW.TV live im Internet und ist so &uuml;berall empfangbar.<br></div>';			
		$('#videoinformation').html(info);	
	}
	
	
	var video_infos = {};
	function getVideoInfosfromPlayer() {
		getVoDPlayer().getVideoInfos();
	}
	
	function getVideoInfosResponse(res) {
	//	debug('getVideoInfosResponse: <br>' +	'Pl&auml;yhead: ' + Math.ceil(res.playhead_pos*100)/100 + ' - L&auml;nge: ' + Math.ceil(res.length),'#33bb33');
		video_infos.playhead = res.playhead_pos;
		video_infos.length = res.length;
	}
	
	function getVideoPlayhead() {
		getVideoInfosfromPlayer();
		return video_infos.playhead;
	}
	
	function getVideoDuration() {
		getVideoInfosfromPlayer();
		return video_infos.length;
	}
	
