
function changePage(base, page)
{
	window.location.href = base + page.options[page.selectedIndex].value;
}

function rt_show_playlists(p)
{
	if (p.length > 0)
	{
		var odd = false;
		for(var i = 0; i < p.length; i++)
		{
			if (p[i].id != currentCategory)
				document.write('<a class="' + (odd?'odd':'even') + '" href="/video/index/category/' + p[i].id + '">' + p[i].name + '</a>');
			else
				document.write('<a class="current ' + (odd?'odd':'even') + '">' + p[i].name + '</a>');
			odd = !odd;
		}
	}
}

function rt_show_movies(t, p)
{
	var pager = '';
	var prev = '';
	var next = '';
	var begin = '';
	var end = '';
	var start = 0;
	var stop = 0;
	var pages = '';
	var select = '';
	if (p.numberOfPages > 1)
	{
		if (p.currentPage > 0)
		{
			prev = '<a href="' + base + (p.currentPage - 1) + '" class="underlined">предыдущая</a>';
		} else {
			prev = '';
		}
		if (p.currentPage < p.numberOfPages - 1)
		{
			next = ' <a href="' + base + (p.currentPage + 1) + '" class="underlined">следующая</a>';
		} else {
			next = '';
		}
		if ((p.currentPage > 3) && (p.numberOfPages > 7))
		{
			begin = '<a href="' + base + '1">1</a> ...';
		} else {
			begin = '';
		}
		if ((p.currentPage < p.numberOfPages - 4) && (p.numberOfPages > 7))
		{
			end = ' ... <a href="' + base + (p.numberOfPages - 1) + '">' + p.numberOfPages + '</a>';
		} else {
			end = '';
		}
		if (p.numberOfPages < 8)
		{
			start = 1;
			stop = p.numberOfPages;
		} else {
			start = p.currentPage - 1;
			stop = p.currentPage + 3;
			if (stop > p.numberOfPages - 2)
			{
				start = p.numberOfPages - 5;
				stop = p.numberOfPages;
			} else if (start < 3) {
				start = 1;
				stop = 5;
			}
		}
		for (var i = start; i <= stop; i++)
		{
			pages += ' <a href="' + base + (i - 1) + '"' + (((i - 1) == p.currentPage)?' class="current"':'') + '>' + i + '</a>';
		}
		select = '';
		for (var i = 1; i <= p.numberOfPages; i++)
		{
			select += '<option value="' + (i - 1) + '"' + (((i - 1) == p.currentPage)?' selected="selected"':'') + '>' + i + '</option>';
		}
		pager = '<div class="pages">' + prev + begin + pages + end + next +
							'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;перейти к ' +
							'<select onchange="changePage(\'' + base + '\', this)">' + select + '</select>' +
							' странице' +
						'</div>';
	}
	if (t.length > 0)
	{
		for(var i = 0; i < t.length; i++)
		{
			var link = '/video/show/id/' + t[i].movieLink.substr(13);
			document.write(
				'<div class="previewBlock">' +
					'<div class="thumb">' +
						'<img src="' + t[i].thumbnailMediumLink + '" alt="" />' +
						'<a href="' + link + '"></a>' +
					'</div>' +
					'<a class="title" href="'  + link + '">' + t[i].title + '</a>' +
					'дата: <span class="date">' + t[i].recordDate + '</span><br />' +
					'длительность: <span class="duration">' + t[i].duration + '</span><br />' +
					'комментариев: <a class="comments" href="' + link + '">' + t[i].numberOfComments + '</a><br />' +
				'</div>'
			);
		}
	} else {
			document.write('<div class="noMovies">Видеоролики отсутствуют</div>');
	}
	if (p.numberOfPages > 1)
	{
		document.write(pager);
	}
}

function rt_show_movie(t)
{
	var out = '<div class="movieWindow">' + t.playerCode + '</div>' +
						'<div class="movieInfo">' +
							'<div class="title">' + t.title + '</div>' +
							'дата: <span class="date">' + t.recordDate + '</span><br />' +
							'длительность: <span class="date">' + t.duration + '</span><br />' +
						'</div>' +
						'<h2>Комментарии <span class="counter">(' + t.numberOfComments + ')</span></h2>';
	document.write(out);
}

function rt_show_comments(c)
{
	if (c.length > 0)
	{
		for(var i = 0; i < c.length; i++)
		{
			if (c[i].deleted == 1)
			{
				continue;
			}
			if (c[i].author == 'stomport')
			{
				var txt = c[i].text.split("<BR><BR>");
				var author = txt.shift();
				var author = author.substr(6);
				var comment = txt.join("<BR><BR>");
				document.write('<div class="comment"><div class="date">' + c[i].date + '</div><div class="author">' + author + '</div>' + comment + '</div>');
			} else {
				document.write('<div class="comment"><div class="date">' + c[i].date + '</div><div class="author">Комментарий пользователя RuTube</div>' + c[i].text + '</div>');
			}
		}
	}
}


