listing_rating 	= new Array();
reset_rating	= new Array();
function hover_rating(ind, id) {
	ptr = $('rating_' + id);
	
	if(!listing_rating[id])	listing_rating[id] 	= get_rating(ptr);		
	if(!reset_rating[id])	reset_rating[id] 	= setTimeout(function() { reset_stars(ptr, listing_rating[id]); reset_rating[id] = false; }, rating_reset_wait * 1000);
		
	reset_stars(ptr, ind + 1);	// don't puff the hover star
	slide_stars(ptr, ind);	
	
	ptr.onclick = function() { submit_rating(ind + 1, id); }	
}

function submit_rating(ind, id) {
	ptr = $('rating_' + id);
	
	f = function(o) {		
		xmlDoc 		= create_xml_doc(o.responseText);		
		
		msg 		= getText(xmlDoc, 'msg');
		the_rating	= getText(xmlDoc, 'rating');
		
		listing_rating[id] 			= the_rating;		
		$('number_' + id).innerHTML = the_rating;
		
		msg_div = $(document.createElement('div'));		
		msg_div.addClassName('msg');
		msg_div.setAttribute('id', 'msg_' + id);
		msg_div.hide();
		msg_div.innerHTML = msg;
		
		$('rating_' + id).appendChild(msg_div);
		
		Effect.BlindDown('msg_' + id, { duration: rating_blind_wait });

		setTimeout(function() { 
			Effect.BlindUp('msg_' + id, { 
				duration: rating_blind_wait,
				afterfinish: function() { 
					$('rating_' + id).removeChild() 
				}
			});
		}, rating_reset_wait * 1000);
	}
	
	new Ajax.Request(rating_file + '?vendor_id=' + id + '&rating=' + ind + '&j=' + ut(), { method: 'get', onSuccess: f } ); 	
}

function get_stars(ptr) {
	return $(ptr.parentNode).getElementsByTagName('img');
}

function reset_stars(ptr, ind) {
	stars = get_stars(ptr);
	
	for(x = ind; x < stars.length; x++) {
		if(stars[x].src.indexOf(gold_star) > -1) {
			puff_star(stars[x]);		
			stars[x].src = grey_star;			
		}
	}
}

function puff_star(ptr) {
	ofs = $(ptr).cumulativeOffset();
	img = $(new Image());	
	img.setStyle({
		position: 'absolute',
		top: ofs.top + 'px',
		left: ofs.left + 'px',
		zIndex: 999
	});
	img.src = gold_star;
	document.body.appendChild(img);
	Effect.Puff(img, { duration: rating_puff_wait });	
}

function slide_stars(ptr, ind) {
	stars = get_stars(ptr);
	
	for(x = 0; x <= ind; x++)
		stars[x].src = gold_star;
}

function get_rating(ptr) {
	stars = get_stars(ptr);
	
	for(x = 0; x < stars.length; x++) {
		if(stars[x].src.indexOf(grey_star) > -1)
			return x;
	}
	
	return stars.length;
}