/******************************************************************/
/* © DMC 01 Consulting & Development GmbH - gerald.urbas@dmc01.at */
/******************************************************************/
/* Flashmedia Frontend Code Plugin in                             */
/******************************************************************/
/* Object generates Flashmedia HTML code                          */
/* can get evolved for styled buttons. able to provide            */
/* Flashmedia-Interface player plugin                             */
/******************************************************************/

//if (detected_plugin_versions['flashmedia']>=9) {

function flashmedia_Playercode(pt,kontext,vt) {
	this.name = "Flash"; // player frontend name
	this.typ = "flashmedia"; // Type
	this.detectionplugin = "Shockwave Flash"; // detection plugin string
	this.objid="FLASHCONTENT"+Math.round(Math.random()*10000); // Object ID 4 HTML
	this.playertype = pt // home or extended or simple
  this.videotype = vt // zusatz br
	this.connurls = false; // initially there are no urls
	this.previewimage = false;
  try {

        if (!player.player_world) {

                this.playerurl = FLASHPLAYERFILE+'?benicetoie6='+this.objid;
        } else {

                this.playerurl = FLASHPLAYERFILE_WORLD+'?benicetoie6='+this.objid;
        }

	} catch (e) {

			this.playerurl = FLASHPLAYERFILE+'?benicetoie6='+this.objid;

			try {

				if (!player1.player_world) {

					this.playerurl = FLASHPLAYERFILE+'?benicetoie6='+this.objid;
				} else {

					this.playerurl = FLASHPLAYERFILE_WORLD+'?benicetoie6='+this.objid;
				}

			} catch (e) {

	this.playerurl = FLASHPLAYERFILE+'?benicetoie6='+this.objid;
			}
	}


	this.skinnningurl = FLASHSKINNNINGFILE;
	this.connectionxml = FLASHCONNXMLFILE;
	this.bgcolor="#ffffff"; // background color SWF Object
	this.playercontrols={// special HTML tag properties for embedding, and object code in HTML frontend
		'simple':{
			'embed':'controls="ImageWindow"',
			'object':'<param name="controls" value="ImageWindow" />'
			},
    'kontext':{
			'embed':'controls="ImageWindow"',
			'object':'<param name="controls" value="ImageWindow" />'
			},
		'home':{
			'embed':'controls="ImageWindow"',
			'object':'<param name="controls" value="ImageWindow" />'
			},
		'extended':{
			'embed':'controls="ImageWindow,StatusBar"',
			'object':'<param name="controls" value="ImageWindow,StatusBar" />'
		}
	};
	
	// define Flash embed sizes in config.js
	this.FLASHEMBEDAUDIOW=FLASHEMBEDAUDIOW
	this.FLASHEMBEDAUDIOH=FLASHEMBEDAUDIOH
	this.FLASHEMBEDSIMPLEW=FLASHEMBEDSIMPLEW
	this.FLASHEMBEDSIMPLEH=FLASHEMBEDSIMPLEH
  this.FLASHEMBEDKONTEXTW=FLASHEMBEDKONTEXTW
	this.FLASHEMBEDKONTEXTH=FLASHEMBEDKONTEXTH
	this.FLASHEMBEDW=FLASHEMBEDW
	this.FLASHEMBEDH=FLASHEMBEDH
	this.FLASHEMBEDHQW=FLASHEMBEDHQW
	this.FLASHEMBEDHQH=FLASHEMBEDHQH
	
	this.playercontrolsheight={ // all Players generet there own control heigts... wo correction values definined here
		'simple':{
			'embed':0,
			'object':0
			},
    'kontext':{
			'embed':0,
			'object':0
			},
		'home':{
			'embed':0,
			'object':0
			},
		'extended':{
			'embed':29,
			'object':29
			}
	};
	
	
	// there are replaceable strings defined in player.js, %varname%.. used in this strings
	// we usw swfobject to create Flash embed/objectcode/...
	this.jscode = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDW%", "%FLASHEMBEDH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "0");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
										+ '  so.setAttribute("wmode", "opaque");'
                    + '  so.write("'+this.objid+'div");';
	// HQ needs some special things
	this.jscodehq = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDHQW%", "%FLASHEMBEDHQH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "1");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
										+ '  so.setAttribute("wmode", "opaque");'
                    + '  so.write("'+this.objid+'div");';
	// HQ needs some special things
	this.jscodesimple = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDSIMPLEW%", "%FLASHEMBEDSIMPLEH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "3");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
                    + '  so.write("'+this.objid+'div");';
               
	// zusatz Kontext
	this.jscodekontext = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDKONTEXTW%", "%FLASHEMBEDKONTEXTH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "3");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
                    + '  so.write("'+this.objid+'div");';
	// SWF 4 Home
	this.jscodehome = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDSIMPLEW%", "%FLASHEMBEDSIMPLEH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "3");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
                    + '  so.write("'+this.objid+'div");';

	// Popup needs too some special things
	this.jscodepopup = '  var so = new SWFObject("'+this.playerurl+'&andtopopups=1", "'+this.objid+'popupid", "100%", "100%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "popupcontent");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "2");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
                    + '  so.write("popupcontent");';
	// Popup needs too some special things
	this.jsaudio = '  var so = new SWFObject("'+this.playerurl+'", "'+this.objid+'", "%FLASHEMBEDAUDIOW%", "%FLASHEMBEDAUDIOH%", "%VERSION%", "'+this.bgcolor+'");'
                    + '  so.addParam("wmode", "opaque");'
                    + '  so.addParam("swliveconnect", "true"); '
                    + '  so.addVariable("objId", "'+this.objid+'");'
                    + '  so.addVariable("isLiveStream", "%ISLIVE%");'
                    + '  so.addVariable("mp3data", "%AUDIO%");'
                    + '  so.addVariable("localmp3", "%ISMP3%");'
                    + '  so.addVariable("server", "%SERVER%");'
                    + '  so.addVariable("starget", escape("%FILENAME%"));'
                    + '  so.addVariable("sheight", "%H%");'
                    + '  so.addVariable("swidth", "%W%");'
                    + '  so.addVariable("smode", "%MODE%");' //normal 0 / hq 1 / popup 2
                    + '  so.addVariable("autoStart", "%AUTOSTART%");'
                    + '  so.addVariable("buffer", "%BUFFER%");'
                    + '  so.addVariable("kontext", "%KONTEXT%");' // zusatz Kontext
                    + '  so.addVariable("xmlFile", "'+this.skinnningurl+'");'
                    + '  so.addVariable("xmlConnectFile", "'+this.connectionxml+'");'
                    + '  so.addVariable("showRecommend", "'+show_recommend+'");'
                    + '  so.addVariable("previewImage", "%PREIMG%");'
                    + '  so.addVariable("startMovieAt", "%STARTAT%");'
				        	//+ '  so.addVariable("debugmodus", "0");'
                    + '  so.setAttribute("style", ";");'
                    + '  so.write("'+this.objid+'div");';
	
	//this.flashparams = this.jscode;
	//this.flashparams = "";
	
	// Jquery inserts just this div as target for swfobject
	this.playerstring = '<div id="'+this.objid+'div" class="playerflashposition">'
                    + 'Dieser Text wird durch den Flashinhalt ersetzt.'
                    + '</div>';

	this.playercall= function() { // callback after rendering. RP doesnt use it here.
		movieName = this.objid;
		var conn = arguments[1]; // get conn param
		var code=this.jscode; // get the JS code
		if (conn==3) { // if Conn is HQ we use another SWFobjectbase
			var code=this.jscodehq; // set it...
		}
		if (this.playertype=='home') {
			var code=this.jscodehome; // set it...
		}
		if (this.playertype=='simple') {
			var code=this.jscodesimple; // set it...
		}
    // zusatz Kontext
    if (this.playertype=='kontext') {
			var code=this.jscodekontext; // set it...
		}
		if (this.mp3stream==1) {
			var code=this.jsaudio; // set it...
		}
		code = this.replace(code,conn);	 // use replace funtion definiend in player prototype for filling out %vars%
		eval(code); // eval the code... Jquery pasted code doesnt interpete JS so we need to eval it...
		playmovie(this.objid);
	};
	
	 // add public methods
	this.enabled = true;
	this.write = writeplayercode;
	this.replace = replaceVars;
	this.setsizes = setsizes;
	this.setconn = setconn;
	this.setplayertype = setplayertype;
	this.setautostart = setautostart;	
	this.setglobid = setglobid;
	this.call_popup = playerPopup;
	this.close_popup = playerPopupClose;
	this.call_carrier = carrierPopup
	this.cutflv = cutflv;
	this.cutmp3 = cutmp3;
	this.setPreviewimage = setPreviewImage;
	this.getPreviewimage = getPreviewImage;
	this.previewImage = previewImagecall;
	// add inline methods 
	this.popup = function() { // this function is used by the popup window... (see doc there)
		var code=this.jscodepopup;
		conn = player.settings['conn'];
		code = this.replace(code,conn);
		return code;
	}	
	this.getconn = function () {
		return this.connurls;
	}
	this.report = function () {
		return "Player:"+this.name+" obid:"+this.objid+" url:"+this.connurls;
	};
	// later this can be evolved to provide transparent and identically Interfaces
	// play button
	
	this.shutdown = function () {
		return;
	}
	
	this.play = function () {
		playmovie(this.objid)
	};
	// pause button
	this.pause = function () {
		this.stop();
	};
	
	this.stop = function () {
		stopmovie(this.objid)
	};

	
	this.fullscreen = function() {
		this.stop();
		this.call_popup();
	}
	
	this.carrier = function () {
		this.call_carrier(170);
	}
	
	this.debug = function (str) { // debuglayer is deativated @ moment
		dbg("flashplugin: "+str);
	};
	
	this.testscriptconn  = function () {
		//alert("flash")
		// Flash does normal popups.. so return always true
		return true;
	}
	 // add anonn methods 
}
//} else {

//flashmedia_Playercode = quicktime_Playercode;

//}
// Prototype of this object is playercode
flashmedia_Playercode.prototpe = new playercode();

//global popup var for flashplayer
var popup=false;


function flashpopup() { // callback from SWF, opening Popup Fullscreenplayer
	dbg("flashpopup function deprecated")
	//alert("flashpopup")
	//popup = window.open('popup.html','fpopup','directories=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,location=no,hotkeys=no')
	//popup.player = player;
	//popup.focus();
}

function flashpopupback() { // callback from SWF,  Popup SWF state calls this for closing the window
	dbg("flashpopupback function deprecated")
	//opener.popup.close();
}

function flashhqclose(){ // callback from SWF, Close the HQ player from Flash
	player.closeHqPlayer();
}

var o_movieName = false;
var obj_f_popup =false;



var videoopended = false;

function videoclick(id) {
	dbg("Clicked into the Videoframe: "+id)
	dbg("Function deprecated");
	/*if (videoopended==false && typeof(player) != "undefined" && player.player_type=='home') {
		dbg("Loadpopup");
		player.loadPopup();
		videoopended = true;
	} else {
		dbg("videoclick: "+id+" no Popup in this mode")
	}*/
	return;
}


		//var movieName = "player";

function thisMovie(mymovieName) {
	dbg("thisMovie: "+mymovieName)
	// IE and Netscape refer to the movie object differently.
	// This function returns the appropriate syntax depending on the browser.
	if (typeof(obj_f_popup) != "undefined" && obj_f_popup!=false) {
		if (navigator.appName.indexOf ("Microsoft") !=-1) {
			return obj_f_popup.window[mymovieName];
		} else {
			return obj_f_popup.document[mymovieName];
		}
	}
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return window[mymovieName];
	} else {
		return document[mymovieName];
	}
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
	dbg("movieIsLoaded: "+theMovie)
	if (typeof(theMovie) != "undefined" && theMovie!=undefined) {
		try {
			return theMovie.PercentLoaded() == 100;
		} catch(e) {
			dbg("theMovie.PercentLoaded is not defined "+e);
		}
	} else {
		dbg("theMovie is undefined");
		return false;
	}
}

function playmovie() {
	dbg("playmovie: "+movieName)
	if (movieIsLoaded(thisMovie(movieName))) {
		thisMovie(movieName).TPlay("_level0/mc");
	}
}

function stopmovie(mymovieName) {
	dbg("stopmovie: "+mymovieName)
		//alert(1)
	if (movieIsLoaded(thisMovie(mymovieName))) {
		thisMovie(mymovieName).TGotoLabel("_level0/mc", "stop");
		//alert(2+" "+mymovieName)
	}
}

function flashescape(id) {
	dbg("flashescape: "+id);
	var flashpopupclosed=false;
	try {
		if (typeof opener.player!="undefined") {
			opener.player.closePopup();
			window.close();
			flashpopupclosed=true;
		}
	} catch(e) {
			dbg("flashescape: popup escape failed "+id+" "+e);
	}
	try {
		if (flashpopupclosed==false && player.settings['conn']==3) {
			player.closeHqPlayer();
		}
	} catch(e) {
		dbg("flashescape: HiqhQ failed "+id+" "+e);
	}
}
		
function flashplayexecute(id) {
	dbg("flashplayexecute: "+id);
	for (p in loaded_Players) {
		var pobj = loaded_Players[p];
		var pobj_id= pobj.players[pobj.currentplayer].objid;
		if (pobj_id!=id) {
			dbg("stop"+" "+pobj_id);
			stopmovie(pobj_id);
		}
		/* IVW removed by Play-Click-Handler */
		//pobj.countIVW();
		
	}
}

function moviestopped(id) {
	dbg("moviestopped"+id)
	if (typeof player!="undefined") {
		if (player.player_type == 'extended') {
			dbg("moviestopped - show recommend pane")
			var tab = "recommend";
			$j("#b_"+ec_current).removeClass("optActive"); // remove Class from old current
			var tab = "recommend";
			if (player.function_urls[tab]!=false) {
				closeHelpInfoObj()
				var cobj = $j("#optionBoxContainer"); // tab content container 
				var obj = $j("#b_"+tab); // the ivotebutton
				var url = player.function_urls[tab]; // Some URL defined in the baseHTML code
				cobj.empty(); // first empty the content container
				loading($j('#optionBoxContainer')); // loading animation
				cobj.load(url+APPHTMLEXTENSION,null); // load the url
				cobj.attr("url",url); // set an attr (used by button funcitons
				$j.getScript(url+APPJSEXTENSION); // Some Tabvs need some aditional JS code... but infopane doesnt!
				obj.addClass("optActive"); // Add correct klass to Button obj.
				ec_current = tab; // set current layer... later used to deativate Buttons--
			}
		} else {
			dbg("moviestopped - player is not extended!")		
		}
	} else {
		dbg("moviestopped - player object is not avaible!")			
	}
}
function setMovieTime(time) {
	//alert(time)
	//$j.cookie('currentTime',time);
	startat = time;
}
