var current_id = 'none';
var lo_quality = 0;

function SetLow()
{
 lo_quality = 1;
}
function sendEvent(typ,prm) { 
  thisMovie("p").sendEvent(typ,prm); 
};
var duration;
function getStopPoints(curDuration)
{
 var points = new Array();
 var j=0;
 for(i=0;i<=curDuration;i+=10)
 {
  points[j]=i;
  j++;
 }
 return points;
}
var old_req_percent=-1;
function getUpdate(typ,pr1,pr2,swf) 
{ 
var client = new XMLHttpRequest();
if(typ == 'state' && pr1 == 2) {
   sp = getStopPoints(duration);
  }

  if(typ == 'time')
  {
   for(i=0;i<sp.length;i++)
   {
    if(pr1 == sp[i])
	{
	 var percent = (sp[i]/duration)*100;
	 percent = Math.round(percent);
	
	 if(old_req_percent == percent)
	 {
	 //test.innerHTML = old_req_percent + " return\n";
	 return;
	 }
	 else
	 {
	 old_req_percent = percent;
	  //test.innerHTML = old_req_percent + "NOT return\n";
	 }
	 
	 //alert('/system/loficount.php?st=0&percent=' + percent + '&trackid=' + current_id);
	 
     client.open("GET", '/system/loficount.php?st=0&percent=' + percent + '&trackid=' + current_id);
     client.send();
    }
   }   
  }

};
function thisMovie(movieName) {

	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
		
	}
	
};
function HandleClick(file, file_lo, id, l, is_icon){

 is_icon = is_icon || 0;

//alert(is_icon); 
 if (id == current_id) 
 {
   sendEvent('stop');
   current_id = 'none';
   var tmp = document.getElementById(id); 
   if(!is_icon)
   { 
   if (tmp) { tmp.innerHTML="Слушать";}
   }
   else
   {
   if(tmp){tmp.className="play";}
   }
  
 } 
 else 
 {
  duration = l;
  CreatePlayer(file, file_lo, id);
  var tmp = document.getElementById(current_id); 
   if(!is_icon)
   { 
   if (tmp) { tmp.innerHTML="Слушать";}
   }
   else
   {
   if(tmp){tmp.className="play";}
   //alert(1);
   }
  
  current_id = id;
  var tmp = document.getElementById(id); 
   if(!is_icon)
   { 
   if (tmp) { tmp.innerHTML="Играет";}
   }
   else
   {
   if(tmp) {tmp.className="pause";}
   //alert(2);
   }
 }
}
function CreatePlayer(file, file_lo, id) {
  if(lo_quality)
  {
   file=file_lo;
  }
  //test.innerHTML=file;
  var so = new SWFObject('/system/mplayer/mediaplayer.swf','p','1','1','8');
  so.addParam('allowscriptaccess','always');
  so.addParam('allowfullscreen','true');
  so.addVariable('height','1');
  so.addVariable('width','1');
  so.addVariable('file',file);
  so.addVariable('javascriptid','p');
  //so.addVariable('callback','/system/callback.php');
  so.addVariable('usefullscreen','false');
  so.addVariable('enablejs','true');
  so.addVariable('autostart','true');
  so.addVariable('volume','100');
  so.write('pldiv');
  var tmp = document.getElementById("p"); if(tmp) {  tmp.style.visibility="hidden"} 
}
