﻿function showMore(id) {
	var b, t, s = document.getElementById(id).style,
	h = innerHeight || document.body.clientHeight;
	//ХГЛЕМЪЕЛ БШЯНРС ОНОЮО НЙМЮ,
	//ЕЯКХ НМН НФХДЮЕЛНИ БШЯНРШ (ДКЪ ГЮЫХРШ НР ХГЛЕМЕМХЪ ПЮГЛЕПЮ МЕ ОНОЮО НЙМЮ АПЮСГЕПЮ)
	t = document.body.getElementsByTagName('TABLE')[0];
	b = t.offsetHeight >= h;
	s.display =  s.display ? '': 'none';
	b && (
		window.resizeBy(0, t.offsetHeight - h)
	);
	return s.display == ''
}
function _showPos() {
	var p = _showPos._this, t, d;
	if (typeof p.o.controls == 'undefined') {
		return
	}
	t = p.o.controls.currentPosition;
	p.oPosition.innerHTML = p.getTimeStr(t);
	d = p.o.currentMedia.duration;
	d && (
		//ОПНДНКФХРЕКЭМНЯРЭ ХГБЕЯРМЮ.
		p.oProgres.getElementsByTagName('DIV')[1].style.width = Math.round(((p.oProgres.offsetWidth-15) * t / d)+15) + 'px'
	);
	d = p.o.network.downloadProgress;
	d && (
		p.oProgres.getElementsByTagName('DIV')[0].style.width = Math.round(((p.oProgres.offsetWidth-16) * d / 100)+15) + 'px'
	)
}
function getMouseRelativePosition(t, e) {
	var x = 0, y = 0;
	while (t && t != document.body) {
		x += t.offsetLeft;
		y += t.offsetTop;
		t = t.offsetParent
	}
	if (e.pageX || e.pageY)	{
		x = e.pageX - x;
		y = e.pageY - y;
	} else if (e.clientX || e.clientY) {
		x = e.clientX + document.body.scrollLeft - x
			+ document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop - y
			+ document.documentElement.scrollTop;
	}
	return {'x': x-1, 'y': y}
}
function classPlayer(o) {
	var i;
	this.o = o;
	this.o.style.height = 0;
	if (document.all && document.all.item && !window.opera) {
		document.execCommand('BackgroundImageCache',false,true)
	}
	this.oBtns = {
		'play': {'o': document.getElementById('playBtnID')},
		'stop': {'o': document.getElementById('stopBtnID')},
		'mute': {'o': document.getElementById('muteBtnID')}
	};
	this.oDuration = document.getElementById('playDurationID');
	this.oPosition = document.getElementById('playPositionID');
	i = this.oProgres = document.getElementById('playProgresID');
	this.oProgres._this = _showPos._this = this;
	window.setInterval('_showPos()', 250);
	//this.oProgres.onclick = _setPosition;
	i.ondragstart = new Function('event.returnValue = false');
	i.onmousedown = i.onmousemove = _setPosition;
	i = this.oVolume = document.getElementById('volumeBtnID');
	i._this = this;
	i.ondragstart = new Function('event.returnValue = false');
	i.onmousedown = i.onmousemove = _setVolume;
	document.attachEvent('onmouseup', new Function('document.getElementById(\'volumeBtnID\')._mouseBtnPress = 0; document.getElementById(\'playProgresID\')._mouseBtnPress = 0;'));
	for (i in this.oBtns) {
		this.oBtns[i].o._this = this;
		this.oBtns[i].o.onmouseout = _out;
	}
	i = this.oBtns.play.o;
	i.onclick = _PlayPause;
	i.onmouseover = _overPlayPause;
	i = this.oBtns.stop.o;
	i.onclick = _Stop;
	i.onmouseover = _overStop;
	i = this.oBtns.mute.o;
	i.onclick = _Mute;
	i.onmouseover = _overMute;
	this.playStateChange = _playStateChange;
	_showVolume(this, o.settings.volume);
	function _setPosition(e) {
		var t = this, x, y, o = t._this, d = o.o.currentMedia.duration;
		if (!d) return;
		e || (e = window.event);
		e.type == 'mousedown' && (t._mouseBtnPress = 1);
		if (!t._mouseBtnPress) {
			return
		}
		x = getMouseRelativePosition(t, e);
		x = x.x;
		y = t.offsetWidth;
		if (x < -10 || y+10 < x) {
			return
		}
		x < 0 && (x = 0);
		//y -= 14;
		x > y && (x = y);
		o.o.controls.currentPosition = d * x / y
	}
	this.getTimeStr = _getTimeStr;
	function _getTimeStr(n) {
		var s = '', t = {
			'h': Math.floor(n / 3600),
			'm': Math.floor(n % 3600 / 60),
			's': Math.floor(n % 60)
		};
		if (t.h) {
			s += t.m + ':'
		}
		t.m < 10 && (s += '0');
		s += t.m + ':';
		t.s < 10 && (s += '0');
		s += t.s;
		return s
	}
	function _playStateChange(n, oPlr) {
		var t = oPlr.oBtns.play, b;
		if (n==1 || n==2) {
			b = t.o._isOver? 'playOver': 'play';
			t.o.className = oPlr.o.controls.isAvailable('play')? b: 'playDisabled';
			t.o.title = '';
		}
		if (n==3) {
		//3 Playing
			b = t.o._isOver? 'pauseOver': 'pause';
			t.o.className = oPlr.o.controls.isAvailable('pause')? b: 'pauseDisabled';
			t.o.title = '';
			t = oPlr.oBtns.stop;
			t.o.className = t.o._isOver? 'stopOver': 'stop';
			t.o.title = 'Стоп';
			//БШБНДХЛ ОПНДНКФХРЕКЭМНЯРЭ БНЯОПНХГБЕДЕМХЪ (ЕЯКХ ДНЯРСОМЮ)
			t = oPlr.o.currentMedia.duration;
			oPlr.oDuration.innerHTML = _getTimeStr(t);
			t || (//ОПНДНКФХРЕКЭМНЯРЭ МЕХГБЕЯРМЮ.
				oPlr.oProgres.firstChild.style.width = ''
			);
		}
		if (n == 1) {
		//1 Stopped
			oPlr.oBtns.stop.o.className = 'stopDisabled';
		}
	}
	function _overPlayPause() {
		var t = this._this, k = {1:1, 2:1};
		if (t.o.controls.isAvailable('pause')) {
			this.className = 'pauseOver'
			this.title='Пауза';
		} else if (t.o.controls.isAvailable('play') && typeof k[t.o.playState] != 'undefined' ) {
			this.className = 'playOver'
			this.title='Слушать';
		}
		this._isOver = 1;
	}
	function _overStop() {
		if (this._this.o.controls.isAvailable('stop')) {
			this.className = 'stopOver'
		} else {
			this.className = 'stopDisabled'
		}
		this._isOver = 1;
	}
	function _overMute() {
		this.className = this._this.o.settings.mute? 'offOver': 'onOver';
		this._isOver = 1;
	}
	function _out() {
		var t = this._this, n = t.o.playState;
		if (n == 1) {
		//1 Stopped
			t.oBtns.play.o.className =  t.o.controls.isAvailable('play')? 'play': 'playDisabled';
			t.oBtns.stop.o.className = 'stopDisabled'
		} else if (n==2) {
		//2 Paused
			t.o.controls.isAvailable('play') && (
				t.oBtns.play.o.className = 'play'
			);
		} else if (n==3) {
		//3 Playing
			t.oBtns.play.o.className = t.o.controls.isAvailable('pause')? 'pause': 'pauseDisabled'
		}
		if (n==2 || n==3) {
			t.oBtns.stop.o.className = 'stop'
		}
		t.oBtns.mute.o.className = t.o.settings.mute? 'off': 'on';
		t.oBtns.mute.o.title = t.o.settings.mute? 'Включить звук': 'Выключить звук';
		this._isOver = 0;
	}
	function _PlayPause() {
		if (this._this.o.controls.isAvailable('pause')) {
			this._this.o.controls.pause()
		} else if (this._this.o.controls.isAvailable('play')) {
			this._this.o.controls.play()
		}
	}
	function _Stop() {
		if (this._this.o.controls.isAvailable('stop')) {
			this._this.o.controls.stop()
		}
	}
	function _Mute() {
		var m = this._this.o.settings;
		this._this.oBtns.mute.o.className = (m.mute = !m.mute)? 'off': 'on'
	}
	function _setVolume(e) {
		var t = this, x, y;
		e || (e = window.event);
		e.type == 'mousedown' && (t._mouseBtnPress = 1);
		if (!t._mouseBtnPress) {
			return
		}
		x = getMouseRelativePosition(t, e);
		x = x.x;
		y = t.offsetWidth;
		if (x < -10 || y+10 < x) {
			return
		}
		x < 0 && (x = 0);
		y -= 12;
		x > y && (x = y);
		y = Math.floor(x * 100 / y);
		t._this.o.settings.volume = y;
		t._this.oVolume.firstChild.style.width = (x+12)+'px';
	}
	function _showVolume(o, v) {
		try {
		o.oVolume.firstChild.style.width = Math.floor(((o.oVolume.offsetWidth-13)* v / 100)+13) + 'px'
		} catch(e) {}
	}
	this.o._this = this;
	_playStateChange(this.o.playState, this)
	/* o._Stop(); */
}
var oPlayer;
function initPlayer(id) {
	var t = initPlayer, o = document.getElementById(id), s, o1;
	if (o) {
		if(!o.versionInfo) {
			function _Play() {
				this.className = 'pauseDisabled';
				this.title = ''; // stiraem
				var o = document.getElementById('stopBtnID');
				o.className = 'stop';
				o.title = 'Стоп';
				_Play.o.style.display = ''
			}
			function _Stop() {
				this.title = ''; // stiraem
				this.className = 'stopDisabled';
				var o = document.getElementById('playBtnID');
				o.className = 'play';
				o.title = 'Слушать';
				_Stop.o.style.display = 'none'
			}
			_Stop.o = _Play.o = o.getElementsByTagName('EMBED')[0];
			o1 = document.getElementById('playBtnID');
			o1.onmouseover = new Function('var t = this, s = t.className; s != \'playDisabled\' && s != \'pauseDisabled\' && (t.className = \'playOver\')');
			o1.onmouseout = new Function('var t = this, s = t.className; s != \'playDisabled\' && s != \'pauseDisabled\' && (t.className = \'play\')');
			o1.className = 'pauseDisabled';
			o1.onclick = _Play;
			o1 = document.getElementById('stopBtnID');
			o1.onclick = _Stop;
			o1.onmouseover = new Function('this.className != \'stopDisabled\' && (this.className = \'stopOver\')');
			o1.onmouseout = new Function('this.className != \'stopDisabled\' && (this.className = \'stop\')');
			o1.className = 'stop'
            _Stop();
		} else {
			oPlayer = new classPlayer(o);
			window.onunload = new Function('oPlayer.o.close()');
		}
		function sendVote(n) {
			var req = new RAjaxRequest( {
				'url': voteURL,
				method: 'post',
				params: 'id='+idTranslation+'&vote='+n,
				callback: function(r, options) {
					if ( req.responseIsSuccess ) {
						if (req.isReaded) {
							return
						} else {
							req.isReaded = true;
						}
						try {
							eval(r.responseText);
							//ЦКНАЮКЭМЮЪ ОЕПЕЛЕММЮЪ ЯН ГМЮВЕМХЕЛ РЕЙСЫЕЦН ПЕИРХМЦЮ 
							currentRating = res.rating;
							alert(res.message)
						} catch (e) {}
					} else {
						return true
					}
				}
			} );
			return false
		}
		t = document.getElementById('ratingID');
		if (t.nodeName != 'FORM') {
			function _overRatingShow(e) {
				var t = this, x, y;
				e || (e = window.event);
				x = getMouseRelativePosition(t, e);
				x = x.x;
				y = t.offsetWidth;
				if (e.type == 'click') {
					sendVote(Math.ceil(x/17))
				}
				x < 0 && (x = 0);
				y -= 17;
				x > y && (x = y);
				x += -(x%17)+17;
				if (e.type == 'click') {
					sendVote(x/17);
				}
				t = t.getElementsByTagName('DIV')[0];
				t.style.width = x+'px';
				t.title='Голосовать';
			}
			t.onmousemove = t.onclick = _overRatingShow;
			t.onmouseout = new Function(
				'this.getElementsByTagName(\'DIV\')[0].style.width = Math.round(currentRating * 20)+\'%\''
			);
			t.onmouseout()
		}
	/**/  //o._Stop();
	} else if ((t.n && t.n--)||(t.n = 60) > 0) {
		window.setTimeout('initPlayer(\''+arguments[0]+'\')', 250);
	}
}
initPlayer('MediaPlayer1');
