// VAriablen
var ratings_max = "5";
var post_id = 0;
var post_rating = 0;
var last_rated_position_id = 0;


// OnMouseOver fürs RAting
function rating_onmouseover(id, rating, rating_text) {
	post_id = id;
	post_rating = rating;
	for(i = 1; i <= rating; i++) {
		document.images['rating_' + post_id + '_' + i].src = 'pics/star_green.gif';
	}
	if(document.getElementById('ratings_' + post_id + '_text')) {
		document.getElementById('ratings_' + post_id + '_text').style.display = 'inline';
		document.getElementById('ratings_' + post_id + '_text').innerHTML = rating_text;
	}
}


// OnMouseOut für Rating.
function rating_onmouseout(rating_value) {
	if(last_rated_position_id != post_id) {
		for(i = 1; i <= ratings_max; i++) {
			if(i <= rating_value) {
				document.images['rating_' + post_id + '_' + i].src = 'pics/star_full.gif';
			} else if(rating_value-i+1 >= 0.5 && rating_value-i < 1) {
				document.images['rating_' + post_id + '_' + i].src = 'pics/star_half.gif';
			} else {
				document.images['rating_' + post_id + '_' + i].src = 'pics/star_empty.gif';
			}
		}

		if(document.getElementById('ratings_' + post_id + '_text')) {
			document.getElementById('ratings_' + post_id + '_text').style.display = 'none';
			document.getElementById('ratings_' + post_id + '_text').innerHTML = '';
		}
	}
}


// Rating durchführen.
function rating_doit(positionId, rating, text) {
	var query = "positionId="+positionId+"&rating="+rating;
	Ajax.Request('GET', 'updateRatingAjax.do', query, rating_onresponse);	

	if(document.getElementById('ratings_' + positionId + '_text')) {
		document.getElementById('ratings_' + positionId + '_text').style.display = 'inline';
		document.getElementById('ratings_' + positionId + '_text').innerHTML = 'Thanks for rating!';
	}
	
	last_rated_position_id = positionId;
}

function rating_onresponse(xml) {
}
