/******************************************************************/
/* © DMC 01 Consulting & Development GmbH - gerald.urbas@dmc01.at */
/******************************************************************/
/* Micorosoft Media Player Frontend Code Plugin in                */
/******************************************************************/
/* Object generates Media Player HTML code                        */
/* can get evolved for styled buttons. able to provide            */
/* MMP-Interface player plugin                                    */
/******************************************************************/

function microsoftmedia_Playercode(pt) {
	this.name = "Windows Media"; // player frontend name
	this.typ = "microsoftmedia"; // Type
	this.detectionplugin = "Windows Media Player"; // detection plugin string
	this.objid = "MEDIAPLAYERCONTROL"+Math.round(Math.random()*10000); // Object ID 4 HTML
	this.playertype = pt // home or extended
	this.connurls = false;// initially there are no urls
	this.playercontrols={// special HTML tag properties for embedding, and object code in HTML frontend
		'simple':{
			'embed':'uiMode="mini" ShowControls="1" ShowStatusBar="0" ShowPositionControls="0" ShowTracker="1"',
			//'embed':'uiMode="full" EnableFullScreenControls="1"  ShowControls="1" ShowStatusBar="1" ShowPositionControls="0" ShowTracker="0"',
			'object':'<param name="uiMode" value="mini" /><param name="ShowControls" value="1" /><param name="ShowStatusBar" value="0" /><param name="ShowPositionControls" value="0" /><param name="ShowTracker" value="0" />'
			},
		'home':{
			'embed':'transparentAtStart="true" wmode="transparent" uiMode="mini"  ShowControls="1" ShowStatusBar="0" ShowPositionControls="0" ShowTracker="0"',
			'object':'<param name="transparentAtStart" value="true"> <param name="wmode" value="transparent" /><param name="uiMode" value="mini" /><param name="ShowControls" value="1" /><param name="ShowStatusBar" value="0" /><param name="ShowPositionControls" value="0" /><param name="ShowTracker" value="0" />'
			},
		'extended':{
			'embed':'uiMode="full" EnableFullScreenControls="1"  ShowControls="1" ShowStatusBar="1" ShowPositionControls="0" ShowTracker="0"',
			'object':'<param name="uiMode" value="mini" /><param name="ShowControls" value="1" /><param name="ShowStatusBar" value="1" /><param name="ShowPositionControls" value="0" /><param name="ShowTracker" value="0" />'
			}
	};
	
	this.playercontrolsheight={ // all Players generet there own control heigts... wo correction values definined here
		'simple':{
			'embed':0,
			'object':0
			},
		'home':{
			'embed':24,
			'object':24
			},
		'extended':{
			'embed':24,
			'object':64
			}
	};
	// there are replaceable strings defined in player.js, %varname%.. used in this strings
	// embed HTML code
	this.playerstring = '<div id="'+this.objid+'" class="playerwmpposition">'
                    + 'Dieser Text wird durch das Windows Media Plugin ersetzt.'
                    + '</div> '
										+'';


	this.debug = function (str) { // debuglayer is deativated @ moment
		dbg("WMP plugin: "+str);
	};
	
	this.testscriptconn  = function () {
		try {
			var obj = document.getElementById(this.objid);
			try {
				obj.controls.currentItem;
				return true;
			} catch(e) {
				return false;
			}
		} catch(e) {
			return false;
		}
		return false;
	}
	
	this.testversion = function() {
		this.is_scriptable = false;
		if ($j.browser.msie == true) {
			var teststring = '<OBJECT ID="testPlayer7" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><PARAM name="uiMode" value="invisible"></OBJECT>';
			$j("BODY").append(teststring);
			obj = document.getElementById('testPlayer7');
			this.exactwmpVersioninfo = obj.versionInfo;
			this.version = obj.versionInfo.split('.')[0];
			$j('#testPlayer7').remove();
			if (this.version>=7) {
				this.is_scriptable = true;
			}
		}
	}
	
	
	this.playercall= function() {// callback after rendering. RP doesnt use it here.
		var tgtobj = arguments[0]; // get conn param
		var conn = arguments[1]; // get conn param
		this.testversion();
		this.debug("scriptable "+this.is_scriptable)
		this.debug("version full "+this.exactwmpVersioninfo)
		this.debug("version major "+this.version)
		$j("#"+tgtobj).empty();
		
		var activeXobject = '<OBJECT ID="'+this.objid+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="%W%" height="%OBJECTH%"><PARAM name="uiMode" value="full"><param name="URL" value="%URL%" /><PARAM name="fullScreen" value="false "><PARAM name="windowlessVideo" value="false"></OBJECT>'
								+ '<SCRIPT LANGUAGE = "JScript"  FOR ="'+this.objid+'" EVENT = PositionChange ()>'
								+ 'dbg(this.id+ " - "+arguments[0]+ " - "+arguments[1]);'
								+ '</SCRIPT>';
		var activeXobjectFullscreen = '<OBJECT ID="'+this.objid+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="%W%" height="%OBJECTH%"><PARAM name="uiMode" value="full"><param name="URL" value="%URL%" /><PARAM name="fullScreen" value="true"><PARAM name="windowlessVideo" value="false"></OBJECT>'
								+ '<SCRIPT LANGUAGE = "JScript"  FOR ="'+this.objid+'" EVENT = PositionChange ()>'
								+ 'dbg(this.id+ " - "+arguments[0]+ " - "+arguments[1]);'
								+ '</SCRIPT>';
		var iEobject = '<object name="'+this.objid+'" id="'+this.objid+'" '
								+ ' width="%W%" height="%EMBEDH%" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"'
								+ 'standby="Loading Windows Media Player components..."'
								+ 'type="application/x-oleobject"'
								// + 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"'
								+ 'name="wmp" border="0">'
								+ '<param name="FileName" value="%URL%" />'
								// + '<param name="URL" value="%URL%" />'
								+ '%OBJECTCONTROLS%'
								+ '<param name="AutoStart" value="%AUTOSTART%" />'
								+ '</object>';
		var iEobjectFullscreen = '<object name="'+this.objid+'" id="'+this.objid+'" '
								+ ' width="%W%" height="%EMBEDH%" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"'
								+ 'standby="Loading Windows Media Player components..."'
								+ 'type="application/x-oleobject"'
								// + 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"'
								+ 'name="wmp" border="0">'
								+ '<param name="FileName" value="%URL%" />'
								+ '<param name="fullScreen" value="true">'
								// + '<param name="URL" value="%URL%" />'
								+ '%OBJECTCONTROLS%'
								+ '<param name="AutoStart" value="%AUTOSTART%" />'
								+ '</object>';
		var fFembed = '<embed type="application/x-mplayer2" name="'+this.objid+'" id="'+this.objid+'" '
								+ ''
								+ 'width="%W%" height="%EMBEDH%" border="0" '
								+ 'pluginspage="http://www.microsoft.com/netshow/download/player.htm" '
								+ 'src="%URL%" '
								+ '%EMBEDCONTROLS% '
								+ 'AutoStart="%AUTOSTART%" DisplaySize="4">'
								+ '</embed>';
		if (this.playertype=='home') { // Only Extended Player needs modern Plugin integration 4 Fullscreen mode
			this.debug("WMP Loading info hack")
			$j("#"+tgtobj).hide();
			$j("#"+tgtobj).after('<div id="wmploadinginfo'+tgtobj+'" class="statusmsg"></div>');
			try {
				loading($j("#wmploadinginfo"+tgtobj));
			} catch(e){}
			$j("#wmploadinginfo"+tgtobj).load('error/wmploading'+APPHTMLEXTENSION,null);
			$j("#wmploadinginfo"+tgtobj).fadeOut(3500,function(){
			$j("#"+tgtobj).fadeIn();
			});
		}
		if (this.playertype=='home' || this.playertype=='simple') { // Only Extended Player needs modern Plugin integration 4 Fullscreen mode
			this.debug("wmp IE 7+ Interface disabled")
			this.is_scriptable = false 
		}
		if ($j.browser.msie == true && this.is_scriptable==true) {
			this.debug("wmp IE sciptable")
			$j("#"+tgtobj).append(this.replace(activeXobject,conn));
			//obj = document.getElementById(this.objid);
			//WMPINTERVALLCHECKER = window.setInterval("setPositionHandle('"+this.objid+"')", 1000); 
			//this.genUi(tgtobj,this.playertype,obj.settings.volume);
			this.fullscreencode = this.replace(activeXobjectFullscreen,conn);
		}
		if ($j.browser.msie == true && this.is_scriptable==false) {
			this.debug("wmp IE not sciptable")
			//this.playercontrolsheight.extended.object = 29;
			$j("#"+tgtobj).append(this.replace(iEobject,conn));
		}
		this.popupcode=iEobject;
		if ($j.browser.msie != true) {
			this.debug("wmp NO IE")
			$j("#"+tgtobj).append(this.replace(fFembed,conn));
			this.popupcode=fFembed;
			this.debug("embeding WMP finished");
		}
		this.play();
		try	{
			player.play();
			window.setTimeout("player.play();", 3000);			
		} catch (e)	{ dbg(e)}
	};
	this.enabled = true; // we are here -  so we use this object.
	// add public methods
	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.genUi = generateUi;
	// add inline methods 	
	this.popupcode = "";
	this.popup = function() { // this function is used by the popup window... (see doc there)
		var code=this.popupcode;
		conn=3;
		code = this.replace(code,conn);
		return '$j("#popupcontent").empty();$j("#popupcontent").append(\''+code+'\')';
	}
	
	this.getconn = function () {
		return this.connurls;
	}
	this.report = function () {
		return "Player:"+this.name+" obid:"+this.objid+" url:"+this.connurls;
	};
	this.shutdown = function () {
		window.clearInterval(WMPINTERVALLCHECKER);
		return;
	}
	// play button
	
	this.play = function () {
		if (this.is_scriptable==true) {
			this.debug("WMP internal play");
			var obj = document.getElementById(this.objid);
			try {
			obj.controls.play();
			} catch(e) {
			obj.play();
			}

		} else {
			this.debug("unscriptable WMP internal play");
		}
	};
	// pause button
	this.pause = function () {
		if (this.is_scriptable==true) {
			this.debug("WMP internal pause");
			var obj = document.getElementById(this.objid);
			try {
			obj.controls.pause();
			} catch(e) {
			obj.pause();
			}
		} else {
			this.debug("unscriptable WMP internal pause");
		}
	};
	
	// stop button
	this.stop = function () {
		if (this.is_scriptable==true) {
			this.debug("WMP internal stop");
			var obj = document.getElementById(this.objid);
			try {
			obj.controls.stop();
			} catch(e) {
			obj.stop();
			}
		} else {
			this.debug("unscriptable WMP internal stop");
		}
	};
	
	this.fastf = function () {
		if (this.is_scriptable==true) {
			this.debug("WMP internal fastf");
			var obj = document.getElementById(this.objid);
			obj.controls.fastForward()
			setPositionHandle(this.objid)
		} else {
			this.debug("unscriptable WMP internal fastf");
		}
	};
	
	this.fastr = function () {
		if (this.is_scriptable==true) {
			this.debug("WMP internal fastr");
			var obj = document.getElementById(this.objid);
			obj.controls.fastReverse()
			setPositionHandle(this.objid)
		} else {
			this.debug("unscriptable WMP internal fastr");
		}
	};
	
	this.position = function (pos) {
		if (this.is_scriptable==true) {
			this.debug("WMP internal position");
			var obj = document.getElementById(this.objid);
			var duration = obj.currentMedia.duration;
			var newpos = (duration/100)*pos
			obj.controls.pause();
			obj.controls.currentPosition = newpos;
			obj.controls.play();
		} else {
			this.debug("unscriptable WMP internal position");
		}
	};
	
	this.fullscreen = function(conn) {
		if (this.is_scriptable==true) {
			this.debug("WMP Fullscreen");
			try{
				this.debug("WMP Fullscreen - try to generate new Object 4 fullscreen mode from WMP object");
				this.stop();
				$j('#'+this.objid).empty();
				$j('#'+this.objid).hide();
				var jqobj = $j('#'+this.objid).parent();//
				jqobj.empty();
				jqobj.append(this.fullscreencode);
				this.play();
				window.setTimeout("player.play();", 3000);
				fullscreenactive=true;
			}catch(e){
				this.debug("WMP Fullscreen - error: "+e);
			}
		} else {
			this.debug("unscriptable WMP Fullscrenn");
		}
	};
	
	this.carrier = function () {
		this.call_carrier(240);
	}
	
	this.volume = function(vol) {
		if (this.is_scriptable==true) {
			this.debug("WMP volume");
			var obj = document.getElementById(this.objid);
			obj.settings.volume = vol;
		} else {
			this.debug("unscriptable WMP volume");
		}
	};
	
	this.mute = function(mute) {
		if (this.is_scriptable==true) {
			this.debug("WMP Mute");
			var obj = document.getElementById(this.objid);
			obj.settings.mute = mute;
		} else {
			this.debug("unscriptable WMP Mute");
		}
	};
	 // add anonn methods 
}

function setPositionHandle(objid) {
		obj = document.getElementById(objid);
		var newpos = obj.controls.currentPosition;
		var slidepos = $j(".sliderpos").attr('nowpos');
		//dbg('das hats'+" "+newpos+" slpos"+slidepos +" | -:"+(newpos-10)+" +:"+(newpos+10));
		dbg("set Slider to"+newpos+" "+parseInt(newpos)+" slide:"+slidepos+" ??");
		$j('.sliderpos').SliderSetValues(
//			[[parseInt(newpos),0]]
			[[1,0]]
		);
		dbg("afterset Slider to"+newpos+" "+parseInt(newpos));
		dbg("object records Pos"+$j(".sliderpos").attr('nowpos'));
}// Prototype of this object is playercode
var WMPINTERVALLCHECKER;
microsoftmedia_Playercode.prototpe = new playercode();


