 function performers_page(data)
{	
	if(data.letter<='9'){
		letters = '0123456789';
		active = 1;
	}
	else if(data.letter<='z'){
		letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		active = 2;
	}
	else{
		letters = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЭЮЯ';
		active = 3;
	}
	h = '<div id="performersLayout">';
	h += '<div id="language_toggle">';
		h += '<a href="/#performers/letter/A"  '+((active==2)?('class="active"'):(''))+'>EN</a>';
		h += '<a href="/#performers/letter/А"  '+((active==3)?('class="active"'):(''))+'>RU</a>';	
		h +=' <a href="/#performers/letter/0"  '+((active==1)?('class="active"'):(''))+'>0..9</a>';		
	h += '</div>';
	h += '<div class="sub-nav">';
	letters = letters.split("");
	for (i = 0; i <letters.length; i++) {
			h += '<a '+((letters[i]==data.letter)?('class="active"'):(''))+' href="/#performers/letter/'+letters[i]+'">';
			h += letters[i];
			h += '</a>';
	}
	h += info({title:'Как добавить нового исполнителя?', url:'/media/howto/performers.txt', style:'top:10px;'});
	h += '</div>';
	h += '<div class="performer-switch">';
	h += '<a href="javascript:;" class="switch-links lactive" title="Просмотр в виде списка"></a>';
	h += '<a href="javascript:;" class="switch-pics" title="Просмотр в виде мозаики"></a>';
	h += '</div>';
	h +="<div class='top-performers'>";
	var CountTopPerformers=22;
	if(data.top_performers.length < CountTopPerformers) CountTopPerformers=data.top_performers.length;
	for (i = 0; i < CountTopPerformers; i++) {
		h += '<a id="p' + i + '" href="/#performers/' + data.top_performers[i].id + '"><img src="' + data.top_performers[i].image + '" /></a>';
	}

	h +="</div>";
	half = 0;
	if (data.performers.length > 3){
		half = Math.round(data.performers.length/2);
		h += '<div class="col col1">';
		for(i=0; i<half; i++){
			print_perfs(data.performers);
		}
		h += '</div>';
		
	}
	h += '<div class="col">';
	for(i=half; i<data.performers.length; i++){
		print_perfs(data.performers);		
	}
	h += '</div>'
	h += '</div>';
	$('#leftContent').html(h);
	
	commonToolTip({
		obj : ".top-performers",
		hoverObj : "a",
		data : data.top_performers,
		field1 : "name",
		field2 : "tracks_num",
		initLeft : 5,
		objectWidth : 57,
		initTop : -60,
		objectHeight: 58,
		perLine : 11,
		invert : 1,
		title : "Треков на сайте: "
	});
	
	h = ban240x400(topArtists.init(data.topPerformers).get(0, 5));
	$('#dynamicRightContent').css('margin-top', "0px");
	$('#dynamicRightContent').html(h);
	topArtists.addEvents("#dynamicRightContent .banner240x400 .topPerformers");
	
	$('.performer-switch .switch-pics').bind('click',function(){
		$(this).addClass('pactive');
		$('.performer-switch .switch-links').removeClass('lactive');
		var tmp='';
		for (i = 0; i < data.top_performers.length; i++) {
			tmp += '<a id="p' + i + '" href="/#performers/' + data.top_performers[i].id + '"><img src="'+data.top_performers[i].image+'" /></a>';
		}
		$('.top-performers').html(tmp);
		$('.col').hide();
		
		commonToolTip({
			obj : ".top-performers",
			hoverObj : "a",
			data : data.top_performers,
			field1 : "name",
			field2 : "tracks_num",
			initLeft : 5,
			objectWidth : 57,
			initTop : -60,
			objectHeight: 58,
			perLine : 11,
			invert : 1,
			title : "Треков на сайте: "
		});
		
	});
	$('.performer-switch .switch-links').bind('click',function(){
		$(this).addClass('lactive');
		$('.performer-switch .switch-pics').removeClass('pactive');
		var tmp='';
		var CountTopPerformers=22;
		if(data.top_performers.length < CountTopPerformers) CountTopPerformers=data.top_performers.length;
		for (i = 0; i < CountTopPerformers; i++) {
			tmp += '<a id="p' + i + '" href="/#performers/' + data.top_performers[i].id + '"><img src="'+data.top_performers[i].image+'" /></a>';
		}
		$('.top-performers').html(tmp);
		
		commonToolTip({
			obj : ".top-performers",
			hoverObj : "a",
			data : data.top_performers,
			field1 : "name",
			field2 : "tracks_num",
			initLeft : 5,
			objectWidth : 57,
			initTop : -60,
			objectHeight: 58,
			perLine : 11,
			invert : 1,
			title : "Треков на сайте: "
		});
		$('.col').show();
	});
}


function print_perfs(p)
{
	h += '<div class="item" ><span>—</span> <a href="/#performers/' + p[i].id + '">' +p[i].name + '</a><br/>';
	h += '<div class="tags"><div class="gradientperf"></div>';
	for(var k=0; k<p[i].tags.length-1;k++){
		h += p[i].tags[k].tag + ', ';
	}
	if(p[i].tags.length>=1){
		h += p[i].tags[p[i].tags.length-1].tag
	}
	else{
		h += 'Исполнитель пока что не отмечен тегами.';
	}
	h += '</div></div>';
}


function performer_page(data){
	var h = '';
	var fav = 0; 
	h += "<div class='subMenu performers'>";
	h += "<a class='menuItem " + ((data.subType=='')?("active"):("")) + "' href='/#performers/" + data.perfId + "'>общая</a>";
	h += "<a class='menuItem " + ((data.subType=='tracks')?("active"):("")) + "' href='/#performers/" + data.perfId + "/tracks'>треки</a>";
	h += "<a class='menuItem " + ((data.subType=='bio')?("active"):("")) + "' href='/#performers/" + data.perfId + "/bio'>биография</a>";
//	h += "<a class='menuItem " + ((data.subType=='events')?("active"):("")) + "' href='/#performers/" + data.perfId + "/events'>афиша</a>";
	h += "<a class='menuItem " + ((data.subType=='fans')?("active"):("")) + "' href='/#performers/" + data.perfId + "/fans'>поклонники</a>";
	h += "<a class='menuItem " + ((data.subType=='alike')?("active"):("")) + "' href='/#performers/" + data.perfId + "/alike'>похожие исполнители</a>";
	h += "<a class='menuItem " + ((data.subType=='videos')?("active"):("")) + "' href='/#performers/" + data.perfId + "/videos'>видеоклипы</a>";
	h += "</div>";
	h += "<div class='subTitle'>" + data.name.toUpperCase() + "</div>";
	h += "<div class='pInfo' style='//height:40px;'>";
	if (data.nowListening.length > 0) {
		h += "Сейчас слушают: ";
		for (i = 0; i < data.nowListening.length; i++) {
			h += "<a class='tahomaNick' style='float:none;' href='/#users/" + data.nowListening[i].nick + "'>" + data.nowListening[i].nick + "</a>";
			h += ((i < data.nowListening.length - 1) ? (", ") : (""));
		}
	} else {
		h += 'Общее количество треков на сайте: <b>' + data.tracks_num + '</b>. Мало? <a href="javascript:Uploader_Object(\'openWnd\');">Загрузите ещё.</a>';
	}
	h += "<div class='activities'>";
	h += "<span class='artComments' title='количество коментариев'></span>";
	h += "<span class='people' title='количество поклонников'>" + data.nFans + "</span>";
	h += "<span class='ntracks' title='количество треков'>" + data.tracks_num + "</span>";
	h += "<span class='nlistens' title='количество прослушиваний'>0</span>";
	h += "<span class='votes' title='рейтинг исполнителя'>" + data.rate + "</span>";
	h += "</div><br clear='All'/>";
	h += "<div class='articleTopInfo'>";
	h += "<span class='buttons'>";
	h += "<a href='javascript:;' class='inFav " + ((data.isFav)?("favDone"):("")) + "'>" + ((data.isFav)?("Убрать из избранного"):("Добавить в избранное")) + "</a>";
	h += "</span>";
	h += "<div class='alsoInStream'>";
	h += "Похожие исполнители: ";
	for (i = 0; i < data.alikePerformers.length; i++) {
		h += "<a id='a" + i + "' href='/#performers/" + data.alikePerformers[i].id + "'>";
		h += "<img src='" + ((data.alikePerformers[i].isimage * 1 == 1) ? data.alikePerformers[i].image : "/media/images/streams/no_picture_55x55.jpg") + "' style='" + ((i == data.alikePerformers.length - 1) ? ("margin-right:0;") : ("")) + "'/>";
		h += "</a>";
	}
	h += '<div class="usersTooltip">';
	h += '<span class="cont">';
	h += '<span class="nick"></span>';
	h += '<span class="karma"></span>';
	h += '</span>';
	h += '<span class="tale"></span>';
	h += "</span>";
	h += "</div>";
	h += "</div>";
	h += "</div>";
	h += '</div>';
	h += '<br clear="all"/>';
	h += '<div id="performersLayout" style="margin-top:10px;width:630px;">';
	
	h += eval('performer' + data.subType + "_content(data)");
	
	h += '</div><br clear="All"/>';
	$('#leftContent').html(h);
	Set_Cookie('discographyBlock', 'hidden', '', '/', '', '');
	if (data.subType == '' || data.subType == 'tracks') {
		tracks = new performerTracks(((data.subType == '') ? ('top') : ('')), data.pTopTracks);
		tracks.show('.trackBlock', data.perfId, 'performer', 'purple');
	}
	
	if (data.subType == '') {
		discography = new discographyFuncs('', data.discography);
		discography.show('.discography', data.perfId, data.name);
		var rating = new ratingFuncs('performers', data.perfId, data.isVote, data.rate, data.isLogin, data.isFav);
		rating.show('.ratingBlock');
		comments = new commentsFuncs(1, data.perfId, '.comments', 'purple');
		comments.show(1);
		var tags = new tagFuncs(data.tags);
		tags.show('#tags', data.perfId, 1);
	}
	
	if (data.subType == 'fans') {
		var fav = new infavFuncs(data.fans);
		fav.show('.favBlock', data.perfId);
	}
	
	if (data.subType == 'alike') {
		$('#performersLayout a').hover(function(){
		});
		
		commonToolTip({
			obj: "#performersLayout",
			hoverObj: "a",
			data: data.alike,
			field1: "name",
			field2: "tracks_num",
			initLeft: $(".alsoInStream")[0].offsetLeft - 172,
			objectWidth: 57,
			initTop: -58,
			objectHeight: 59,
			perLine: 11,
			title: "Треков на сайте: ",
			invert:1
		});
		
	}
	
	if (data.isLogin != 0) {
		$('.inFav').bind('click', function(){
			if ($(this).hasClass('favDone')) {
				$.post('/performers/unfav/' + data.perfId, function(){
					$('.inFav').html('Добавить в избранное');
					$('.inFav').removeClass('favDone');
				});
			}
			else {
				$.post('/performers/fav/' + data.perfId, function(){
					$('.inFav').html('Убрать из избранного');
					$('.inFav').addClass('favDone');
				});
			}
		});
	}

	var full = 0;
	
	$('.viewAll').bind('click', function(){
		if(!full){
			if($('.infoText p')[0].offsetHeight + 50<283){
				return;
			}
			$('.infoText').css('height', $('.infoText p')[0].offsetHeight + 50 + 'px');
			$('.infoText .fadeOut').css('display', 'none');
			full = 1;
		} else{
			$('.infoText').css('height', '283px');
			$('.infoText .fadeOut').css('display', 'block');
			full = 0;
		}
	});
	
	$('.plLine .playlistPlay').bind("click", function(){
		load_track_in_player('/performers/getxml/' + data.perfId);
	});
	
	commonToolTip({
		obj : ".alsoInStream",
		hoverObj : "a",
		data : data.alikePerformers,
		field1 : "name",
		field2 : "tracks_num",
		initLeft : $(".alsoInStream")[0].offsetLeft - 42,
		objectWidth : 33,
		initTop : -38,
		objectHeight: 58,
		perLine : 10,
		title : "Треков на сайте: "
	});
	
	$('.editText').click(function(){
		var backup = $('#perfDescr').html();
		RbEditor1 = new RBEditor;
		RbEditor1.buttons =  [
						{name:"B",  cmd:"bold",                key:'b',  title:"Жирный"},
						{name:"I",  cmd:"italic",              key:'i',  title:"Курсив"},
						{name:"U",  cmd:"underline",           key:'u',  title:"Подчеркнутый"},
						{name:"S",  cmd:"StrikeThrough",       key:'0',  title:"Зачеркнутый"},
						{name:"OL", cmd:"insertorderedlist",   key:'',   title:"Упорядоченный список"}
						//,{name:"A",  cmd:"link",                key:'',   title:"Гиперссылка"}
					 ]; 
		RbEditor1.init('perfDescr');
		if(data.descr!='')
			RbEditor1.val(data.descr);
		h = "<a style='margin-top:5px;margin-right:10px;' href='javascript:;' class='saveText profileButton'>Сохранить</a>";
		h += "<a href='javascript:;' style='margin-top:5px;' class='cancelEdit profileButton'>Отмена</a>";
		$('#rbeditor').after(h);
		
		$('.cancelEdit').click(function(){
			$('#rbeditor').remove();
			$('#controlLayout').remove();
			$('.profileButton').remove();
			$('#perfDescr').show();
		});
		
		$('.saveText').click(function(){
			$.post('/performers/saveInfo', {
				id: data.perfId, 
				value : RbEditor1.val()
			}, function(dat){
				$('#rbeditor').remove();
				$('#controlLayout').remove();
				$('.profileButton').remove();
				$('#perfDescr p').html(((dat!=' ')?(dat):("<br/><br/><br/><br/>Биография исполнителя временно отсутствует.<br/><br/><a style='font-size:12px;' href='javascript:;' onclick='$(\".editText\").trigger(\"click\");'>Примите участие в развитии сайта.</a>")));
				data.descr = dat;
				$('#perfDescr').show();
			});
		});
		
	});
	
	
	var h =  ban240x400("<div class='topPerformers first'></div>");;
	
	/*h += "<div class='banner240x400'>";
	h += "<div class='topPerformers first'></div>";
	h += "<div class='bannerLayout'><img src='/media/images/240x400.jpg'/></div>";
	h += "</div>"*/
	h += "<br clear='All'/>";
	
	$('#dynamicRightContent').css('margin-top', "0px");
	$('#dynamicRightContent').html(h);
	
	var topPerformers = new topPerformersFuncs(data.topPerformers);
	topPerformers.show('#dynamicRightContent .banner240x400 .first', 0, 5);

}

function performer_content(data){
	var h = "";
	h = '<div id="perfDescr" class="infoText" style="height:283px;">';
	h += '<div class="photo"><img src="' + data.image + '"/>';
	if (data.isLogin) {
		h += '<span class="photoLinks">';
		h += '<form enctype="multipart/form-data" action="/performers/newimage/" method="post" id="imageForm">';
		h += '<input name="img" id="artistImage" onchange="change_image();" type="file" />';
		h += '<input name="pid" type="hidden" value="' + data.perfId + '"/>';
		h += '<input name="name" type="hidden" value="' + data.name + '"/>';
		h += '</form>';
		h += '<a href="javascript:;" class="changePhoto" style="float:none;">Изменить фотографию</a>';
		h += '</span>';
	}
	h += ((data.image_changed!='')?("Фото изменено " + data.image_changed.split(" ")[0] + ". <a class='tahomaNick' style='float:none;' href='/#users/" + data.image_changed.split(" ")[1] + "'>" + data.image_changed.split(" ")[1] + "</a>"):(""));
	h += '</div>';
	h += '<span class="performer-color user-size">БИОГРАФИЯ</span><p>' + ((data.descr!='')?(data.descr):("<br/><br/><br/><br/>Биография исполнителя временно отсутствует.<br/><br/><a style='font-size:12px;' href='javascript:;' onclick='$(\".editText\").trigger(\"click\");'>Примите участие в развитии сайта.</a>")) + '</p>';
	h += '<span class="fadeOut"></span>';
	h += '<div class="links">';
	h += '<a href="javascript:;" class="viewAll">Читать дальше</a>';
	if (data.isLogin != 0) {
		h += '<span style="float:left;margin:0 10px 0 20px;">|</span>';
		h += '<a href="javascript:;" class="editText">Редактировать текст</a>';
	}
	h += '</div>';
	h += '</div><br clear="All"/>';
	
	h += "<div class='plLine block'>";
	h += "<div class='plLayout'>";
	h += "<span class='playlistTitle' style='width:200px;'>";
	h += data.name.toUpperCase() + "</span>";
	h += "<span class='plMenu'>";
	h += "<span class='nTracks /*rightBorder*/'>" + data.tracks_num + "&nbsp;треков</span>";
//	h += "<a href='javascript:;' class='nTracks " + ((data.isLogin)?("rightBorder"):("")) + "'>просмотреть</a>";
//	h += ((data.isLogin)?("<a href='javascript:;'>добавить в мои плейлисты</a>"):(""));
	h += "</span>";
	h += "</div>";
	h += "<a href='javascript:;' class='playlistPlay'></a>"
	h += "</div><br clear='All'/>";
	
	h += '<div class="trackBlock top block" style="margin-top:20px;"></div><br clear="All"/>';
	h += '<div class="discography block" style="margin-top:15px;"></div>';
	h += '<br clear="all" />';
	h += '<div id="tags" class="block"></div>';
	h += '<br clear="all" />';
	h += '<br clear="All"/><div class="ratingBlock block"></div>';
	h += '<br clear="all" />';
	h += '<div class="comments block"></div>';
	return h;
}

function performertracks_content(data){
	var h = '';
	h += '<div id="performerSongs">';
	h += '<div class="trackBlock block"></div><br clear="All"/>';
	h += '</div>';
	return h;
}

function performerbio_content(data){
	var h = '<div class="infoText">';
	h += '<span class="performer-color user-size"></span><p style="margin-bottom:50px;">' + ((data.descr!='')?(data.descr):("<br/><br/><br/><br/>Биография исполнителя временно отсутствует.<br/><br/><a style='font-size:12px;' href='javascript:;'>Примите участие в развитии сайта.</a>")) + '</p>';
	h += '<div class="links">';
	if (data.isLogin != 0) {
		//h += '<a onclick="edit_artist_bio()" href="javascript:;" class="editText">Редактировать текст</a>';
	}
	h += '</div>';
	h += '</div><br clear="All"/>';
	return h;
}

function performerevents_content(data){
	var h = '';
	h += 'Хуй знает!';
	return h;
}

function performerfans_content(data){
	var h = '';
	h += '<div class="favBlock"></div>';
	return h;
}

function performeralike_content(data){
	var h = '';
	for(i=0;i<data.alike.length;i++){
		h += "<a id='a" + i + "' href='/#performers/" + data.alike[i].id + "'>";
		h += "<img src='" + ((data.alike[i].isimage * 1 == 1) ? data.alike[i].image : "/media/images/streams/no_picture_55x55.jpg") + "' style='margin-bottom:4px;" + ((i == data.alike.length - 1) ? ("margin-right:0;") : ("margin-right:2px;")) + "'/>";
		h += "</a>";
	}
	return h;
}

function performervideos_content(data){
	var h = '';
	var search_link = "http://gdata.youtube.com/feeds/api/videos?alt=json-in-script&vq=";
	$.getScript(search_link + data.name + "&callback=showVideos");
	h += info({title:"Список клипов генерируется автоматически. Поэтому возможны промахи с содержанием."});
	if(data.videoId){
		h += '<object style="margin-top:20px;" width="632" height="386"><param name="movie" value="http://www.youtube.com/v/'+data.videoId+'&hl=ru_RU&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  style="margin-top:20px;" src="http://www.youtube.com/v/'+data.videoId+'&hl=ru_RU&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="632" height="386"></embed></object>';
	}
	h += '<br clear="All"/>';
	h += '<div id="videos" class="block" style="' + ((data.videoId)?('top:29px;'):('top:20px;')) + '">';
	var title = "<span style='cursor:pointer;text-align:left;' class='blockTitle performer-color'>";
	title += "<span class='minimizeArrow'></span>";
	title += "остальные <a href='javascript:;'>КЛИПЫ</a>";
	title += " <span class='titleTip'></span>";
	title += "</span><br clear='All'/>";
	
	h += ((data.videoId)?(title):(''));
	h += '</div><br clear="All"/>';
	return h;
}

function showVideos(data){
	var h = '';
	var feed = data.feed;
	var entries = feed.entry || [];
	for (var i = 0; i < entries.length; i++) {
		var entry = entries[i];
		var title = entry.title.$t;
		var id = entry.id.$t.replace("http://gdata.youtube.com/feeds/api/videos/", "");
		h += "<div title='" + title + "' id='" + id + "' style='" + ((i<entries.length-1)?(""):("margin-right:0;")) + "' >";
		h += "<img src='" + entry.media$group.media$thumbnail[0].url + "'/>";
		h += "<a class='vid' href='javascript:;'></a>";
		h += "<span>" + title + "</span>";
		h += "</div>";
	}
	$('#videos').append(h);
	
	$("#videos div").click(function(){
		location.hash = 'performers/' + location.hash.split('/')[1] + '/videos/' + this.id;
	});

	h = ((entries.length>5)?(" (показаны 5 из " + entries.length + ")"):(""));
	$('#videos .titleTip').html(h);
	var full = 1;
	
	var fullHeight = (Math.round(entries.length/5)*183 + 32) + "px";
	
	if ($('#videos .blockTitle')[0]) {
		if (Get_Cookie('performerVideosBlock') == 'hidden') {
			$('#videos').css('height', '210px');
			full = 0;
		}
		else {
			$("#videos .minimizeArrow").addClass('maximized');
			$("#videos .titleTip").hide();
		}
	}
	
	if (entries.length > 5) {
		$('#videos .blockTitle').bind("click", function(){
			var height;
			if (!full) {
				height = fullHeight;
				full = 1;
				Set_Cookie('performerVideosBlock', 'shown', '', '/', '', '');
				$("#videos .titleTip").hide();
				$("#videos .minimizeArrow").addClass('maximized');
			}
			else {
				height = '210px';
				full = 0;
				Set_Cookie('performerVideosBlock', 'hidden', '', '/', '', '');
				$("#videos .titleTip").show();
				$("#videos .minimizeArrow").removeClass('maximized');
			}
			$('#videos').animate({
				height: height
			});
		});
	}
	
} 

function change_image() 
{
	$("#imageForm").ajaxSubmit(
	   {
			beforeSubmit:  function(){
				tmp = $("#performersLayout .photoLinks").html();
				$("#performersLayout .photoLinks a").replaceWith('<img style="float:none;" src="/media/images/beta-pics/loaders/universal_loader_03.gif"/>');
			},
			dataType:  'xml',
       		success:       function(data){
				var im = new Image;
				if ($('error val', data).text() == 0) {
					im.src = $('src', data).text();
					$("#performersLayout .photo img").replaceWith(im);
					$("#performersLayout .photoLinks").html(tmp);
				}else {
					alert($('error val', data).text());
				}
			}
		}
	);
}

function performerTracks (type, data){
	this.obj = 0;
	this.nNews = 0;
	this.jSData = 0;
	this.headerWidth = 0;
	this.height = 0;
	this.style = 0;
	this.color = 0;
	this.type = ((!type||type=='')?(''):(type));
	((data)?(this.jSData = data):(this.jSData = 0));
}

performerTracks.prototype = {

	refresh:		function(id){
							var t = this;
							$.post('/performers/get_' + t.type + 'tracks/' + id, {
							}, function(data){
								t.jSData = data;
								t.show();								
							});							
					},
	show:			function(obj, id, style, color){
						var t=this;
						if (!t.style){
							this.style = style;
						}
						if (!t.color){
							this.color = color;
						}						
						if (!t.obj) {
							this.obj = obj;
						}
						if(!t.jSData){
							t.refresh(id);
							return;
						}
							
						var data = t.jSData;
						var h = '';
						h += "<div style='float:left;'>";
						var sumRates = 0;
						var mult = ((t.type=='top')?(0):(1));
					    for (i = 0; i < t.jSData.length; i++) {
							h += generateTrackLine({
								element : 'div',
								addClass : '',
								id : '',
								trackId : t.jSData[i].id,
								performerId : t.jSData[i].performer_id,
								trackLength : t.jSData[i].length,
								performer : t.jSData[i].performer,
								title : t.jSData[i].name,
								ownerNick : 1,
								color : this.color,
								tooltipLen : 15,
								columns : 2,
								even:i%2*mult
							});
							sumRates = ((t.jSData[i].rate*1>sumRates*1)?(t.jSData[i].rate*1):(sumRates*1));
					    }
						h += "</div>";
						if (t.type == 'top') {
							h += "<div class='voices'>";
							for (i = 0; i < t.jSData.length; i++) {
								h += "<span class='voice' style='" + ((i == 0) ? ("margin-top:3px;") : ("")) + "'>" + t.jSData[i].rate;
								h += "<span style='width:" + (t.jSData[i].rate * 100) / sumRates + "%;' class='percents'></span>";
								h += "</span><br clear='All'/>";
							}
							h += "</div>";
						}
						$(t.obj).html(h);

						
					    $('a.playButton').bind("click", function(){
							sendTrackToPlayer(this, t.color);								
					    });
					    $('a.plusButton').bind("click", function(){
							pPopup.openWnd(this);
					    });						
					}
}

function discographyFuncs (preTitle, data){
	this.obj = 0;
	this.nNews = 0;
	this.jSData = 0;
	this.performer = 0;
	this.isFav = 0;
	this.preTitle = preTitle;
	if(data){
		this.jSData = data;
	}
}

discographyFuncs.prototype = {

	refresh:		function(id){
						var t = this;
						$.post('/performers/albums/' + id, function(data){
					        data = data;
							t.jSData = data;
							t.show();
						});
					},
	show:			function(obj, id, perfName){
						var full=1;
						if(!this.performer)
							this.performer = perfName;
						var t=this;
						if (!t.obj) {
							this.obj = obj;
						}
						if (!t.jSData) {
							t.refresh(id);
							return;
						}
						var data = t.jSData;
						var h = '';
						h += "<span style='cursor:pointer;' class='blockTitle performer-color'>";
						h += ((data.length>3)?("<span class='minimizeArrow'></span>"):(""));
						h += t.preTitle + " ";
						h += "<a href='javascript:;'>АЛЬБОМЫ</a>";
						h += ((data.length>3)?(" <span class='titleTip'>(показаны 3 из " + data.length + ")</span>"):(""));
						h += "</span>";
						
						for(i=0;i<data.length;i++){
							if((i+1)%3==0)
								h += '<div class="album" style="margin-right:0;">';
							else
								h += '<div class="album">';
							h += '<table valign="center" style="font-size:8pt;"><tr><td style="font-size:8pt;">';							
							h += '<a href="/#albums/' + data[i].id + '" class="albumPicture"><img src="' + data[i].cover + '"/><div class="albumCover"></div></a>';
							h += '</td><td style="font-size:8pt;">';
							h += '<p><strong><a href="/#albums/' + data[i].id + '" style="text-decoration:none;">'+data[i].name +"</a></strong><br/><span class='performer-bg' style='padding-left:1px;bottom:2px;'>" + this.performer + '</span><br/>' + ((data[i].year!=0)?('<span>Год: ' + data[i].year):('')) + '</span></p>';
							h += '</td></tr></table>';
							h += '</div>';
						}
		
						h += '<br clear="all"/>';						
						$(t.obj).html(h);
						var fullHeight = ($(t.obj)[0].offsetHeight + 5) + 'px';
						
						$(t.obj).height(fullHeight);
						
						if (Get_Cookie('discographyBlock') == 'hidden') {
							$(t.obj).css('height', '105px');
							full = 0;
						}
						if (data.length > 3) {
							$(t.obj + ' .blockTitle').bind("click", function(){
								var height;
								if (!full) {
									height = fullHeight;
									full = 1;
									Set_Cookie('discographyBlock', 'shown', '', '/', '', '');
									$(t.obj + " .titleTip").hide();
									$(t.obj + " .minimizeArrow").addClass('maximized');
								}
								else {
									height = '105px';
									full = 0;
									Set_Cookie('discographyBlock', 'hidden', '', '/', '', '');
									$(t.obj + " .titleTip").show();
									$(t.obj + " .minimizeArrow").removeClass('maximized');
								}
								$(t.obj).animate({
									height: height
								});
							});
						}
					}
}

function infavFuncs (data){
	this.obj = 0;
	this.nNews = 0;
	this.jSData = 0;
	this.func = 0;
	if(data)
		this.jSData = data;
}

infavFuncs.prototype = {

	refresh: function(id){
		var t = this;
		$.post('/performers/fav_users/' + id, function(data){
			data = data;
			t.jSData = data;
			t.show();
		});
	},
	show: function(obj, id){
		var t = this;
		if (!t.obj) {
			this.obj = obj;
		}
		if (!t.jSData) {
			t.refresh(id);
			return;
		}
		var data = t.jSData;
		var h = '';
	//	h += '<div id="performersLayout" style="margin:0px;">';
		/*h += "<br clear='All'/>";
		for (i = 0; i < data.length; i++) {
			h += '<a class="uLink" id="u' + i + '" href="/#users/' + data[i].nick + '" style="margin-right:4px;margin-bottom:4px;float:left;width:55px;height:55px;display:block;"><img src="' + data[i].avatar.replace('.jpg', '_55x55.jpg') + '"/></a>';
		}*/
		
		half = 0;
		if (data.length > 3){
			half = Math.round(data.length/2);
			h += '<div class="col col1" style="margin-top:0px;">';
			for(i=0; i<half; i++){
				h += '<div class="item favitem">';
				h += '<table class="infavtable">';
				h += '<tr>';
				h += '<td rowspan="2" class="userimglike"><img width="25px" src="' + data[i].avatar.replace('.jpg', '_55x55.jpg') + '"/></td>';
				h += '<td><a  class="usernicklike" href="/#users/' + data[i].nick + '">' +data[i].nick + '</a></td>';
				h += '</tr>';
				h += '<tr>';
				h += '<td><div class="userlike">Любит:';
				if (data[i].fav_music.length != 0) {
					h += data[i].fav_music;
				}else{
					h += 'не указано';
				}
				h += '<div class="gradientperf"></div></div></td>';
				h += '</tr>';
				h += '</table>';
				h += '</div>';
			}
			h += '</div>';
		}
		h += '<div class="col"  style="margin-top:0px;">';
		for(i=half; i<data.length; i++){
			h += '<div class="item  favitem">';
				h += '<table>';
				h += '<tr>';
				h += '<td rowspan="2" class="userimglike"><img width="25px" src="' + data[i].avatar.replace('.jpg', '_55x55.jpg') + '"/></td>';
				h += '<td><a  class="usernicklike" href="/#users/' + data[i].nick + '">' +data[i].nick + '</a></td>';
				h += '</tr>';
				h += '<tr>';
				h += '<td><div class="userlike">Любит:';
				if (data[i].fav_music.length != 0) {
					h += data[i].fav_music;
				}else{
					h += 'не указано';
				}
				h += '<div class="gradientperf"></div></div></td>';
				h += '</tr>';
				h += '</table>'
				h += '</div>';		
		}
	//	h += '</div>';
		h += '</div>';
		
		h += '<div class="usersTooltip">';
		h += '<span class="cont">';
		h += '<span class="nick"></span>';
		h += '<span class="karma"></span>';
		h += '</span>';
		h += '<span class="tale lefter"></span></div>';
		h += "</span>";
		h += "</div>";
		
		h += '<br clear="all"/><br/>';
		$(t.obj).html(h);
		
		$(t.obj + ' a.uLink').bind("mouseover", function(){
			id = this.id.substr(1, this.id.length);
			$(t.obj + ' .usersTooltip .nick').html(data[id].nick + "<span class='fader'></span>");
			h = "Карма: " + data[id].karma;
			$(t.obj + ' .usersTooltip .karma').html(h);
			offs = this.parentNode.offsetLeft + 10 + 59 * (id%10);
			$(t.obj + ' .usersTooltip').css("left", offs + "px");
			
			offs = this.offsetTop - 55;
			$(t.obj + ' .usersTooltip').css("top", offs + "px");
			$(t.obj + ' .usersTooltip').css("display", "block");

		});
		
		$(t.obj + ' a.uLink').bind("mouseout", function(){
			$(t.obj + ' .usersTooltip').css("display", "none");
		});
		
		
	}
}

function tagFuncs (data){
	this.obj = 0;
	this.jSData = 0;
	this.id = 0;
	this.type = 0;
	if(data){
		this.jSData = data;
	}
}

tagFuncs.prototype = {

	refresh:		function(){
						var t = this;
						$.post('/tags/get_tags/', {
								id: this.id,
								type: t.type
							}, function(data){
							t.jSData = data;
							t.show();								
						});
					},
	show:			function(obj, id, type){
						var t=this;
						if (!t.obj) {
							this.obj = obj;
						}
						if (!t.id) {
							this.id = id;
						}
						if(!t.type){
							t.type = type;
						}
						if (!t.jSData) {
							t.refresh();
							return;
						}
						var data = t.jSData;
						var h = '';
						isLogin = $('.logoutLink')[0];
						h += "<span class='blockTitle'>";
						h += "популярные ";
						h += "<a href='javascript:;' style='margin-right:15px;'>ТЕГИ</a>";
						
						if(data.length == 0){
							switch(t.type*1){
								case 1:	h += 'Данный исполнитель пока не отмечен тегами.';
										break;
								case 2:	h += 'Данный альбом пока не отмечен тегами.';
										break;
								case 3:	h += 'Данный трек пока не отмечен тегами.';
										break;
								case 4:	h += 'Данная статья пока не отмечена тегами.';
										break;
							}
						}
						
						for(i=0;i<data.length;i++){
							h += '<a class="tagLink" href="/#search/' + data[i].tag + '">' + data[i].tag + '</a>';
							if(i<data.length-1)
								h += ',&nbsp;';
						}
												
						h += "<span class='fadeOut'></span>";
						h += "</span>";
						if (isLogin) {
							h += "<span class='cont' style='display:none;float:left;'>";
							h += "<input type='text' id='tagInput'/>";
							h += "<a href='javascript:;' style='margin-top:0px;margin-left:-2px;float:left;' class='profileButton artistAddTag'>Добавить теги</a>";
							h += "<span class='howToWork' style='left:0;margin-left:5px;float:left;width:395px;height:26px;position:relative;'><span class='cnt' style='background-color:#303030;display:block;height:21px;width:395px;'><span class='i-icon'></span><span style='margin-top:4px;width:380px;float:left;'>Добавляйте новые теги через запятую, например: rock, pop-punk, retro</span></span><span class='tale'></span></span>";
							h += "</span>";
							h += "<a style='margin-top:0px;' class='cont profileButton toggle' href='javascript:;'>Добавить теги</a>";
						}
						h += "<br style='margin-bottom:10px;clear:both;'/>";
						h += "<div id='tagLinks'>";

						h += '</div>';						
						h += '<br clear="all"/><br/>';	
						$(t.obj).html(h);
						$(t.obj + ' a.toggle').bind('click', function(){
							$('#tags input').val('');
							$(this).parent().find('.cont').toggle();
							$('#tags input').focus();
							$('.artistAddTag').unbind('click');
							$('.artistAddTag').bind('click', function(){
								var tags = $('#tags input').val();
								if (tags == '') {
									return;
								}
								tags = tags.split(',');
								var jSTags = '';
								jSTags = '[';
								for(i=0;i<tags.length;i++){
									jSTags += '{"tag" : "' + tags[i] + '"}';
									if(i<tags.length-1)
										jSTags += ',';
								}
								jSTags += ']';
								$.post('/tags/add_tags/', {
									id : t.id,
									type : t.type,
									tags: jSTags
								}, function(){
									$('#tags .cont').toggle();
									t.refresh(t.id);
								});
							});
						});
						
						$('#tagInput').bind('keydown', function(ev){
							if(ev.keyCode==13){
								$('.artistAddTag').trigger('click');
							}
						});
					}
}

function alertTag(str){
	$('#search .query').val(str);
	$('#search .submit').trigger('click');
}

var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

function userFavFuncs (data){
	this.obj = 0;
	this.nNews = 0;
	this.jSData = 0;
	this.func = 0;
	if(data)
		this.jSData = data;
}

userFavFuncs.prototype = {

	refresh:		function(){
						var t = this;
						$.post('/user/fav_performers/', function(data){
							t.jSData = data;
							t.show();								
						});
					},
	show:			function(obj){
						var t=this;
						if (!t.obj) {
							this.obj = obj;
						}
						if (!t.jSData) {
							t.refresh();
							return;
						}
						var data = t.jSData;
						if(data.length == 0){
							$(t.obj).remove();
							return;
						}
						var h = '';
					    h += "<span class='performer-bg' style='cursor:pointer;font-size:10pt;padding-left:2px;'><span class='arrow ar-c0' style='width:14px;'></span>Любимые исполнители:</span>&nbsp;&nbsp;&nbsp;";
						h += "<div style='height:15px;clear:both;'></div>";
						for(i=0;i<data.length;i++){
							h += '<a href="/#performers/' + data[i].id + '">' + data[i].name + '</a>';
							if(i<data.length-1)
								h += ', ';
						}
						h += '<br clear="all"/><br/>';						
						$(t.obj).html(h);
						var full = 0;
						fullHeight = $('#favPerformers')[0].offsetHeight;
						$('#favPerformers').css('height', '45px');
						if (Get_Cookie('favperformers') != 'hidden') {
							$('#favPerformers').css('height', fullHeight);							
							$("#favPerformers .arrow").addClass('ar-ccc0');
							full = 1;
						}
						$('#favPerformers .performer-bg').bind("click", function(){
							var height;
							if(!full){
								$("#favPerformers .arrow").addClass('ar-ccc0');
								height = fullHeight;
								full = 1;
								Set_Cookie( 'favperformers', 'shown', '', '/', '', '' );								
							} else{
								$("#favPerformers .arrow").removeClass('ar-ccc0');
								height = '45px';
								full = 0;
								Set_Cookie( 'favperformers', 'hidden', '', '/', '', '' );																
							}
							$(t.obj).animate({
								height: height
							});							
						});
					}
}