﻿
function checkPlayState() {
    var wmpControl = document.getElementById('wmplayer');

    var newState = wmpControl && wmpControl.playState;
    var status = document.getElementById("marq");
    if (null == newState) {
        if (browser.isIE) {
            newState = 0;
        } else {
            return false;
        }
    }
    var playButtonMax = document.getElementById('button');
    if (10 == newState) {
        // 10	Ready	Ready to begin playing.
    } else if (11 == newState) {
        status.innerHTML = 'Соединение';
    } else if (6 == newState) {
        status.innerHTML = 'Буферизация';
    } else if (7 == newState) {
        status.innerHTML = 'Ожидание';
    } else if (9 == newState) {
        status.innerHTML = 'Идет загрузка медиапотока...';
    } else if (1 == newState) {
        status.innerHTML = 'Для прослушивания нажми кнопку Play';
        i = 0;
    } else { /* 3 == playState */

    }
}

function Play() {

    $('#nobreak').remove();
    $('#rtl_marquee').append('<nobr id="nobreak"><span id="marq" onclick=fnSelect(\'marq\')></span></nobr>')

	var button = document.getElementById('button');
	if (button.className == 'play') 
	{
	    event_track();
	
	    button.className = 'pause';
	    wmpStart();
	    checkPlayState();
	    getCurrentSong();

	    rtl_marquee.newPosition = 250;
	    rtl_marquee._setLeft('250');
	    rtl_marquee.start();

	    $(document).everyTime("20s", "getCurrentSongTimer", function(i) {
	        getCurrentSong();
	    });

	    $(document).everyTime("300s", "getConnectionsCountTimer", function(i) {
	        getConnectionsCount();	   
	    });	    
	    
	}
	else
	{
		button.className = 'play';
		wmpFinish();

		rtl_marquee.newPosition = 250;
		rtl_marquee._setLeft('250');
		rtl_marquee.start();

		document.getElementById("marq").innerHTML = "Для прослушивания нажми кнопку Play";
		document.getElementById("marq").style.color = '#0076A3';

		$(document).stopTime('getCurrentSongTimer');
				
	}
	return false;
}
	
var flashtest = false;
var ietest = false;

function CheckFlash(){
	if (navigator.userAgent.indexOf('MSIE') != -1) {
		flashtest = true;
		ietest = true;
	} else {
		for (var p =0; p< navigator.plugins.length; p++) {
			var d = navigator.plugins[p].name.toLowerCase().indexOf('flash');
			if (d > -1) {
				flashtest = true; break;
			}
		}
	}
}

function OpenPlayer(radio_id){
	if (radio_id){
		var radioOpen = window.open('player.aspx?radio_id=' + radio_id,'radio','resizable=no,width=645,height=535');
		if (radioOpen){
			radioOpen.focus();
		} else {
			alert('Для прослушивания радио Вам необходимо отключить блокирование всплывающих окон для этого сайта');
		}
	}
	return false;
}
