//var g_clear = 'image/pomaranczowa.gif';
//var g_fill = 'image/szara.gif';
var g_clear = 'http://www.dobre-gry.pl/images/star_off.gif';
var g_fill = 'http://www.dobre-gry.pl/images/star_on.gif';
var ile = '5';
		
var x = 17;
var y = 14;

function $( id ){
	return document.getElementById( id );
}

function generujto(file, rate)
{
	var rate = Math.round(rate);

	var iden = $( 'ocena' );
	docBody = $( 'ocena' );
	
	for( i = 0; i < ile; i++ )
	{
		element = document.createElement("img");
		element.id = 'GW'+i;
		docBody.appendChild(element);
		
		incre = i + 1;
		//docBody.innerHTML += '<img id="vote' + i + 'Image' + i + '" src="' + g_clear + '" onmouseover="setImages(' + i + ', ' + i + ')" onmouseout="setImages(' + i + ',0)" onclick="rateItem(' + i + ',' + i + ')" class="rateImage" alt="' + i + '" />';
		element.setAttribute("src", g_clear);
		element.setAttribute("width", x);
		element.setAttribute("height", y);
		element.setAttribute("name", incre);
		element.setAttribute("class", "rateImage");

		element.onclick=function () { vote(i, file); };
		element.onmouseover=function () { zmien(this.name); };
		$('ocena').onmouseout=function () { czysc(); };
	}
	
}

function zmien(nr)
{
	
	for(i = 0; i < nr; i++)
	{
		$('GW'+(i)).setAttribute("src", g_fill);	
	   //$(i).setAttribute("src", g_fill);	
	}
}

function czysc()
{
	for( i = 0; i < ile; i++ )
	{
		$('GW'+i).setAttribute("src", g_clear);	
	}
}

function vote(rate, file)
{
	advAJAX.post({
		url: './includes/insertrating.php?rank='+rate+'&gameid='+file,
		onSuccess: function(obj) {
			var result = obj.responseText.split('|');

			if (result[0] != '2')
			{
				alert('Dziekujemy!');
			}
			else
			{
				alert('You\'ve already voted.');
			}	
		},
		onError: function(obj) { alert("Error"); },
		parameters : {
			file: file,
			rate: i
		}
	});
	
	return false;
}





