	legend = new Array(null, 'Awful', 'Poor', 'Average', 'Good', 'Excellent');

	function params(user_id, video_id, estimate)
	{
		ret = new Object;
		ret.user_id = user_id;
		ret.video_id = video_id;
		ret.estimate = estimate;

		return ret;
	}

	function doLoad(force, cach, type, data)
	{
		var req = new Subsys_JsHttpRequest_Js();

		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.responseJS) {
					switch (type) {
						case 'rating':
							updateRating(req.responseJS);
							break;
						case 'image_rating':
							updateImageRating(req.responseJS);
							break;
						case 'playlist':
							updatePlaylist(req.responseJS);
							break;
						case 'media_scroll':
							if (req.responseJS.direct == 0) {
								eval('page_html_' + req.responseJS.postfix)[req.responseJS.page] = req.responseJS.html;
							} else {
								document.getElementById("loading_indicator_" + req.responseJS.postfix).style.display = "none";
								if (req.responseJS.html != '') {
									eval('move_box_' + req.responseJS.postfix)(req.responseJS.direct, 0, req.responseJS.html);
								} else {
									alert('Can\'t move in this direction');
									busy = false;
								}
							}
							break;
						default:
							alert('Unknown action');
							break;
					}
				}
//				alert(req.responseText);
			}
		}

		req.caching = cach;
		req.open('POST', '/load.php', true);
		req.send({ id: data, act: type });
	}

	function updatePlaylist(response)
	{
		var html = '';

		html += '<a href="" onClick="doLoad(true, false, \'playlist\', \'' + response.user + (response.result == 1 ? '-' : '+') + response.media + '\'); return false;">' + (response.result == 1 ? 'Delete from' : 'Add to') + ' playlist</a>';

		for(var key in media[response.media]) {
			document.getElementById(media[response.media][key]).innerHTML = html;
		}
	}

	function updateImageRating(response)
	{
//		DEBUG
//		var str = '';
//		for(var key in response) {
//			str += key + ' = ' + response[key] + '\n';
//		}
//		alert(str);

		var html = '';

		for (i = 1; i <= 5; i++) {
			if (response.estimate > 0) {
				if ((i - 0.5) < response.estimate) {
					html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_a.gif" width="15" height="14" border="0" />';
				}else{
					html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_w.gif" width="15" height="14" border="0" />';
				}
			}else{
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_no.gif" width="15" height="14" border="0" />';
			}
		}

		html += '<br />Average rating (' + response.voices + ')<br />';

		for (i = 1; i <= 5; i++) {
			if ((i - 0.5) < response.voiced) {
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_y.gif" width="15" height="14" border="0" id="star_' + response.video_id + '_' + i + '" onMouseOver="raitingRoll(' + i + ', ' + response.video_id + ')" onMouseOut="raitingRoll(\'back\', ' + response.video_id + ')" style="cursor: hand;" onClick="doLoad(true, false, \'image_rating\', params(' + response.user_id + ', ' + response.video_id + ', ' + i + '));" />';
			}else{
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_w.gif" width="15" height="14" border="0" id="star_' + response.video_id + '_' + i + '" onMouseOver="raitingRoll(' + i + ', ' + response.video_id + ')" onMouseOut="raitingRoll(\'back\', ' + response.video_id + ')" style="cursor: hand;" onClick="doLoad(true, false, \'image_rating\', params(' + response.user_id + ', ' + response.video_id + ', ' + i + '));" />';
			}
		}

		html += '<span style="margin: 10px;" id="ratingEstimate_' + response.video_id + '">' + legend[response.voiced] + '</span>';

		document.getElementById('voice_box_' + response.video_id).innerHTML = html;
	}

	function updateRating(response)
	{
//		DEBUG
//		var str = '';
//		for(var key in response) {
//			str += key + ' = ' + response[key] + '\n';
//		}
//		alert(str);

		var html = '';

		for (i = 1; i <= 5; i++) {
			if (response.estimate > 0) {
				if ((i - 0.5) < response.estimate) {
					html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_a.gif" width="15" height="14" border="0" />';
				}else{
					html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_w.gif" width="15" height="14" border="0" />';
				}
			}else{
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_no.gif" width="15" height="14" border="0" />';
			}
		}

		html += '<br />Average rating (' + response.voices + ')<br />';

		for (i = 1; i <= 5; i++) {
			if ((i - 0.5) < response.voiced) {
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_y.gif" width="15" height="14" border="0" id="star_' + response.video_id + '_' + i + '" onMouseOver="raitingRoll(' + i + ', ' + response.video_id + ')" onMouseOut="raitingRoll(\'back\', ' + response.video_id + ')" style="cursor: hand;" onClick="doLoad(true, false, \'rating\', params(' + response.user_id + ', ' + response.video_id + ', ' + i + '));" />';
			}else{
				html += '<img src="http://panjea.vo.llnwd.net/o10/pics/star_w.gif" width="15" height="14" border="0" id="star_' + response.video_id + '_' + i + '" onMouseOver="raitingRoll(' + i + ', ' + response.video_id + ')" onMouseOut="raitingRoll(\'back\', ' + response.video_id + ')" style="cursor: hand;" onClick="doLoad(true, false, \'rating\', params(' + response.user_id + ', ' + response.video_id + ', ' + i + '));" />';
			}
		}

		html += '<span style="margin: 10px;" id="ratingEstimate_' + response.video_id + '">' + legend[response.voiced] + '</span>';

		document.getElementById('voice_box_' + response.video_id).innerHTML = html;
	}

	function raitingRoll(n, item)
	{
		if (n == 'back') {
			for (var i = 1; i <= 5; i++) {
				document.getElementById('star_' + item + '_' + i).src = star[i];
			}
			document.getElementById('ratingEstimate_' + item).innerText = star['text'];
			star = new Array;
		} else {
			star = new Array;
			for (var i = 1; i <= 5; i++) {
				star[i] = document.getElementById('star_' + item + '_' + i).src;
			}
			star['text'] = document.getElementById('ratingEstimate_' + item).outerText;
			document.getElementById('ratingEstimate_' + item).innerText = legend[n];
			for (var i = 1; i <= 5; i++) {
				if (i <= n) {
					document.getElementById('star_' + item + '_' + i).src = 'http://panjea.vo.llnwd.net/o10/pics/star_y.gif';
				} else {
					document.getElementById('star_' + item + '_' + i).src = 'http://panjea.vo.llnwd.net/o10/pics/star_w.gif';
				}
			}
		}
	}