



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
		this.haveQT = this.haveQuickTime();
	},
	haveQuickTime: function () {	//pridana funkce
		if (navigator.plugins) {
			for (i=0; i < navigator.plugins.length; i++ ) {
				if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
				 return true; 
				}
			}
		}
		if ((navigator.appVersion.indexOf("Mac") > 0)
			&& (navigator.appName.substring(0,9) == "Microsoft")
			&& (parseInt(navigator.appVersion) < 5) ) { 
			return true; 
		}
		return false;
	},			
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};




















var MyPlayer = {

	//init
	init: function (settings) {
		
		
		//settings = { width: 400, height: 400 };
		BrowserDetect.init();	// detekuji browser a OS
		this.browserType = BrowserDetect.browser;	//nastavim browser
		this.osType = BrowserDetect.OS;	//nastavim OS
		this.haveQT = BrowserDetect.haveQT;	//nastavim jestli ma quicktime


		this.browserCheckCanPlay();	//zjistim, jestli muzu hrat nebo ne

		//velikost okna prehravace
		this.playerWidth = settings.width;
		this.playerHeight = settings.height;
	},

	//funkce pripravi prehravac 
	showVideo: function (url) {
		
		
		var soundUrl = url;
	

		if (this.browserType == 'Explorer' ) {
			var text = '<OBJECT ID="mySound" width="'+this.playerWidth +'" height="'+this.playerHeight +'"  ' +
			'	classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ' +
			'	codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ' +
			'        STANDBY="Loading Microsoft Windows Media Player components..." ' +
			'        type="application/x-oleobject"> ' +
			'  <PARAM NAME="AutoStart" VALUE="false"> ' +
			'  <PARAM NAME="FileName" VALUE="' + soundUrl + '"> ' +
			'  <PARAM NAME="ShowControls" VALUE="True"> ' +
			'  <PARAM NAME="ShowStatusBar" VALUE="True"> ' +
			'<EMBED id="mySound" name="mySound" src="'+soundUrl+'" type="application/x-mplayer2"' +  
			' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="'+this.playerWidth +'" height="'+this.playerHeight +'" ></EMBED> ' +
			'</OBJECT>';
	
	
		} else if (this.browserType== 'Firefox' && this.osType == 'Windows' ) {	//na windows
	
			var text = '<OBJECT id="dmySound" width="'+this.playerWidth +'" height="'+this.playerHeight +'" ' +
			'	classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" ' +
			'     > ' +
			'  <PARAM NAME="AutoStart" VALUE="false"> ' +
			'  <PARAM SRC="FileName" VALUE="' + soundUrl + '"> ' +
			'  <PARAM NAME="ShowControls" VALUE="True"> ' +
			'  <PARAM NAME="ShowStatusBar" VALUE="True"> ' +
			'<EMBED id="mySound" name="mySound" src="'+soundUrl+'" type="application/x-mplayer2"' +  
			' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="'+this.playerWidth +'" height="'+this.playerHeight +'" ></EMBED> ' +
			'</OBJECT>';

	
		} else if (this.browserType== 'Firefox' && this.osType == 'Linux') {	//asi to bude linux
				// type="application/x-mplayer2"' 
			var text =  '<EMBED id="mySound" name="mySound" src="'+soundUrl+'" ' +
			' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="'+this.playerWidth +'" height="'+this.playerHeight +'" autostart=0 ></EMBED>';
		
	
		} else {
			this.browserCannotPlay();
			return;
		}

		return text;
			
	},
	
	
	 


	//funkce zjisti, jestli muzu hrat
	browserCheckCanPlay: function () {

		//pokud neni mozne prehravat, upozornim na to
		if (!(
			(this.browserType == 'Explorer') 	//IE
		  	|| ( this.browserType== 'Firefox' && this.osType == 'Windows' )	//FF na windows
		  	|| (this.browserType== 'Firefox' && this.osType == 'Linux')	//FF a linux
			))
		{
			this.browserCannotPlay();
			return;
		} 
		
	},


	//pokud nelze prehravat, ukonci se to
	browserCannotPlay: function () {
		alert('Váš prohlížeč a nastavení nepodporuje přehrávání!\r\n' +
		'Stránku lze přehrávat pouze pokud je splňena alespoň jedna z následujících podmínek:\r\n' +
		'1. operační systém Windows + prohlížeč Internet Explorer + Windows Media Player\r\n' +
		'2. operační systém Windows + prohlížeč Firefox 2.0.0.11 a vyšší + + Windows Media Player\r\n ' +
		'3. operační systém Linux + prohlížeč Firefox 2.0.0.11 a vyšší + plugin Mplayer pro Firefox\r\n');
		clearInterval(timerID);
		return false;
	}




}









