function product_rating_tabs_init()
{
	//Default
	var params = {};
	params.type = 'rating';
	$.post('/grade/productrating/', params, product_rating_tabs_callback, 'json');
}
function item_swither(link_id, type)
{
	var type = '';
	if($(link_id).text() == 'новые'){
		$('#sw1').html('<b>новые</b>');
		$('#sw2').html('<a class="blue_ajax_span" onclick="item_swither(this);">популярные</a>');
		type = 'new';
	}else{
		$('#sw1').html('<a class="blue_ajax_span" onclick="item_swither(this);">новые</a>');
		$('#sw2').html('<b>популярные</b>');
		type = 'rating';
	}
	var params = {};
	params.type = type;
	$.post('/grade/productrating/', params, product_rating_tabs_callback, 'json');
}

function product_rating_tabs_callback(obj)
{
	var html = (obj.p.length > 0) ? '' : '<p class="none">Список вещей пуст</p>';
	html += '<div style="clear: both">';
	for (i = 0; i < obj.p.length; i++) {
		
		html += '<div class="status-col">';
		html += '<div class="status-col-in">';
		if(obj.p[i] && obj.p[i] != ''){
			html += '<div class="status-photo">';
			html += '<a href="' + obj.p[i].url + '">';
			if (obj.p[i].photo != '') {
				html += '<img src="' + obj.p[i].photo + '" width="98" height="98" alt="' + obj.p[i].name + '" />';
			} else {
				html += '<img src="/blogpic/default.jpg" width="98" height="98" alt="" />';
			}
			html += '</a>';
			html += '</div>';
			html += '<div class="status-name"><a href="' + obj.p[i].url + '" title="' + obj.p[i].name + '">' + obj.p[i].name + '</a><div class="transp">&nbsp;</div></div>';
			if (obj.p[i].avg_rating != 0) {
				html += '<div class="status-rating">';
				html += 'Рейтинг:&nbsp;<span class="strong maroon">' + obj.p[i].avg_rating + '</span> (<img src="/i/user-vote.gif" width="11" height="11" alt="" /><span class="strong black">' + obj.p[i].count_voters + '</span>)';
				html += '</div>';
				html += '</div>';
			} else {
				html += '<p class="none">Оценок нет</p>';
			}
		}else{
		
			html+='&nbsp;';
		}
		html += '</div>';
		html += '</div>';
		
	}
	html += '</div>';
	
	
	html += '<div style="clear: both">';
	for (i = 0; i < obj.p.length; i++) {
	html += '<div class="status-col">';
	html += '<div class="status-col-in">';
	if(obj.p[i].comments && obj.p[i].comments != ""){
			for(var j =0;j <obj.p[i].comments.length;j++){
				html +='<dl class="comments-last"><dt><a href="/user/'+ obj.p[i].comments[j]['user_nick'] +'/">'+ obj.p[i].comments[j].user_nick +'</a></dt><dd>'+ obj.p[i].comments[j].text +'&nbsp;<a href="' + obj.p[i].url + '#comment' + obj.p[i].comments[j].id + '" class="blue">...</a></dd></dl>';
			}
	}else{
		html += '&nbsp;';
	}
	html += '</div>';
	html += '</div>';
	}
	html += '</div>';
	//$('#dataProduct').html(html);
	document.getElementById('dataProduct').innerHTML = html;
}
