var radioctl;

soundManager.bgColor = '#000000';
soundManager.wmode = 'transparent'; 
soundManager.useFlashBlock = false; 
 soundManager.flashVersion = 9; 

soundManager.debugMode = false;
soundManager.url = 'sm/';
 
 
soundManager.onready(function(){
 
  if (!soundManager.supported()) {
 
  } else {
  
	enumClasses("pl_stop", function(obj){
		obj.style.display="";
	},null,"div");
 
	    if (getCookie("playing")==1) {
		do_play(getCookie("scode"));
	    };

  }
});

// --------------------------------  Горизонтальная 
/*
function VolumeMouseMove(e, dwn) {
 //        confirm(did('volume_back').offsetTop);
 if (dwn==1 || e.button) {
  var box = did('volume_back').getBoundingClientRect();
  var cLeft = Math.round(e.clientX)-box.left;
  var width=(box.right-box.left);
  if (cLeft<=width) {
	  var hp = (cLeft/width);
	  VolumeUpdate(hp);
 }};
};

function VolumeUpdate(hp) {
      soundManager.setVolume('radio'+radio_channel[currentscode], (Math.round(hp*100)) );
      setCookieA("volume", (Math.round(hp*100)),100);
      var box = did('volume_back').getBoundingClientRect(); 
      cWidth = Math.round(hp*(box.right-box.left)) ;
      if (cWidth==0) {
	  did('volume_front').style.display='none';
      } else {
          did('volume_front').style.display='';
          did('volume_front').style.width=(cWidth)+"px";
      }
}
*/ 
// --------------------------------- Вертикальная 

function VolumeMouseMove(e, dwn) {
 //        confirm(did('volume_back').offsetTop);
 if (dwn==1 || e.button) {
  var box = did('volume_back').getBoundingClientRect();
  var cTop = Math.round(e.clientY)-box.top;
  var height=(box.bottom-box.top);
  if (cTop<=height) {
	  var hp = (1-cTop/height);
	  VolumeUpdate(hp);
 }};
};

function VolumeUpdate(hp) {
      soundManager.setVolume('radio'+radio_channel[currentscode], (Math.round(hp*100)) );
      setCookieA("volume", (Math.round(hp*100)),100);
      var box = did('volume_back').getBoundingClientRect(); 
      cHeight = Math.round(hp*(box.bottom-box.top)) ;
      if (cHeight==0) {
	  did('volume_front').style.display='none';
      } else {
          did('volume_front').style.display='';
          did('volume_front').style.height=(cHeight)+"px";
	  did('volume_front').style.top=((box.bottom-box.top)-cHeight)+"px";
      }
}


var radio_channel="http://badplace.ru:1111/radio";
var radio_vol=10;
var currentscode=0;

function do_play(scode){
 do_stop();
 radioctl=soundManager.createSound({
        id           : 'radio'+radio_channel[scode],
        url          : radio_channel[scode],
        volume       : radio_vol, 
  	usePeakData  : false      
	});
 soundManager.play('radio'+radio_channel[scode]);
 setCookieA('playing', 1, 1); // автопроигрывание - 10 дней
 setCookieA('scode', scode, 1); // автопроигрывание - 10 дней
 currentscode=scode;
 did('radio'+scode).className="pl_play";
 favicon.animate([
"1d.style/favicon/1.ico", 
"1d.style/favicon/2.ico",
"1d.style/favicon/3.ico",
"1d.style/favicon/4.ico",
"1d.style/favicon/5.ico",
"1d.style/favicon/6.ico",
"1d.style/favicon/7.ico",
"1d.style/favicon/8.ico",
"1d.style/favicon/9.ico",
"1d.style/favicon/10.ico",
"1d.style/favicon/11.ico"], {delay: 300} );

 did('radio'+scode).parentNode.appendChild(did('player_ops'));
 VolumeUpdate(getCookie("volume")/100);
};

function do_stop() {
  soundManager.unload('radio'+radio_channel[currentscode]);
  setCookieA('playing', 0, 1);

	enumClasses("pl_play", function(obj){
		obj.className="pl_stop";
	},null,"div");
  currentscode=0;
  favicon.unanimate();
  favicon.change('/favicon.ico');
  did('hiddenbox').appendChild(did('player_ops'));
};
  

