var sec_init=0;

var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
  trans[i] = i - 0x350; 
trans[0x401] = 0xA8;    
trans[0x451] = 0xB8;    
var escapeOrig = window.escape;

window.escape = function(str)
{
  var ret = [];
  for (var i = 0; i < str.length; i++)
  {
    var n = str.charCodeAt(i);
    if (typeof trans[n] != 'undefined')
      n = trans[n];
    if (n <= 0xFF)
      ret.push(n);
  }
  return escapeOrig(String.fromCharCode.apply(null, ret));
}
 
function get_pl3(pp){
	var sf=pp;
	if(sec_init==2) fstop('stop',2);
	if(pp==-1) pp=0;
jQuery('#showmmnd').show();
jQuery('title').html(jQuery('#i_search').val()+' скачать mp3'); 


 
if ( history.pushState ) history.pushState(null, null, '/music/'+escape(jQuery('#i_search').val()+'/'+pp+'/'));
	$.get("/ajax.php", {'p': pp, 'music': jQuery('#i_search').val() }, function(data) {

	jQuery('#showmmnd').hide();
	var msg=data.split('{JAVASCRIPT}');
	
 if(msg[1].length>=2) {var loadedJS = document.createElement('script');   
    loadedJS.type = "text/javascript";   
    loadedJS.language = "javascript";   
    loadedJS.id = "bool2";   
    loadedJS.innerHTML = msg[1];   
    var head = document.getElementsByTagName('head')[0];   
    head.appendChild(loadedJS);
 }
$('body,html').animate({
                scrollTop: 357
            }, 1000);
           
	jQuery('#glav_poisk').html(msg[0]); 

$("a[id^=aplayer]").click(function() {
	var tth=$(this).attr('id');
	$("a[id^=aplayer]").each(function(i,elem){
		$("#"+$(elem).attr('id')+'_z').hide();
	});
$("#"+$('#'+tth).attr('id') + '_z').show();
});
	
$("div[id^=addmp3_]").click(function() {
showPopupv('<center>Трек успешно добавлен</center>', 0);
setTimeout("closePopupv()",1500);
		var iz=$(this).attr('id');
	var vaid=$(this).find("#aid").text();
	var oid=$(this).find("#oid").text();
	var title=$(this).find("#title").text();
	var autor=$(this).find("#autor").text();
	var vtime=$(this).find("#time").text();

a_this = $(this);
$.post("/play_list.php",{'add':'ok','aid':vaid,'oid':oid,'title':title,'autor':autor,'time':vtime,'uid':get_cookie('uid')},  function(msg){
if(msg=='ok'){
    a_this.find('img').attr("src",'/images/addok.png');
            a_this.removeAttr('id'); //a_this.off("click");
			a_this.addClass('pls'); //a_this.off("click");
plist_load();}
});

event.preventDefault();
	});

	
$("a[id^=add_comment]").click(function() {
		var rel=$(this).attr('rel');
	$("div[id^=commadd]").each(function(i,elem){
		if($(elem).attr('id') != 'commadd'+rel) $(elem).hide();
	});
	
if(jQuery('#commadd'+rel).is(':hidden')) jQuery('#commadd'+rel).show();
	else jQuery('#commadd'+rel).hide();
 
});

$("[id^=postcomm]").click(function() {
	var id=$(this).attr('name');
$.post("/comm.php",{'login':get_cookie('llogin'),'pass':get_cookie('lpass'),'id':id,'text':$('#thiscomm'+id).val(),'step':'add','title':$('#thistitle'+id).val(),'oid':$('#thisoid'+id).val()},  function(msg){
if(msg=='ok'){   jQuery('#commadd'+id).hide();  //window.location.reload();
reload_comm(id,'0','1');
$('#coocount'+id).find('b').text( Math.round($('#coocount'+id).find('b').text()) + 1 );
}
else alert(msg);
});

});

 if(sf==-1) return false;
});
 
}


function closePopup()
 {
   $('#opaco').toggleClass('hidden').removeAttr('style');
   $('#popup').toggleClass('hidden');
   	$('#poptxt').html('')

 }
 
 function closePopup()
 {
   $('#opacov').toggleClass('hiddenv').removeAttr('style');
   $('#popupv').toggleClass('hiddenv');
   	$('#poptxtv').html('')

 }

function showPopup(popup_type,ttq)
 { if(ttq==false) ttq=0;
 if(ttq==null) ttq=0;
 	if(ttq==0){
   if($.browser.msie)
   {
     $('#opaco').height($(document).height()).toggleClass('hidden');
   }
   else
   {
     $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('fast', 0.8);
   }

   $('#popup')
     .toggleClass('hidden');
	}
	$('#poptxt').html(popup_type)
   $('#popup').alignCenter()


   return false;
 }

 function reload_comm(id,page,suka){
	if(page==null) page=0;
	if(page==false) page=0;
	if(suka==0){
	$("div[id^=commtext]").each(function(i,elem){
		if($(elem).attr('id') != 'commtext'+id) $(elem).hide();
		else { if($(elem).is(':hidden')==false) $(elem).hide();
		else $(elem).show();
		}
	});
	} else $('#commtext'+id).show();
$.post("/comm.php",{'id':id,'step':'list','page':page},  function(msg){
$("#commtext"+id).html(msg);
});
 }
 
jQuery(document).ready(function(){
	
	$("#btn_reg").click(function() {
showPopup('<center>Loading...</center>');
$.get("/reg.php",{'a':'a'},  function(msg){
	msg=msg.split('{JAVASCRIPT}');
showPopup(msg[0],1);
 var loadedJS = document.createElement('script');   
    loadedJS.type = "text/javascript";   
    loadedJS.language = "javascript";   
    loadedJS.id = "bool2";   
     loadedJS.innerHTML = msg[1];   
   
    var head = document.getElementsByTagName('head')[0];   
   
    
    head.appendChild(loadedJS);

  });
});

$("#btn_lost").click(function() {
showPopup('<center>Загрузка...</center>');
$.get("/lost.php",{'a':'a'},  function(msg){
	msg=msg.split('{JAVASCRIPT}');
showPopup(msg[0],1);
 var loadedJS = document.createElement('script');   
    loadedJS.type = "text/javascript";   
    loadedJS.language = "javascript";   
    loadedJS.id = "bool2";   
     loadedJS.innerHTML = msg[1];   
  
    var head = document.getElementsByTagName('head')[0];   
   
   
    head.appendChild(loadedJS);

  });
});

$("a[id^=add_comment]").click(function() {

	var rel=$(this).attr('rel');
	$("div[id^=commadd]").each(function(i,elem){
		if($(elem).attr('id') != 'commadd'+rel) $(elem).hide();
	});
if($('#commadd'+rel).is(':hidden')) $('#commadd'+rel).show();
	else $('#commadd'+rel).hide();
 
});

$("[id^=postcomm]").click(function() {
	var id=$(this).attr('name');
 
$.post("/comm.php",{'login':get_cookie('llogin'),'pass':get_cookie('lpass'),'id':id,'text':$('#thiscomm'+id).val(),'step':'add','title':$('#thistitle'+id).val(),'oid':$('#thisoid'+id).val()},  function(msg){
if(msg=='ok'){   jQuery('#commadd'+id).hide();  //window.location.reload();
reload_comm(id,'0','1');
$('#coocount'+id).find('b').text( Math.round($('#coocount'+id).find('b').text()) + 1 );
}
else alert(msg);
});

});

$("#btn_login").click(function() {
$('#log_in').html('проверка...');
$.post("/index.php",{'slogin':$("#slogin").val(),'spass':$("#spass").val()},  function(msg){
if(msg=='ok'){  window.location.reload();

}
else jQuery('#log_in').html(msg);
});
});

$("#btn_change").click(function() {
showPopup('<center>Загрузка...</center>');
$.get("/change_pass.php",{'a':'a'},  function(msg){
	msg=msg.split('{JAVASCRIPT}');
showPopup(msg[0],1);
 var loadedJS = document.createElement('script');   
    loadedJS.type = "text/javascript";   
    loadedJS.language = "javascript";   
    loadedJS.id = "bool2";   
     loadedJS.innerHTML = msg[1];   
 
    var head = document.getElementsByTagName('head')[0];   
     
    head.appendChild(loadedJS);

  });
});

$("#btn_exit").click(function() {
$('#log_in').html('выход...');
$.post("/index.php",{'sexit':'ok'},  function(msg){
if(msg=='ok') window.location.reload();
else jQuery('#log_in').html(msg);
});
});


$("a[id^=aplayer]").click(function() {
	var tth=$(this).attr('id');
	$("a[id^=aplayer]").each(function(i,elem){
		$("#"+$(elem).attr('id')+'_z').hide();
	});
$("#"+$('#'+tth).attr('id') + '_z').show();
});

$("div[id^=addmp3_]").click(function() {
showPopupv('<center>Трек успешно добавлен</center>', 0);
setTimeout("closePopupv()",1500);
		var iz=$(this).attr('id');
	var vaid=$(this).find("#aid").text();
	var oid=$(this).find("#oid").text();
	var title=$(this).find("#title").text();
	var autor=$(this).find("#autor").text();
	var vtime=$(this).find("#time").text();

a_this = $(this);
$.post("/play_list.php",{'add':'ok','aid':vaid,'oid':oid,'title':title,'autor':autor,'time':vtime,'uid':get_cookie('uid')},  function(msg){
if(msg=='ok'){
    a_this.find('img').attr("src",'/images/addok.png');
            a_this.removeAttr('id'); //a_this.off("click");
			a_this.addClass('pls'); //a_this.off("click");
plist_load();}
});

event.preventDefault();
	});
	
   jQuery.fn.alignCenter = function() {
      var marginLeft = Math.max(40, parseInt($(window).width()/2 - $(this).width()/2)) + 'px';
      var marginTop = Math.max(40, parseInt($(window).height()/2 - $(this).height()/2)) + 'px';
      return jQuery(this).css({'margin-left':marginLeft, 'margin-top':marginTop});
   };

});

function getMovie() {
        var M$ =  navigator.appName.indexOf("Microsoft")!=-1
	return (M$ ? window : document)["BridgeMovie"]
}
function BridgeMovie_DoFSCommand(command, args) {
	window[command].call(null, args)
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results ) return ( unescape ( results[2] ) );
  else return '';
}
 
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
 var cookie_string = name + "=" + escape ( value );
  path='/';
  if ( exp_y ){
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }
  if ( path   )   cookie_string += "; path=" + escape ( path );
  if ( domain ) cookie_string += "; domain=" + escape ( domain );
  if ( secure ) cookie_string += "; secure";
  document.cookie = cookie_string;
}

function plist_load(){
$('#plist').html('<br><br><br><center><img src="/images/load.gif"></center>');
$.post("/play_list.php",{'list':'ok','uid':get_cookie('uid')},  function(msg){
var msg=msg.split('{JAVASCRIPT}');
	jQuery('#plist').html(msg[0]);

 if(msg[1].length>4){
	var loadedJS = document.createElement('script');   
    loadedJS.type = "text/javascript";   
    loadedJS.language = "javascript";   
    loadedJS.id = "bool3";   
    if(loadedJS.innerHTML) loadedJS.innerHTML = msg[1];   
    var head = document.getElementsByTagName('head')[0];   
    head.appendChild(loadedJS);
	plo_list_id = $.inArray(plo_url,plo_list_norber);
	plo_list_hash=plo_list_obj[plo_list_id];
	if(plo_list_id != -1){
		plo_cur_title=plo_list_xftitle[plo_list_id];
	}
}
		plo_list_norber2=new Array();
		plo_list_xftitle2=new Array();
		plo_list_obj2=new Array();
		plo_list_send=new Array(); vii=1;
		 $('#example-1-3 .sortable-list .sortable-item').each(function(i, val){
		if ( $(val).is(':visible') ){
			//i=vii;
			 plo_list_send[i]=$(val).find("img[id^=del_mp]").attr('alt');
			 $(val).find("img[id^=del_mp]").attr({'alt':i+1})
			 plo_list_norber2[i]=$(val).find('#norber').text();
			 plo_list_xftitle2[i]=$(val).find('#xftitle').text();
			 plo_list_obj2[i]=$(val).find("div[id^=plid_]").attr('id');
			 plo_list_obj2[i]=plo_list_obj2[i].replace(/plid_/,'');
			 vii++;
		}
		 });
		plo_list_norber=plo_list_norber2;
		plo_list_xftitle=plo_list_xftitle2;
		plo_list_obj=plo_list_obj2;

	$('#example-1-3 .sortable-list').sortable({'axis': 'y',forceHelperSize: true,forcePlaceholderSize: true, opacity: 0.6, stop: function(event, ui) {
		
		plo_list_norber2=new Array();
		plo_list_xftitle2=new Array();
		plo_list_obj2=new Array();
		plo_list_send=new Array(); vii=1;
		 $('#example-1-3 .sortable-list .sortable-item').each(function(i, val){
		 
		if ( $(val).is(':visible') ){
			i=vii;
			 plo_list_send[i]=$(val).find("img[id^=del_mp]").attr('alt');
			 $(val).find("img[id^=del_mp]").attr({'alt':vii})
			 plo_list_norber2[i]=$(val).find('#norber').text();
			 plo_list_xftitle2[i]=$(val).find('#xftitle').text();
			 plo_list_obj2[i]=$(val).find("div[id^=plid_]").attr('id');
			 plo_list_obj2[i]=plo_list_obj2[i].replace(/plid_/,'');
			 vii++;
		 }
		 });
		plo_list_norber=plo_list_norber2;
		plo_list_xftitle=plo_list_xftitle2;
		plo_list_obj=plo_list_obj2;
		$.post("/play_list.php",{'sort':'ok','rid':plo_list_send,'uid':get_cookie('uid')},  function(msg){ //alert('plist save:'+plo_list_send);
		});
	}});
	
	$("a[id^=aplayer]").click(function() {
	var tth=$(this).attr('id');
	$("a[id^=aplayer]").each(function(i,elem){
		$("#"+$(elem).attr('id')+'_z').hide();
	});
$("#"+$('#'+tth).attr('id') + '_z').show();
});


$("img[id^=del_mp]").click(function() {
	
$.post("/play_list.php",{'del':'ok','rid':$(this).attr('alt'),'uid':get_cookie('uid')},  function(msg){

  });

  $(this).parent().parent().parent().hide();
		plo_list_norber2=new Array();
		plo_list_xftitle2=new Array();
		plo_list_obj2=new Array();
		plo_list_send=new Array(); vii=1;
		 $('#example-1-3 .sortable-list .sortable-item').each(function(i, val){
		 if ( $(val).is(':visible') ){
			i=vii;
			 plo_list_send[i]=$(val).find("img[id^=del_mp]").attr('alt');
			 $(val).find("img[id^=del_mp]").attr({'alt':vii})
			 plo_list_norber2[i]=$(val).find('#norber').text();
			 plo_list_xftitle2[i]=$(val).find('#xftitle').text();
			 plo_list_obj2[i]=$(val).find("div[id^=plid_]").attr('id');
			 plo_list_obj2[i]=plo_list_obj2[i].replace(/plid_/,'');
			 vii++;
		 }
		 });
		plo_list_norber=plo_list_norber2;
		plo_list_xftitle=plo_list_xftitle2;
		plo_list_obj=plo_list_obj2;

});

});
}




var plo_b_proc=0;
var plo_b_total=0;
var plo_b_current=0;
var plo_pos_total=0;
var plo_pos_current=0;
var plo_volume=75;
var plo_url='';
var plo_cur_title='';
var plo_list_norber=new Array();
var plo_list_xftitle=new Array();
var plo_list_obj=new Array();
var plo_list_send=new Array();
var plo_list_id = '';
var plo_list_hash='';
var plo_mainlist=0;
var plo_nextlist='';
var plo_list_element_repeat='';

function flload(volume) {
	jsetvolume(volume);
}
function flproc(percent,total_b,current_b) {
	plo_b_proc=percent;
	plo_b_total=total_b;
	plo_b_current=current_b;
	if(percent==100) percent=100;
	$( "#progressbar" ).progressbar({value: percent});
}
function fltime(duration,current_pos) {
plo_pos_total=duration;
plo_pos_current=current_pos;
var min0=Math.floor((current_pos/1000)/60);
var sec0=0;
if(min0==0) sec0=Math.floor(current_pos/1000); else sec0=Math.floor((current_pos-min0*60*1000)/1000);
if(sec0<=9) sec0='0'+sec0;
if(min0<=9) min0='0'+min0;
if(sec0==60) sec0='00';
	$("#play_duration").text(min0+':'+sec0);
	$( "#play_progress" ).slider({value:current_pos,max:duration});
	if(current_pos>3) $("#play_trackname").text(plo_cur_title);
}

function flplay(Txt)    {}
function flplaypos(Txt) {}
function flpause(Txt)   {}
function flstop(Txt)    {}
function flend(Txt) {
	$("#ui-icon-pause").hide();
	$("#ui-icon-play").show();
 	if(plo_mainlist==0){ $("#ui-icon-seek-next").click(); //alert('1');
	}
		if (plo_list_element_repeat=='yes') {
$('#player').find('#ui-icon-play').click();
}
	else { 
$(plo_nextlist).click();

	}
}
function jsetvolume(vol){
	
	fsetvol(vol);
	$( "#play_volume" ).slider( "value", vol );
}
function jplaypos(vol){
	if(vol>$( "#play_progress" ).slider("max")) vol=Math.abs(plo_pos_current-3*1000);
	$("#ui-icon-play").hide();
	$("#ui-icon-pause").show();
	var movie = getMovie()
	movie.jplaypos(vol);
}



// инициализация
jQuery(function($) {
	
$(".aidubal").click(function(){
  return false;
});
$(".window-abc a").click(function(){
  return false;
});
$(".window-top a").click(function(){
  return false;
});
$(".aabcl a").click(function(){
  return false;
});
$("#footer .txtboxes a").click(function(ela){

$('#i_search').val($(this).text());

$('.windows-main').find('h3').html('');
get_pl3('-1');
  return false;
});
$("#top .txtboxestop a").click(function(ela){
$('#i_search').val($(this).text());
$('.windows-main').find('h3').html('');
get_pl3('-1');
  return false;
});
$("#glavnaya .txtb a").click(function(ela){
$('#i_search').val($(this).text());
$('.windows-maina').find('h3').html('');
get_pl3('-1');
  return false;
});

$("#ui-icon-seek-next").click(function() {
	if(plo_mainlist==1){ if($(plo_nextlist).find('#norber')) $(plo_nextlist).click(); else fstop2(); }
	else {
	var xs=0;  var tratata=0;
$.each(plo_list_obj, function(i, val) { 
	if(xs==1) xs=2;
	if(val==plo_list_hash){ xs=1; }
	if(xs==2){ 
		if($("#plid_"+val) || plo_list_norber[i].length > 10){
			
			tratata=1;
			$("#plid_"+val).find('#ui-icon-pause').show();
			$("#plid_"+val).find('#ui-icon-play').hide();
			$("#plid_"+val).parent().addClass('playyed');
			fset(plo_list_norber[i]);
			plo_list_id=i;
			plo_list_hash=val;
			plo_cur_title=plo_list_xftitle[i];
			xs=3;
		}
	}
    });
	
	if(tratata==0){
			$("[id^=plid_]:first").find('#ui-icon-pause').show();
			$("[id^=plid_]:first").find('#ui-icon-play').hide();
			$("[id^=plid_]:first").parent().addClass('playyed');
			fset(plo_list_norber[0]);
			plo_list_id=0;
			plo_list_hash=plo_list_obj[0];
			plo_cur_title=plo_list_xftitle[0];
	}
}
});
$("#ui-icon-seek-prev").click(function() {
		if(plo_mainlist==1){ $(plo_prevlist).click(); }
	else {
	var xs=0; var pr=0;
$.each(plo_list_obj, function(i, val) { 
	if(i==plo_list_id){ xs=1; }
	if(xs==1){ val=plo_list_obj[pr];
		if($("#plid_"+val)){
			$("#plid_"+val).find('#ui-icon-pause').show();
			$("#plid_"+val).find('#ui-icon-play').hide();
			$("#plid_"+val).parent().addClass('playyed');
			fset(plo_list_norber[pr]);
			plo_list_id=pr;
			plo_list_hash=val;
			plo_cur_title=plo_list_xftitle[pr];
			xs=3;
		}
	}
	pr=i;
    });
}
});

$("#ui-icon-stop").click(function() {
	var xs=0; var pr=0;
$.each(plo_list_obj, function(i, val) {
		if($(this)){
			$(this).find('#ui-icon-pause').hide();
			$(this).find('#ui-icon-play').show();
			$(this).parent().removeClass('playyed');
		}
    });
		
			fstop2();
			plo_list_id='';
			plo_list_hash='';
			plo_cur_title='Загрузка прервана!';
			$("#play_trackname").text(plo_cur_title);

});

$("#ui-icon-play").click(function() {
	plo_mainlist=1;
	fplay();
	});
$("#ui-icon-pause").click(function() {
	fpause();
	});
$( "#progressbar" ).progressbar({value: 100,disabled: false});
$("#play_volume").slider({range: "min",value: 75,min: 3,max: 100,
 slide: function( event, ui ) {
 jsetvolume(ui.value);
 }
 });

$("#play_progress").slider({range: "min",value: 0,min: 0,max: 0,
 slide: function( event, ui ) {
 jplaypos(ui.value);
 }
 });

 
});
function fsetvol(url) {
	plo_volume=url;
	var movie = getMovie()
	movie.fsetvol(url);
}

function gopl(elm){
	
	var plqw=1;
	var plqw21=elm;
	var plqw22='';
	jQuery('#glav_poisk li').each(function(i, val) {
	var tt7=jQuery(this).find('[id^=plid_]').attr('id');
	if(plqw22=='') plqw22=$(this).find('[id^=plid_]'); else plqw22=plqw21;
	plqw21=$(this).find('[id^=plid_]');
	
	if(plqw==2) {if($(this).find('[id^=plid_]')) plo_nextlist=$(this).find('[id^=plid_]'); else plo_nextlist='';  plqw++;  }
	if($(elm).attr('id') == tt7) {plqw++; if(plqw22) plo_prevlist=plqw22; else plqw22='';} 

    });
	if(jQuery(elm).parent().parent().parent().parent().attr('id') == 'plist' ){plo_mainlist=0;} else {plo_mainlist=1;}
	
	
	var u1=$(elm).find('#norber').text();
	var t1=$(elm).find('#xftitle').text();
	plo_cur_title=t1;
	if($(elm).find('#ui-icon-play').is(':hidden')){
		$(elm).parent().removeClass('playyed');
		$(elm).find('#ui-icon-pause').hide();
		$(elm).find('#ui-icon-play').show();
		fpause();
	} else {
		$(elm).parent().addClass('playyed');
		$(elm).find('#ui-icon-pause').show();
		$(elm).find('#ui-icon-play').hide();
	
		if(plo_url!=u1){ fset(u1);  } else fplay();
		
	}
}
function goplist(elm){
	
	var plqw=1;
	var plqw21=elm;
	var plqw22='';
	jQuery('#plist li').each(function(i, val) {
	var tt7=jQuery(this).find('[id^=plid_]').attr('id');
	if(plqw22=='') plqw22=$(this).find('[id^=plid_]'); else plqw22=plqw21;
	plqw21=$(this).find('[id^=plid_]');
	
	if(plqw==2) {if($(this).find('[id^=plid_]')) plo_nextlist=$(this).find('[id^=plid_]'); else plo_nextlist='';  plqw++;  }
	if($(elm).attr('id') == tt7) {plqw++; if(plqw22) plo_prevlist=plqw22; else plqw22='';} 

    });
	if(jQuery(elm).parent().parent().parent().parent().attr('id') == 'plist' ){plo_mainlist=0;} else {plo_mainlist=1;}
	
	
	var u1=$(elm).find('#norber').text();
	var t1=$(elm).find('#xftitle').text();
	plo_cur_title=t1;
	if($(elm).find('#ui-icon-play').is(':hidden')){
		$(elm).parent().removeClass('playyed');
		$(elm).find('#ui-icon-pause').hide();
		$(elm).find('#ui-icon-play').show();
		fpause();
	} else {
		$(elm).parent().addClass('playyed');
		$(elm).find('#ui-icon-pause').show();
		$(elm).find('#ui-icon-play').hide();
	
		if(plo_url!=u1){ fset(u1);  } else fplay();
		
	}
}

function fset(url) {
	plo_url=url;
	plo_b_proc=0;
	plo_b_total=0;
	plo_b_current=0;
	plo_pos_total=0;
	plo_pos_current=0;
	$( "#play_progress" ).slider({value: 0});
	$("#play_duration").text('00:00');
	$("#play_trackname").text('Загрузка. Пожалуйста подождите...');
	$( "#progressbar" ).progressbar({value: 0});
	$("#ui-icon-play").hide();
	$("#ui-icon-pause").show();
	
	plo_list_id = $.inArray(plo_url,plo_list_norber);
	plo_list_hash=plo_list_obj[plo_list_id];
	if(plo_list_id != -1){ 
		plo_cur_title=plo_list_xftitle[plo_list_id];
	}
$.each(plo_list_obj, function(i, val) {
	if(plo_list_hash!=val){
		if($("#plid_"+val)){
			$("#plid_"+val).find('#ui-icon-pause').hide();
			$("#plid_"+val).find('#ui-icon-play').show();
			$("#plid_"+val).parent().removeClass('playyed');
		}
	}
    });

	$('#glav_poisk div[id^=plid]').each(function(i,val) {
		
	if(plo_url!=$(val).find('#norber').text()){
		if($(val)){ 
			$(val).parent().removeClass('playyed');
			$(val).find('#ui-icon-pause').hide();
			$(val).find('#ui-icon-play').show();
		}
	}
    });
	
	if(url!=''){
	var movie = getMovie()
	movie.fset(url);
	fsetvol(plo_volume);
	} else {
		fpause();
	}
}
function fplay(url) {
	$("#ui-icon-play").hide();
	$("#ui-icon-pause").show();

	if($("#plid_"+plo_list_hash)){
			$("#plid_"+plo_list_hash).find('#ui-icon-pause').show();
			$("#plid_"+plo_list_hash).parent().addClass('playyed');
			$("#plid_"+plo_list_hash).find('#ui-icon-play').hide();
		}
	var movie = getMovie()
	movie.fplay(url);
}
function fpause(url) {
	$("#ui-icon-pause").hide();
	$("#ui-icon-play").show();
		if($("#plid_"+plo_list_hash)){
			$("#plid_"+plo_list_hash).find('#ui-icon-pause').hide();
			$("#plid_"+plo_list_hash).parent().removeClass('playyed');
			$("#plid_"+plo_list_hash).find('#ui-icon-play').show();
		}
	var movie = getMovie()
	movie.fpause(url);
}
function fstop(url) {
	$("#ui-icon-pause").hide();
	$("#ui-icon-play").show();
		if($("#plid_"+plo_list_hash)){
			$("#plid_"+plo_list_hash).find('#ui-icon-pause').hide();
			$("#plid_"+plo_list_hash).parent().removeClass('playyed');
			$("#plid_"+plo_list_hash).find('#ui-icon-play').show();
		}
	var movie = getMovie()
	movie.fstop(url);
}
function fstop2(url) {
	$("#ui-icon-pause").hide();
	$("#ui-icon-play").show();
		if($("#plid_"+plo_list_hash)){
			$("#plid_"+plo_list_hash).find('#ui-icon-pause').hide();
			$("#plid_"+plo_list_hash).parent().removeClass('playyed');
			$("#plid_"+plo_list_hash).find('#ui-icon-play').show();
		}
	var movie = getMovie()
	movie.fstop2(url);
}
$(document).ready(function(){
$('#fx_player-pv_p').live('click',function() {
if ($('#fx_player-pv_p').attr('class')=='fx_player-pv_p') {
$('#fx_player-pv_p').attr('class','fx_player-pv_p_active');
$('#fx_player-pv_p').attr('title','Повтор включен');
showPopupv('<center>Повтор включен</center>', 0);
setTimeout("closePopupv()",1500);
plo_list_element_repeat='yes';
} else {
$('#fx_player-pv_p').attr('class','fx_player-pv_p');
$('#fx_player-pv_p').attr('title','Повтор выключен');
showPopupv('<center>Повтор выключен</center>', 0);
setTimeout("closePopupv()",1500);
plo_list_element_repeat='';
}
});
  $("#rusgold").hide();
    
  $(function () {
        
        $('#footer a').click(function () {
            $('body,html').animate({
                scrollTop: 357
            }, 1000);
            return false;
        });
        
    });

});
function sshow(idd){
	if(jQuery('#tex_'+idd).is(':hidden')) jQuery('#tex_'+idd).show();
	else jQuery('#tex_'+idd).hide();
}
function wplay(iidd){
showPopup('<center>загрузка...</center>');
	$.ajax({
  type: "POST",
  url: '/index.php',
  data:{
	'tool': 'wplay',
	'play': iidd
	},
  success: function(msg){
showPopup(msg,1);
  }
});
}

function closePopup()
 {
   $('#opaco').toggleClass('hidden').removeAttr('style');
   $('#popup').toggleClass('hidden');
   	$('#poptxt').html('')

 }
 function closePopupv()
 {
   $('#opacov').toggleClass('hiddenv').removeAttr('style');
   $('#popupv').toggleClass('hiddenv');
   	$('#poptxtv').html('')

 }

function showPopupv(popup_type,ttq)
 { if(ttq==false) ttq=0;
 if(ttq==null) ttq=0;
 	if(ttq==0){
   if($.browser.msie)
   {
     $('#opacov').height($(document).height()).toggleClass('hiddenv');
   }
   else
   
   {
     $('#opacov').height($(document).height()).toggleClass('hiddenv').fadeTo('fast', 0.0);
   }

   $('#popupv')
     .toggleClass('hiddenv');
	}
	$('#poptxtv').html(popup_type)
   $('#popupv').alignCenter()


   return false;
 }
 
  function newmp3(elm){
$('#i_search').val($(elm).text());
$('.windows-main').find('h3').html('Результаты поиска');
 var href = $(elm).attr('href');
  jQuery('title').html($(elm).text()+', поиск музыки, музыкальный поисковик, скачать и слушать музыку бесплатно'); 

if ( history.pushState ) window.history.pushState("", "", href);
get_pl3('-1');
return false;
}

function newabc(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('Исполнители на букву '+atitle+''); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'abc':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('Исполнители на букву '+atitle); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-abc a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}

function rules(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('Правообладателям'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'rules':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('Правообладателям'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-rules a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html(''+$(val).html()+'');
	}
});
return false;
}

function cut(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('Нарезка MP3'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'cut':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('Нарезка MP3'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-cut a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html(''+$(val).html()+'');
	}
});
return false;
}

function top100(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 50 самых популярных'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'top':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 50 самых популярных'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function dfm(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 20 Радио DFM'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'dfm':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 20 Радио DFM'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function maximum(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 20 Радио Maximum'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'maximum':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 20 Радио Maximum'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function nashe(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 20 Наше Радио'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'nashe':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 20 Наше Радио'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function shanson(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 20 Радио шансон'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'shanson':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 20 Радио шансон'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function russkoe(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('ТОП 20 Русское Радио'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'russkoe':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('ТОП 20 Русское Радио'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}
function europa(alt,atitle,ap,elm){
  var href = $(elm).attr('href');
 if ( history.pushState ) window.history.pushState("", "", href);
 jQuery('title').html('Европа Плюс'); 
jQuery('#showmmnd').show();
 $.get("/ajax.php",{'europa':alt,'p':ap},  function(msg){
	$('.windows-main').find('h3').html('Европа Плюс'); 
	
	jQuery('#showmmnd').hide();
	
	var msg=msg.split('{JAVASCRIPT}');
	$('#glav_poisk').html(msg[0]);
	
$(".aabcl a").click(function(){
  return false;
});
$(".aidubal2 a").click(function(){

  return false;
});

	});
$('.window-top a').each(function(i,val) {
	if($(val).text() != atitle){
$(val).html($(val).text());
	} else { 
		$(val).html('<b>'+$(val).html()+'</b>');
	}
});
return false;
}

jQuery(document).ready(function() {

	reInitPage('domready',true);


});



function reInitPage(evnt, scroll) {


	initPlaylists(scroll);

}



function initPlaylists(scroll) {

	if (scroll === true) {

		




		var
		sliding_list = jQuery('#pl_block'),
		sliding_list_position = sliding_list.position();

		function sliding_list_pos() {

			var top = jQuery(window).scrollTop();

			if (top < sliding_list_position.top + 75) {
				sliding_list.css({
					position: 'static'
				});
				sliding_list_position.top = sliding_list_position.top;
				correctPlaylistHeight(0);
			} else {
				sliding_list.css({
					position: 'fixed',
					right: sliding_list_position.right,
					top: '10px'
				});
				correctPlaylistHeight(85);
			}
		}

		function correctPlaylistHeight(c) {

			var footerY = jQuery('footer').offset().top;
			var fromTop = jQuery(window).scrollTop();
			var viewportH = jQuery(window).height();
			var coverage = viewportH + fromTop;

			var isFooterVisible = ( coverage >= footerY ) ? true : false;

			c = ( typeof( c ) != 'undefined' ) ? c : 0;

			var height = ( isFooterVisible == true ) ? jQuery(window).height() - 320 : jQuery(window).height() - 160;

			if ( jQuery(window).height() > 500 ) {
				jQuery('#user-playlist-container').height(height + c + 'px');
			}
			
		}

		jQuery(window).bind('scroll',function() {
			sliding_list_pos();
		});
		
		sliding_list_pos();

		
	}

	reDrawPlayList('#playlist .track');
	reDrawPlayList('#user-playlist .track');
}
$(function(){$.fn.scrollToTop=function(){$(this).hide().removeAttr("href");if($(window).scrollTop()!="0"){$(this).fadeIn("slow")}var scrollDiv=$(this);$(window).scroll(function(){if($(window).scrollTop()=="0"){$(scrollDiv).fadeOut("slow")}else{$(scrollDiv).fadeIn("slow")}});$(this).click(function(){$("html, body").animate({scrollTop:0},"slow")})}});
