/* --- component Photo Rate JS --- */

/**
 * Photo Rate javascript class
 */
function JSProfileRate( profile_id )
{
	/* -- Class constructor -- */
	// integer
	this.profile_id = profile_id;
	this.user_score = 0;
	
	this.allow_rate = true;
	
	// objects
	this.obj_container = $('profile_rate_container');
	
	this.obj_average_score = $('profile_rate_average_score');
	this.obj_average_score_rates = $('profile_rate_rates');
	
	this.obj_points_container = $('profile_rate_points_container');
	
	// points nodes
	this.points = this.obj_points_container.getElementsByTagName('div');
	
	
	/* -- Class methods -- */
	this.rate_highlight = function( point )
	{
		if ( !this.allow_rate )
			return;
		
		var className = point ? 'profile_rate_point_on' : 'profile_rate_point_off';
		
		point--; // index begins at 0, points at 1
		
		for( var i = 0; i < this.points.length; i++ )
		{
			if( i == point  )
			{
				this.points[i].className = 'profile_rate_point_active';
				className = 'profile_rate_point_off';
				continue;
			}
			
			this.points[i].className = className;
		}
		
		return;
	}
	
	
	this.rate_higlight_reset = function()
	{
		return this.rate_highlight(this.user_score);
	}
	
	this.fix_rate_scores = function( user_score, average_score, rates )
	{
		this.user_score = user_score;
		this.obj_average_score.innerHTML = average_score;
		this.obj_average_score_rates.innerHTML = rates;
		
		this.rate_higlight_reset();
		
		this.obj_container.className = '';
	}
	
	this.rate_profile = function( score )
	{
		this.user_score = score;
		this.obj_container.className = 'profile_rate_container_inactive';
		
		xajax_rateProfile( this.profile_id, score );
		
		this.rate_higlight_reset();
	}
	
	this.rate_profile(0);
	
	setTimeout( "$('profile_rate_container').className = ''", 150 );
}
