/* DETECTIONS */


var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;


if (checkIt('konqueror')) {
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('firefox')) browser = "Firefox"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible')) {
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";




if (!version) version = detect.charAt(place + thestring.length);

if (!OS) {
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}


/* PLAYER OPERATIONS */

var urlToPlay;
var playerPaused = false;
var playerMuted = false;
var playerPlaying = true;

function startPlayer(clipUrl) {
	

	
	errorOccured = false;
	urlToPlay = clipUrl;
	
	if ( pluginlist.indexOf("Windows Media Player") != -1) {
		document.getElementById("defaultScreen").innerHTML="";
		playerPlaying = true;
		var string = '';
		var toEmbed = true;
		
		if (browser == 'Internet Explorer') {
			toEmbed = false;
		}
		
		
		if (!toEmbed) {
			document.Player.URL = clipUrl;
		} else {
			string +='<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" width="266px" height="200px" filename="'+clipUrl+'" autostart="True" showcontrols="True" showstatusbar="False" showdisplay="False" autorewind="True" style="margin-left:5px;"></embed>';
		}

		if (toEmbed) document.getElementById("screenContent").innerHTML = string;

		if (!toEmbed) {
			document.Player.uiMode = 'none';
			document.Player.style.display='block';
			document.Player.controls.play();
			
		}
		
		
		if (!toEmbed) {
			document.getElementById("soundBtn").innerHTML = '<a href="#Player" onClick="mutePlayer()" title="Спри Звука"><img src="img/sound_btn_on.gif" id="soundStatPic" alt="Спри Звука"/></a>';
			document.getElementById("soundBtn").style.display = 'block';
			document.getElementById("screenBtn").innerHTML = '<a href="javascript:pausePlayer();" title="Паузирай"><img src="img/index_video_btn_stop.gif"/></a>';
		} else {
			document.getElementById("soundBtn").style.display = 'none';
		}
		
	} else {
		document.getElementById("videoError").innerHTML = '<strong>Грешка: </strong>Вие нямате инсталиран Microsoft Windows Media Player. Ако желаете, можете да го инсталирате от <a href="http://www.microsoft.com/windows/windowsmedia/player/download/download.aspx"><b>тук</b></a>.';
	}
	
}

function pausePlayer() {
	if (!playerPaused) {
		document.Player.controls.stop();
		document.getElementById("screenBtn").innerHTML = '<a href="javascript:pausePlayer();"  title="Продължи"><img src="img/index_video_btn.gif"  title="Продължи"/></a>';
		document.getElementById('screenContent').focus();
		playerPaused = true;
		playerPlaying = false;
	} else {
		document.Player.controls.play();
		document.getElementById("screenBtn").innerHTML = '<a href="javascript:pausePlayer();" title="Спри"><img src="img/index_video_btn_stop.gif" alt="Спри"/></a>';
		document.getElementById('screenContent').focus();
		playerPaused = false;
	}
}


function mutePlayer() {
	if (!errorOccured) {
		if (!playerMuted) {
			document.Player.settings.mute = true;
			document.getElementById('soundStatPic').src = 'img/sound_btn_off.gif';
			document.getElementById('soundStatPic').title = 'Пусни звука';
			document.getElementById('screenContent').focus();
			playerMuted = true;
		} else {
			document.Player.settings.mute = false;
			document.getElementById('soundStatPic').src = 'img/sound_btn_on.gif';
			document.getElementById('soundStatPic').title = 'Спри звука';
			document.getElementById('screenContent').focus();
			playerMuted = false;
		}
	}
}


/* PLUGINS DETECTION */



var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (browser == "Opera") { 
	ns = true;
	ie = false;
	}

if (ie && win) {	pluginlist = detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player"); }
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}

function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);