//var offsetX = -88; 
//var offsetY = -80;

var offsetX = -123; 
var offsetY = -117;

var mouseXPos = 0;
var mouseYPos = 0;

var media = 
{	
	id:"",
	pl:"",
	path:"",
	title:"",
	type:"",
	lyrics:"",
	keyword:""
};

var mediaTypes = new Array("sound", "video","sound2","sound2");
var hideTimerId = 0;

var locked = false;
var playerHeight = 30;
var controllerName = 'controller';	
var playerName = 'ffplayer';
var playlistName = 'playlist';
var empty = 'empty';



var playlistCurrentContainerID;
var playlistIsActiveVar = false;
var ajax = 0;
var suggest = false;
var ajaxRedirect = false;
var ajaxRedirectURL;

var documentTitle = null;
var pos = 0;
var spacer = " - ";
var scrollingTitle;
var scrollingTitle1;
var __type;
var parser;
var title;

function ScrollTitle()
{

documentTitle = documentTitle.toString();

document.title = documentTitle.substring(pos, documentTitle.length) + spacer + documentTitle.substring(0, pos) ;
pos++;
if (pos > documentTitle.length) pos=0;
scrollingTitle = setTimeout("ScrollTitle()",200);

}

function titleStop()
{
clearTimeout(scrollingTitle); 
clearTimeout(scrollingTitle1); 
document.title = (documentTitle == null) ? document.title : documentTitle ;
}


boxT = new Image(300,10);
boxT.src="http://"+site+"/imgs/t.gif";
boxB = new Image(300,10);
boxB.src="http://"+site+"/imgs/b.gif";


function mouseX(evt) {
if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else 
if (evt.clientX) return (evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft)); else return 0;
}
function mouseY(evt) {
if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else 
if (evt.clientY) return (evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)); else return 0;
}

function rand ( n )
{
  return ( Math.floor ( Math.random ( ) * ( n + 1 ) ) );
}


function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function enableSelection(target){

if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return true}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="text"
else //All other route (ie: Opera)
	target.onmousedown=function(){return true}
target.style.cursor = "default"
}

function _followfunction(evt) 
{
	if (document.getElementById) 
	{
		mouseXPos = (parseInt(mouseX(evt))+offsetX);
		mouseYPos = (parseInt(mouseY(evt))+offsetY);
	}
}

function _onmousedownfunction(evt) 
{

	if(!locked) 
	{
	var t2 = setTimeout("enableSelection(document.body)",2000);
	
	if ( $("#controller").css("left") != '-5000px' )
		var t1 = setTimeout ( "hideController()", 50 );

	}
	
	
	
	locked = false;
	

}


document.onmousedown = _onmousedownfunction;

document.onmousemove = _followfunction;


function _wheel(event)
{

	var step = 300;
	if (!event) 
	{
		event = window.event;
	}
	if (event.wheelDelta) 
	{
		wheelDelta = event.wheelDelta/120;
	} 
	else if (event.detail) 
	{
		wheelDelta = -event.detail/3;
	}


	wheelDelta = wheelDelta * 3;

	var callResult = document.getElementById(playlistName).setScroll(wheelDelta);



	if (event.preventDefault)
	{
		event.preventDefault();
	}
	event.returnValue = false;
	
	
}



function isPlaying() 
{	
	titleStop();
	scrollingTitle1 = setTimeout("ScrollTitle()",1000);

	document.siteLogoPic.src = "http://"+site+"/imgs/mp3lalogo-anim2.gif";
	
}

function isStopped() 
{
	document.siteLogoPic.src = "http://"+site+"/imgs/mp3lalogo.jpg";
	titleStop();

}

function popUpClose()
{	

	$("#mask").hide();
	$("#popup").hide();
	$("#youtube").hide();

	

	 $("#playlist_container").css("position","relative");
	 $("#playlist_container").css("left","0px");

}




		function register()
		{	


			var regLayer = document.getElementById("popup");

			$("#playlist_container").css("position","relative");
			$("#playlist_container").css("left","-5000px");

        var maskHeight = $(document).height();  
		$('#mask').css({'width':'100%','height':maskHeight,'opacity':0.7});  
          
         $('#mask').fadeIn(100);

		 
		 regLayer.innerHTML = "<div class='box'><table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td><div class=\"boxtop\"></div></td>  </tr>  <tr>    <td bgcolor=\"white\">  <div class='boxcontent'>	<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td align=\"left\" valign=\"top\"><span style=\"color:#68cb02;font-size:24px;font-weight:bold;padding-left:10px\">Регистрация</span></td>    <td align=\"right\" valign=\"top\"><a href=\"javascript:void(null)\" title=\"Закрыть\" onclick=\"popUpClose();return false;\"><img border=\"0\" style=\"float:right;padding-right:10px\" src=\"http://"+site+"/imgs/close.png\" /></a></td>  </tr></table><div id=\"popup_msg\"></div><div id=\"regForm\" style=\"padding-top:20px;padding-bottom:20px\"><form action=\"javascript:getRegister()\" id=\"regform\" name=\"regform\" method=\"post\"><table width=\"280\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\" style='padding-right:20px;'><tr><td width=\"110\" align=\"right\">Email: </td><td width=\"170\"><input id=\"email\" name=\"email\" type=\"text\" value=\"\" /></td></tr><tr><td align=\"right\">Пароль: </td><td><input id=\"pass\" name=\"pass\" type=\"password\" maxlength=\"17\" value=\"\" /><div style=\"font-size:12px;color:#68cb02\">от 7ми символов</div></td></tr><tr><td align=\"right\">еще раз: </td><td><input id=\"pass2\" name=\"pass2\" type=\"password\" maxlength=\"17\" value=\"\" /></td></tr></table><br /><input type='image' src='http://"+site+"/imgs/ok.png'/></form></div></div></td>  </tr>  <tr>    <td height=\"10\"> <div class=\"boxbottom\"></div></td>  </tr></table></div>";



		regLayer.style.position = "fixed";
	$('#popup').fadeIn(500);

			
			regLayer.style.top = "50%";
			regLayer.style.left = "50%";
			regLayer.style.marginLeft = "-150px";
			regLayer.style.marginTop = "-75px";
			
			
			
			regLayer.style.zIndex = "9999";

			$(".boxcontent").css("height","210px");

		}



function authorize()
{	


		

			var authLayer = document.getElementById("popup");
			
			$("#playlist_container").css("position","relative");
			$("#playlist_container").css("left","-5000px");


        var maskHeight = $(document).height();  
		$('#mask').css({'width':'100%','height':maskHeight,'opacity':0.7});  
           
         $('#mask').fadeIn(100);


				 authLayer.innerHTML = "<div class='box'><table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td><div class=\"boxtop\"></div></td>  </tr>  <tr>    <td bgcolor=\"white\">  <div class='boxcontent'>	<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td align=\"left\" valign=\"top\"><span style=\"color:#68cb02;font-size:24px;font-weight:bold;padding-left:10px\">Авторизация</span></td>    <td align=\"right\" valign=\"top\"><a href=\"javascript:void(null)\" title=\"Закрыть\" onclick=\"popUpClose();return false;\"><img border=\"0\" style=\"float:right;padding-right:10px\" src=\"http://"+site+"/imgs/close.png\" /></a></td>  </tr></table><div id=\"popup_msg\"></div><div id=\"authForm\" style=\"padding-top:20px;padding-bottom:20px\"><form action=\"javascript:getAuth()\" id=\"authform\" name=\"authform\" method=\"post\"><table width=\"280\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\" style='padding-right:20px;'><tr><td width=\"110\" align=\"right\">Email: </td><td width=\"170\"><input id=\"email\" name=\"email\" type=\"text\" value=\"\" /></td></tr><tr><td align=\"right\">Пароль: </td><td><input id=\"pass\" name=\"pass\" type=\"password\" maxlength=\"17\" value=\"\" /></table><br /><input type='image' src='http://"+site+"/imgs/ok.png'/></form></div></div></td>  </tr>  <tr>    <td height=\"10\"> <div class=\"boxbottom\"></div></td>  </tr></table></div>";

		
		authLayer.style.position = "fixed";
	$('#popup').fadeIn(500);

			
			authLayer.style.top = "50%";
			authLayer.style.left = "50%";
			authLayer.style.marginLeft = "-150px";
			authLayer.style.marginTop = "-75px";
			
			
			
			authLayer.style.zIndex = "9999";

			$(".boxcontent").css("height","170px");

}



		function getRegister()
		{

		 var email = $("input#email").val();  
		 var pass = $("input#pass").val();
		 var pass2 = $("input#pass2").val();

		 var dataString = 'm=reg&email='+ email + '&pass=' + pass + '&pass2=' + pass2 ; 
		 
		 $.ajax({
		   type: "POST",
		   url: "http://"+site+"/registered.php",
		   data: dataString,
		   success: function(msg){
			eval(msg);
			var reg_status = reg_response[0];
			var reg_message = reg_response[1];
		
			if (reg_status == true)
			{

				$('.boxcontent').css("height","100px");
				$('.boxcontent').html(reg_message);


					window.location = "http://"+site+"/";


			}
				
					
			if (reg_status == false)
			   {
	
				$('.boxcontent').css("height","240px");

				$('#popup_msg').css("padding-top","20px");
				
				$('#popup_msg').html(reg_message);


			   }
			 
			 
		   }

		 });

		}




		function getAuth()
		{

		


		 var email = $("input#email").val();  
		 var pass = $("input#pass").val();  
		 var dataString = 'm=auth&email='+ email + '&pass=' + pass ; 
		 
		 
		 $.ajax({
		   type: "POST",
		   url: "http://"+site+"/registered.php",
		   data: dataString,
		   success: function(msg){
	
				eval(msg);
				
				var auth_status = reg_response[0];
				var auth_message = reg_response[1];
								
				if (auth_status == true)
				{
				

				$('.boxcontent').css("height","100px");
				$('.boxcontent').html(auth_message);
				
				switch (ajaxRedirect)
				{
				case false:
					window.location = redirectURL;
					break;
				case true:
					window.location = ajaxRedirectURL;
					break;
				}

			}
				
					
			if (auth_status == false)
			   {
	
				$('.boxcontent').css("height","200px");

				$('#popup_msg').css("padding-top","20px");
				
				$('#popup_msg').html(auth_message);

			   }
			 
			 
		   }

		 });

		}




function logout()
{
		 

		 var dataString = 'm=logout'; 
		 
		 $.ajax({
		   type: "POST",
		   url: "http://"+site+"/registered.php",
		   data: dataString,
		   success:function(msg){
				switch (ajaxRedirect)
				{
				case false:
					window.location = redirectURL;
					break;
				case true:
					window.location = ajaxRedirectURL;
					break;
				}

		   }
		 });



}


/////////////////////////////////////////////////////////////
function goSource()
{	
	var path;
    var get;
	var browser = navigator.appName;

	if ( browser == 'Opera' ) 
	{
	get	= true;
	}
	else 
	{
	get = confirm("Получить ссылку на источник?");
	}

	if (get == true) 
	{

	
		switch (parseInt(__type))
		{
			case 0:
				

				var directLink = (media.path.indexOf("http://"+remote+"/") != -1);
		
				if (directLink)
				{
					
					path = media.path;
					var source_prompt = prompt("Ссылка на источник:",path);

				} else {

					dataString = 'url=' + media.path ;
					
					$.ajax({
					   type: "POST",
					   data: dataString,
					   url: 'http://'+site+'/liru.php',
					   success: function(msg){
							
							path = msg;
							var source_prompt = prompt("Ссылка на источник:",path);
							
					   }

					 });
				}

				break;

			case 2:

				var directLink = (media.path.indexOf("http://"+remote+"/") != -1);
				
				//http://my.mail.ru/cgi-bin/my/audiotrack?file=5da308f45546dd2515f7ed28f732d431&uid=-490724
				
				var mailSource = media.mail.split("@");
				
				if (directLink)
				{
					
					path = media.path;
					var source_prompt = prompt("Ссылка на источник:",path);

				} else {

					var source_prompt = prompt("Ссылка на источник:",'http://my.mail.ru/cgi-bin/my/audiotrack?file=' + mailSource[0] + '&uid=' + mailSource[1]);
							
				}
		
				break;
				
			case 3:

			
		
				var directLink = (media.path.indexOf("http://"+remote+"/") != -1);
				
				//http://my.mail.ru/cgi-bin/my/audiotrack?file=5da308f45546dd2515f7ed28f732d431&uid=-490724
				
				var mailSource = media.mail.split("@");
				

		
				if (directLink)
				{
					
					path = media.path;
					var source_prompt = prompt("Ссылка на источник:",path);

				} else {

					var source_prompt = prompt("Ссылка на источник:",'http://vkontakte.ru/gsearch.php?section=audio&q='+encodeURIComponent(media.title));
							
				}
		
				break;
			
			case 1:
				
				path = 'http://www.youtube.com/watch?v=' + media.path;
				var source_prompt = prompt("Ссылка на источник:",path);
				break;
			
		}

	}

}


function getSearch(inputSearch) 
{	
	
	var hit = true;

	ajaxRedirect = true;
	
	if ( Boolean(inputSearch) == false ) {
		
		var inputSearch = $("#q").val();
		hit = false;

	}

	else $("#q").val(inputSearch);

	var x = rand(19);
	var y = rand(19);


var query = encodeURIComponent(inputSearch);

	$("#resultcell").html("<div style=\"padding:200px 0 200px 167px;\"><img src=\"http://"+site+"/imgs/ajax-loader.gif\" /></div>");

var url="http://"+site+"/search.php";
url=url+"?q="+query;
url=url+"&x="+x;
url=url+"&y="+y;

ajaxRedirectURL = url;
ajaxRedirectURL += '&r=1';

var pl = url;

url=url+"&ajax=1";
if (hit) url=url+"&nh=1";
url=url+"&sid="+Math.random();

pl=pl+"&pl=1";
pl=pl+"&sid="+Math.random();

		
 $.ajax({
   type: "GET",
   url: url,
   success: function(msg){
	

	if (msg == 'false')
	{
	window.location="http://"+site+"/";
	}
	else {

		$("#resultcell").html(msg);
		document.title = $("#title").html();
		getPlaylist(pl);
	

	}

   }

 });


}

function submitForm()
{
$(".ac_results").hide();
document.formsearch.submit();
}





function ajaxPagi(url) 
{	
	ajaxRedirect = true;
	ajaxRedirectURL = url;


	var url = url;
	var pl;

	$("#resultcell").html("<div style=\"padding:200px 0 200px 167px;\"><img src=\"http://"+site+"/imgs/ajax-loader.gif\" /></div>");
	

pl=url;

url=url+"&ap=1";
url=url+"&sid="+Math.random();


pl=pl+"&pl=1";
pl=pl+"&sid="+Math.random();


 $.ajax({
   type: "GET",
   url: url,
   success: function(msg){
	
	$("#resultcell").html(msg);
	getPlaylist(pl);


   }

 });


}

function getPlaylist(url)
{	

		 $.ajax({
		   type: "GET",
		   url: url,
		   dataType: "script",
		   success: function(msg){
					
			$("#playdata").empty()
			
			$("#playdata").html(msg);
					
		   }

		 });

}

function sendPlaylist(n)
{	

var playlist=window.confirm("Передать плейлист?");

	if (playlist) 
	{
		dataString = 'n=' + n ;
		

		$.ajax({
		   type: "POST",
   		   data: dataString,
		   url: 'http://'+site+'/playlist.php',
		   success: function(msg){
				
				eval(msg);
	
				var playlist_title = playlist_response[0];
				var playlist_url = playlist_response[1];

			   
				var url_prompt = prompt(playlist_title,playlist_url);

		   }

		 });

	}
}


function getLink(pl,title,url,type,mail)
{

var type = type;

if (pl)
	{

		switch (type)
		{
		case 'sound':
			var type = 0;
			break;
		
		case 'sound2':
			var type = 2;
			break;

		case 'video':
			var type = 1;
			break;
		}

	}

var link=window.confirm("Получить ссылку?");

	if (link) 
	{
		dataString = 'url=' + url +'&title=' + title + '&type='+type + '&mail=' + mail;
		


		$.ajax({
		   type: "POST",
   		   data: dataString,
		   url: 'http://'+site+'/link.php',
		   success: function(msg){

				eval(msg);
	
				var link_title = link_response[0];
				var link_url = link_response[1];

			   
				var url_prompt = prompt(link_title,link_url);

		   }

		 });

	}
}



function getVideo()
{
getVideoWPager(1);
}



function getVideoWPager(ytStartIndex)
{

disableSelection(document.body);
hideController();

$("#txtloading").css("top","50%");
$("#txtloading").css("left","50%");
$("#txtloading").css("margin-left","-100px");
$("#txtloading").css("margit-top","-25px");
$("#txtloading").css("display","block");
$("#txtloading").css("text-align","center");
$("#txtloading").css("width","200px");
$("#txtloading").css("height","50px");
$("#txtloading").css("background-color","#fdfff8");
$("#txtloading").css("border","1px solid #a0c735");
$("#txtloading").css("position","fixed");

$("#txtloading").html("<span style=\"font-size:12px;\">Поиск ...  </span><img style=\"position:relative;top:10px;\" src=\"http://"+site+"/imgs/ajax-loader.gif\" />");

title = media.title;

var url="http://"+site+"/getyoutube.php";
url=url+"?title="+title;
url=url+"&ytp_index="+ytStartIndex;
url=url+"&sid="+Math.random();

 $.ajax({
   type: "GET",
   url: url,
   success: function(msg){
	

	$("#txtloading").css("display","none")
	$("#txtloading").html("");
	
	$("#youtube_serp").css("display","block");
	$("#youtube_serp").html(msg);
	
   }

 });


}

function showVideo(vid)
{
			
			
			var youtubeLayer = document.getElementById("youtube");

						$("#playlist_container").css("position","relative");
			$("#playlist_container").css("left","-5000px");


        var maskHeight = $(document).height();  
		$('#mask').css({'width':'100%','height':maskHeight,'opacity':0.7});  
          
         $('#mask').fadeIn(100);

		 
		 youtubeLayer.innerHTML = "<object width=\"480\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+vid+"&amp;hl=en_US&amp;fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+vid+"&amp;hl=en_US&amp;fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"480\" height=\"385\"></embed></object><img src='http://mp3la.ru/imgs/roundclose.png' onclick=\"javascript:popUpClose();\"/>";



		youtubeLayer.style.position = "fixed";
	$('#youtube').fadeIn(500);

			
			youtubeLayer.style.top = "50%";
			youtubeLayer.style.left = "50%";
			youtubeLayer.style.marginLeft = "-240px";
			youtubeLayer.style.marginTop = "-192px";
			
			
			
			youtubeLayer.style.zIndex = "9998";


}


function loadLyrics(q)
{


var text = q;
var title = q;

var url="http://"+site+"/lyrics.php";
url=url+"?text="+text;
url=url+"&title="+title;
url=url+"&l=1";
url=url+"&sid="+Math.random();

 $.ajax({
   type: "GET",
   url: url,
   success: function(msg){
	
	$("#txtlyrics").css("display","none");
	$("#txtlyrics").html(msg);
	$('#txtlyrics').fadeIn(1000);
	
   }

 });

}

function mailruDb(path,title,keyword)
{

var title = encodeURIComponent(title);
var keyword = encodeURIComponent(keyword);

var url="http://"+site+"/mail.php";
url=url+"?url=" + path;
url=url+"&title=" + title;
url=url+"&keyword=" + keyword;

 $.ajax({
   type: "GET",
   url: url

 });


}


function showLyrics(pl,titlepl, pathpl, typepl,keywordpl)
{

disableSelection(document.body);
hideLyrics();
hideController();


if(pl)
{
$("#txtlyrics").css("display","block");
$("#txtlyrics").html("<img style=\"position:relative;top:20px;\" src=\"http://"+site+"/imgs/ajax-loader.gif\" />");
}
else
{
$("#txtloading").css("top","50%");
$("#txtloading").css("left","50%");
$("#txtloading").css("margin-left","-100px");
$("#txtloading").css("margit-top","-25px");
$("#txtloading").css("display","block");
$("#txtloading").css("text-align","center");
$("#txtloading").css("width","200px");
$("#txtloading").css("height","50px");
$("#txtloading").css("background-color","#fdfff8");
$("#txtloading").css("border","1px solid #a0c735");
$("#txtloading").css("position","fixed");

$("#txtloading").html("<span style=\"font-size:12px;\">Поиск ...  </span><img style=\"position:relative;top:10px;\" src=\"http://"+site+"/imgs/ajax-loader.gif\" />");

}




if(pl)
{
text = titlepl;
title = titlepl;
keyword = keywordpl;
type = typepl;
uid = pathpl;

} else

{
text = media.lyrics;
title = media.title;
keyword = media.keyword;
type = __type;
uid = media.path;
}

var url="http://"+site+"/lyrics.php";
url=url+"?text="+text;
url=url+"&title="+title;
url=url+"&keyword="+keyword;
url=url+"&url="+uid;
url=url+"&type="+type;
if (pl) url=url+"&p=1";
url=url+"&sid="+Math.random();

 $.ajax({
   type: "GET",
   url: url,
   success: function(msg){
	

	$("#txtloading").css("display","none")
	$("#txtloading").html("");
	
	$("#txtlyrics").css("display","block");
	$("#txtlyrics").html(msg);
	
   }

 });


}


function startDownload(pl,titlepl, pathpl, typepl,keywordpl) 
{


if(pl)
{


title = titlepl;
path = pathpl;

	var directLink = (path.indexOf("http://"+remote+"/") != -1);
	
	if (directLink)
	{
		var type = 's';
	}
	else {
				

		switch (typepl)
		{
		case 'sound':
			var type = 0;
			break;
		
		case 'sound2':
			var type = 2;
			break;

		case 'video':
			var type = 1;
			break;
		}
	
	}


	keyword = keywordpl;

} else
{

title = media.title;
path = media.path;
type = __type;
keyword = media.keyword;

}



// title=encodeURIComponent(title);

	switch (type)
	{
		case 0:
			path = 'http://'+site+'/download.php?url=' + path + '&type=0&title=' + title+ '&keyword=' + encodeURIComponent(keyword);
			//path = 'http://'+site+'/download.php?url=' + path + '&type=0&title=' + encodeURIComponent(title) + '&keyword=' + encodeURIComponent(keyword);
			break;
		case 1:
			path = 'http://'+site+'/download.php?url=' + path + '&type=1&title=' + title+ '&keyword=' + encodeURIComponent(keyword);
			break;
		case 2:
			path = 'http://'+site+'/download.php?url=' + path + '&type=2&title=' + title+ '&keyword=' + encodeURIComponent(keyword);
			//path = 'http://'+site+'/download.php?url=' + path + '&type=2&title=' + encodeURIComponent(title) + '&keyword=' + encodeURIComponent(keyword);
			break;
		case 3:
			path = 'http://'+site+'/download.php?url=' + path + '&type=3&title=' + title+ '&keyword=' + encodeURIComponent(keyword);
			//path = 'http://'+site+'/download.php?url=' + path + '&type=2&title=' + encodeURIComponent(title) + '&keyword=' + encodeURIComponent(keyword);
			break;
		case 's':
			path = 'http://'+site+'/download.php?url=' + path + '&type=s&title=' + title+ '&keyword=' + encodeURIComponent(keyword);
			break;

	}
	

	window.open(path, "down_win" ,"width=540, height=640, scrollbars=no, resizable=no, menubar=no, location=no, status=no, toolbar=no, fullscreen=no");
	
}






function _startDownload(pl,titlepl, pathpl, typepl,keywordpl) 
{



if(pl)
{

title = titlepl;
path = pathpl;

		switch (typepl)
		{
		case 'sound':
			var type = 0;
			break;
		
		case 'sound2':
			var type = 2;
			break;

		case 'video':
			var type = 1;
			break;
		}


keyword = keywordpl;

} else
{

title = media.title;
path = media.path;
type = __type;
keyword = media.keyword;

}



	var directLink = (path.indexOf("http://"+remote+"/") != -1);
	
	if (directLink)
	{
				
		var source_prompt = prompt("Ссылка для скачивания:",path);

	}
	
	
	else
	{
		
		$("#txtloading").css("top","50%");
		$("#txtloading").css("left","50%");
		$("#txtloading").css("margin-top","-25px");
		$("#txtloading").css("margin-left","-100px");
		$("#txtloading").css("display","block");
		$("#txtloading").css("text-align","center");
		$("#txtloading").css("width","200px");
		$("#txtloading").css("height","50px");
		$("#txtloading").css("background-color","#fdfff8");
		$("#txtloading").css("border","1px solid #a0c735");
		$("#txtloading").css("position","fixed");

		$("#txtloading").html("<span style=\"font-size:12px;\">Генерация ссылки ...  </span><img style=\"position:relative;top:10px;\" src=\"http://"+site+"/imgs/ajax-loader.gif\" />");
		

		dataString = 'path=' + path +'&type=' + type + '&keyword=' + keyword;
		

		$.ajax({
		   type: "POST",
		   data: dataString,
		   url: 'http://'+site+'/download.php',
		   success: function(msg){
				
				$("#txtloading").html("");
				$("#txtloading").css("display","none");

				var url_prompt = prompt("Ссылка для скачивания:",msg);
					

		   }

		 });

	}
	

}

function showController()
{	

	var directLink = (media.path.indexOf("http://"+remote+"/") != -1);

	if (!directLink) {
		ct = setTimeout("controllerSourceOn()",0);
	}



	var controller = document.getElementById(controllerName).style;
	controller.left = mouseXPos + "px";
	controller.top = mouseYPos + "px";
}


function hideController() 
{
	
	var ct = setTimeout("controllerSourceOff()",0);

	var controller = document.getElementById(controllerName).style; 
 controller.left = "-5000px";

}

function hideLyrics() 
{
	var obj = document.getElementById("txtlyrics").style; 
	obj.display = "none";
}

function showPlayer() 
{	
	
	playerIsVisible = true;
	
	$("#empty").css("padding-top","70px");

	$("#ffplayer").css("visibility","visible");
	$("#ffplayer").css("position","relative");
	$("#ffplayer").css("left","9px");
	
	playSelectedMedia();


}


function controllerSourceOn()
{
var controller = getFlashMovieObject('controller');
var callResult = controller.sourceVisible(true);
}

function controllerSourceOff()
{
	
var controller = getFlashMovieObject('controller');

try
  {
var callResult = controller.sourceVisible(false);
  }
catch(err)
  {
	var callResult = controller.sourceVisible(false);
  }


}

function setParser()
{

	var parsersArrayCount = parsersArray.length;
	var parserRand = rand(--parsersArrayCount);
	parser = parsersArray[parserRand];
	
}


function setSelected(_id, _pl, _path, _title, _type, _link, _lyrics, _keyword, _mail) 
{
	
	setParser();

	disableSelection(document.body);
	titleStop();


	locked = true;
	media.id = _id;
	media.pl = _pl;
	media.path = _path;
	media.title = _title;
	__type = _type;
	media.lyrics = _lyrics;
	media.keyword = _keyword;
	media.mail = _mail;

	documentTitle = media.pl;
	document.title = media.pl;
    
	

			if (playlistCurrentContainerID)
			{
				
				var playlistLastSongContainer = document.getElementById('playlistSong' + playlistCurrentContainerID);
				
				if (playlistLastSongContainer) 
				{
				
				playlistLastSongContainer.childNodes[0].className = 'mediaLinkContainer';
				
				}

			} 
			
		playlistCurrentContainerID = _id;	
		
            var playlistCurrentSongContainer = document.getElementById('playlistSong' + _id).getElementsByTagName("div");
			
			var urso=document.getElementById('playlistSong' + _id);

			playlistCurrentSongContainer[0].className = 'mediaLinkContainerSelected';
    
	showController();

} 

function playSelected() 
{

	disableSelection(document.body);
	playSelectedMedia();
	hideController();

}

		
function errorUrl() 
{
	playNext();
}




function playNext() 
{	

		titleStop();
		

		
		if (playlistIsActiveVar ) {
		
			var callResult = document.getElementById(playlistName).playNextPlaylistItem(); 
				
		} else 
		{

			
			if (playlistCurrentContainerID < playList.length - 1) 
			{
					
				
				playlistNextSong = playlistCurrentContainerID;

				var playlistLastSongContainer = document.getElementById('playlistSong' + playlistCurrentContainerID);
				playlistLastSongContainer.childNodes[0].className = 'mediaLinkContainer';

				playlistNextSong++;
				
				var playlistCurrentSongContainer = document.getElementById('playlistSong' + playlistNextSong);

				playlistCurrentSongContainer.childNodes[0].className = 'mediaLinkContainerSelected';
				
				playlistCurrentContainerID = playlistNextSong;

				

				documentTitle = titles[playlistCurrentContainerID];

				
				if ( playList[playlistCurrentContainerID][0].indexOf("http://"+remote+"/") != -1 )
				
					path = playList[playlistCurrentContainerID][0];
				
				else {
					switch (playList[playlistCurrentContainerID][1])
					{
					case 0:
						path = 'http://'+parser+'/liru.php?url=' + playList[playlistCurrentContainerID][0];
						break;
					case 1:
						path = 'http://'+parser+'/youtube.php?videoid=' + playList[playlistCurrentContainerID][0];
						break;
					case 2:
						path = 'http://'+parser+'/mail.php?url=' + playList[playlistCurrentContainerID][0];
						break;
						
					case 3:
						path = 'http://'+parser+'/vk.php?url=' + playList[playlistCurrentContainerID][0];
						break;
						
					case 4:
						path = playList[playlistCurrentContainerID][0];
						break;
				
					}
				}
				
								
				sendToFFPlayer(path,  mediaTypes[playList[playlistCurrentContainerID][1]]);
				setTimeout("loadLyrics(karaoke[playlistCurrentContainerID])",500);


			} else repeatPlaylist();



		}
	
}

function repeatPlaylist() {

	var playlistLastSongContainer = document.getElementById('playlistSong' + playlistCurrentContainerID);
	playlistLastSongContainer.childNodes[0].className = 'mediaLinkContainer';

	playlistCurrentContainerID = 1;

	
	documentTitle = titles[playlistCurrentContainerID];


	var playlistCurrentSongContainer = document.getElementById('playlistSong' + playlistCurrentContainerID);
	playlistCurrentSongContainer.childNodes[0].className = 'mediaLinkContainerSelected';
  
        	 
		if ( playList[playlistCurrentContainerID][0].indexOf("http://"+remote+"/") != -1 )
		
			path = playList[playlistCurrentContainerID][0];
		
		else {
            switch (playList[playlistCurrentContainerID][1])
			{
			case 0:
				path = 'http://'+parser+'/liru.php?url=' + playList[playlistCurrentContainerID][0];
				break;
			case 1:
				path = 'http://'+parser+'/youtube.php?videoid=' + playList[playlistCurrentContainerID][0];
				break;
			case 2:
				path = 'http://'+parser+'/mail.php?url=' + playList[playlistCurrentContainerID][0];
				break;
			case 3:
				path = 'http://'+parser+'/vk.php?url=' + playList[playlistCurrentContainerID][0];
				break;
			
			case 4:
				path =  playList[playlistCurrentContainerID][0];
				break;

			}
		}

		//var player = document.getElementById('ffplayer');
		//var callResult = player.startComposition(path, mediaTypes[playList[playlistCurrentContainerID][1]]);
		sendToFFPlayer(path, mediaTypes[playList[playlistCurrentContainerID][1]]);
		setTimeout("loadLyrics(karaoke[playlistCurrentContainerID])",500);



}

function onPlayDB(path,title,keyword,source)
{

var title = encodeURIComponent(title);
var keyword = encodeURIComponent(keyword);

var url="http://"+site+"/"+source+".php";
url=url+"?url=" + path;
url=url+"&title=" + title;
url=url+"&keyword=" + keyword;

 $.ajax({
   type: "GET",
   url: url

 });


}


function playSelectedMedia() 
{

	playlistIsActiveVar = false;

	var callResult = document.getElementById(playlistName).analyzerOff();

		var directLink = (media.path.indexOf(site) != -1);

		if (directLink)
		{
			
			sendToFFPlayer(media.path, __type);
			return false;

		}

		switch (__type)
	{
	case 0:
		//path = 'http://'+site+'/liru.php?url=' + media.path + '&title=' + encodeURIComponent(media.title) + '&keyword=' + encodeURIComponent(media.keyword);
		path = 'http://'+parser+'/liru.php?url=' + media.path;
	sendToFFPlayer(path, mediaTypes[__type]);
	onPlayDB(media.path,media.title,media.keyword,'liru');
		break;
	case 1:
		path = 'http://'+site+'/youtube.php?videoid=' + media.path + '&title=' + encodeURIComponent(media.title) + '&keyword=' + encodeURIComponent(media.keyword);
	sendToFFPlayer(path, mediaTypes[__type]);
		break;
	case 2:
	    //path = 'http://'+site+'/mail.php?url=' + media.path + '&title=' + encodeURIComponent(media.title) + '&keyword=' + encodeURIComponent(media.keyword);
	    path = 'http://'+parser+'/mail.php?url=' + media.path;
		sendToFFPlayer(path, mediaTypes[__type]);
		onPlayDB(media.path,media.title,media.keyword,'mail');
		break;
	case 3:
		path="http://"+parser+"/vk.php?url="+media.path;
		sendToFFPlayer(path, mediaTypes[__type]);
		onPlayDB(media.path,media.title,media.keyword,'vk');
		break;
	case 4:
		path=media.path;
		sendToFFPlayer(path, mediaTypes[__type]);
		onPlayDB(media.path,media.title,media.keyword,'vk');
		break;
		
	}
	documentTitle = media.pl;
	setTimeout("loadLyrics(media.title)",500);


}

function getFlashMovieObject(swf)
{

var movieName = swf;

if(document.embeds[movieName])
return document.embeds[movieName];
if(window.document[movieName])
return window.document[movieName];
if(window[movieName])
return window[movieName];
if(document[movieName])
return document[movieName];
return null;
}


function sendToFFPlayer(value1, value2) 
{	
	var player = getFlashMovieObject('ffplayer');


	if (value2 == 'sound2') value2 = 'sound';
	var callResult = player.startComposition(value1, value2);

	
}


function playlistIsActive(value)
{
playlistIsActiveVar = value;
}


function toPlaylist() 
{
var playlistVarName = decodeURIComponent(media.pl);
var callResult = document.getElementById(playlistName).addToPlaylist(playlistVarName, media.path, media.keyword,mediaTypes[__type],media.mail); 
}



function allToPlaylist()
{

	var copyWholePlaylist=window.confirm("Добавить все композиции в плейлист ?");

	if (copyWholePlaylist)
		{

        var maskHeight = $(document).height();  
		$('#mask').css({'width':'100%','height':maskHeight,'opacity':0.7});  
          
         $('#mask').fadeIn(100);

		var playlistSize = types.length;


			var plLayer = document.getElementById("popup");

			$("#playlist_container").css("position","relative");
			$("#playlist_container").css("left","-5000px");





		 plLayer.innerHTML = "<div class='box'><table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">  <tr>    <td><div class=\"boxtop\"></div></td>  </tr>  <tr>    <td bgcolor=\"white\">  <div class='boxcontent'></div></td>  </tr>  <tr>    <td height=\"10\"> <div class=\"boxbottom\"></div></td>  </tr></table></div>";


		plLayer.style.position = "fixed";
		$('#popup').fadeIn(500);

			
			plLayer.style.top = "50%";
			plLayer.style.left = "50%";
			plLayer.style.marginLeft = "-150px";
			plLayer.style.marginTop = "-75px";
			
			
			
			plLayer.style.zIndex = "9999";

			$(".boxcontent").css("height","100px");
			
			$('.boxcontent').html("<div style=\"padding-top:35px\"><img src=\"http://"+site+"/imgs/ajax-loader.gif\" /><span style=\"color:#4d9902;font-size:24px;font-weight:bold;padding-left:10px;position:relative;top:-5px\">Загрузка...</span></div>");
			
	
	for(i=1;i<playlistSize;i++)
	
		{
		var playlistVarName = decodeURIComponent(titles[i]);
		var callResult = document.getElementById(playlistName).addToPlaylist(playlistVarName, playList[i][0], keywords[i] , types[i], mail[i] ); 
		}

	var uploaded = setTimeout("popUpClose()",2000);
	
	setTimeout("throwAlert('Плейлист добавлен!')",2500);
	
	}

}

function throwAlert(msg)
{
alert(msg);
}


function sendToPlayerFromPlaylist(value1, value2, value3,value4) 

{	

	setParser();

	var callResult = document.getElementById(playlistName).analyzerOn();


    documentTitle = value4;


	//$("#empty").css("padding-top","70px");


		playlistIsActiveVar = true;

		var directLink = (value1.indexOf("mp3la.ru") != -1);
		

		if (directLink)
		{
			
			path = value1;

		}


		else {

			switch (value2)
			{
			case 'sound':
				path = 'http://'+parser+'/liru.php?url=' + value1;
				break;
			
			case 'sound2':
				path = 'http://'+parser+'/mail.php?url=' + value1;
				break;

			case 'video':
				path = 'http://'+parser+'/youtube.php?videoid=' + value1;
				break;
			}
		
		}
		

		sendToFFPlayer(path, value2);
		loadLyrics(value3);


   //var callResult = document.getElementById(playerName).setPlayAll();

}

$(document).ready(function() {	

	

	$('#mask').click(function () {
		 		
		popUpClose();
		

	});			
   
    $("#playlist_container").bind('mousewheel', function(event, delta) {
		
            return false;
		
	 });


		var playlist = document.getElementById("playlist_container");
		playlist.onmousewheel = _wheel;




});


var playerFlashVars =
{
};

var playerParams =
{
	allowscriptaccess: 'always',
	bgcolor: '#FFFFFF',
	wmode: 'opaque'
};


var controllerFlashVars =
{
	shadow:"true"
};

var controllerParams =
{
	allowscriptaccess: 'always',
	wmode: 'transparent'
}; 


var playlistParams =
{
	allowscriptaccess: 'always',
	bgcolor: '#FFFFFF',
	wmode: 'window'
};




swfobject.embedSWF('http://'+site+'/ffplayer.swf?burner='+Math.random(), 'ffplayer', '363', 30, '9.0.0', "expressInstall.swf", playerFlashVars, playerParams);
swfobject.embedSWF('http://'+site+'/controller.swf?burner='+Math.random(), 'controller', '250', '250', '9.0.0', "expressInstall.swf", controllerFlashVars, controllerParams);
swfobject.embedSWF('http://'+site+'/playlist.swf?burner='+Math.random(), 'playlist', '295', '500', '9.0.0', "expressInstall.swf", playlistFlashVars, playlistParams);


