/**
 * Stars RAting System
 *
 * Author : Gabi Balasz
 *
 * date : 22.01.2008
 *
 **/
 
/***
 *	overStar
 *
 *		Functie ce se apeleaza cand se duce mouse-ul deasupra unei jumatati de stea
 *
 *	@ param
 *		sobj - obiectul jumatatii de stea
 *		nr   - numarul echivalent
 **/
function overStar( sobj, nr )
{
	
	if ( sr_active == 1 )
	{
		sr_status[ nr ] = 1 ;

		for (i=1;i<=nr;i++)
		{
			sr_status[ i ] = 0;
			if( i % 2 == 0 )
			{
				document.getElementById('rating'+i).className = 'half_right_selected';
			}
			else
			{
				document.getElementById('rating'+i).className = 'half_left_selected';
			}
		}
		for (i=nr+1;i<=10;i++)
		{
			sr_status[ i ] = 0;
			if( i % 2 == 0 )
			{
				document.getElementById('rating'+i).className = 'half_right';
			}
			else
			{
				document.getElementById('rating'+i).className = 'half_left';
			}
		}
		
	overlib('<b>Your rating: ' + nr + '</b><br/>Your last rating: ' + sr_curentVal + '<br/>Average rating: ' + sr_average + '<br/>Total ratings: ' + sr_total ,ol_width=100,ol_height=55,ol_offsetx=-45);
		
	}
	else
	{
//	nd();
	overlib('Average rating: ' + sr_curentVal + '<br/>Total ratings: ' + sr_total ,ol_width=100,ol_height=55,ol_offsetx=-45);
	}
}

function clearStars()
{
	for (i=10;i>sr_curentVal;i--)
	{
		if( i % 2 == 0 )
		{
			document.getElementById('rating'+i).className = 'half_right';
		}
		else
		{
			document.getElementById('rating'+i).className = 'half_left';
		}
	}	
	for (i=1;i<=sr_curentVal;i++)
	{
		if( i % 2 == 0 )
		{
			document.getElementById('rating'+i).className = 'half_right_selected';
		}
		else
		{
			document.getElementById('rating'+i).className = 'half_left_selected';
		}
	}	
	nd();	
}

/***
 *	starClick
 *
 *		Functie ce se apeleaza cand se selecteza o valoare pt. rating
 *
 *	@ param
 *		nr   - numarul echivalent jumatatii apasate
 **/
function starClick( nr )
{
	if ( sr_active )
	{
		sr_curentVal = 	nr ;
		saveRating( sr_curentVal );
		nd();
	}
}

/***
 *	Functie ce afiseaza noile contenturi din featured additions
 **/
function starResponse()
{ 
	//ajax response storing
	eval( 'var aj = ' + ajax.response + ';' ) ;
	var ar = aj[0] ;
	sr_total = ar['total'] ;
	sr_average = Math.round(ar['average']);
	
}


function saveRating( val )
{
	if ( sr_active )
	{	
		ajax.requestFile = root_path + 'application/ajax/www/saveRatings.php?key='+content_key+'&val=' + val ;	// Specifying which file to get
		ajax.onCompletion = starResponse;	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function		
	}
}

function setKey( key )
{
	content_key = key;	
}
function setRating( key )
{
	sr_curentVal = Math.round(key);	
}
function setAverage( key )
{
	sr_average = Math.round(key);	
}
function setTotal( val )
{
	sr_total = val;	
}

function activateStars()
{
	sr_active =1  ;
}
function deactivateStars()
{
	sr_active = 0  ;
}

	// instatiating Ajax object
	var ajax = new sack();

	// variabila ce indica daca sistemul de rating este activ
	var content_key = 0;

	// variabila ce indica daca sistemul de rating este activ
	var sr_active = 0;

	// variabila ce indica valoarea curenta a votului
	var sr_curentVal = 0;

	// variabila ce indica valoarea curenta a votului
	var sr_average = 0;

	// variabila ce indica valoarea curenta a votului
	var sr_total = 0;

	// sir ce retine statusul fiecarei jumatati de stea
	var sr_status = new Array();

	for (i=1;i<=10;i++)
	{
		sr_status[ i ] = 0;
	}
 
 