origRates = new Array();
ratingText1 = new Array();
ratingText2 = new Array();
ratingText3 = new Array();
ratingText4 = new Array();
ratingText5 = new Array();
defaultText = new Array();

function wprater_showRate( id )
{
    new Ajax.Request( 'http://dp.nonoo.hu/wp-content/plugins/wprater/wprater-ajax.php', {
	method: 'post',
	parameters: { showrate: id }
    } );
}

function wprater_renderRate( id, rate, ishovered, votesnum, userrating )
{
    if( ishovered )
    {
	switch( rate )
	{
	    case 1:
		if( ratingText1[id] != '' )
		{
		    wprater_setText( id, ratingText1[id], 0 );
		}
		break;
	    case 2:
		if( ratingText2[id] != '' )
		{
		    wprater_setText( id, ratingText2[id], 0 );break;
		}
		break;
	    case 3:
		if( ratingText3[id] != '' )
		{
		    wprater_setText( id, ratingText3[id], 0 );break;
		}
		break;
	    case 4:
		if( ratingText4[id] != '' )
		{
		    wprater_setText( id, ratingText4[id], 0 );break;
		}
		break;
	    case 5:
		if( ratingText5[id] != '' )
		{
		    wprater_setText( id, ratingText5[id], 0 );break;
		}
	}
    }
    else
    {
	wprater_setText( id, '', 1 );
    }

    for( j=1; j < 6; j++ )
    {
	if( ishovered )
	{
	    if( rate >= j )
	    {
		$(id+'-img-'+j).src = 'http://dp.nonoo.hu/wp-content/plugins/wprater/star_2.png';
	    }
	}
	else
	{
	    if( rate >= j )
	    {
		// full star
	    	$(id+'-img-'+j).src = 'http://dp.nonoo.hu/wp-content/plugins/wprater/star_1.png';
	    }
	    else
	    {
		if( rate >= j-0.5 )
		{
		    // half star
	    	    $(id+'-img-'+j).src = 'http://dp.nonoo.hu/wp-content/plugins/wprater/star_3.png';
		}
		else
		{
		    $(id+'-img-'+j).src = 'http://dp.nonoo.hu/wp-content/plugins/wprater/star_0.png';
		}
	    }
	}
    }
}

function wprater_setText( id, text, setdefaulttext )
{
    if( setdefaulttext )
    {
	text = defaultText[id];
    }

    $(id+'-text').innerHTML = text;
}

function wprater_rate( id, value )
{
    new Ajax.Request( 'http://dp.nonoo.hu/wp-content/plugins/wprater/wprater-ajax.php', {
	method: 'post',
	parameters: { rate: id, value: value }
    } );
}
