function RegisterNamespaces(){for(var i=0;i<arguments.length;i++){var p=arguments[i].split("."),w=window;for(var j=0;j<p.length;j++){if(!w[p[j]])w[p[j]]=new Object();w=w[p[j]];}}}
RegisterNamespaces('Inpl.Vote');

Inpl.Vote = new function()
{
	var objVote=this,d='default',ranks={},cName='V_',fn='Inpl.Vote.',en='Vote',ttl=2592000,prl={};

	this.Init = function(id,type,rank)
	{
		try{
			var o,i,a,s,r,x=type+id;

			ranks[x]=Math.floor(rank);
			r = parseInt(INTPL('getCookie',cName+x));
			if(r>=0)
			{
				Voted(id,type,r);
			}
			else
			{
				o=$(en+x).getElementsByTagName("LI");
				for(i=0;i<2;i++)
				{
					
					a=o[i].childNodes[0];
					//a.onmouseover = new Function('return '+fn+'Set('+id+',"'+type+'",'+(i+1)+')');
					//a.onmouseout = new Function('return '+fn+'Clear('+id+',"'+type+'")');
					a.onclick = new Function('return '+fn+'Vote('+id+',"'+type+'",'+(1-i)+')');
				}
			}
		}catch(e){}
	};

	this.Vote = function(id,type,rank)
	{
		try	{
			var i=document.createElement('IMG');
			i.style.position='absolute';
			i.style.top='1px';
			i.style.left='1px';
			i.style.display='none';
			i.alt='';
			i.src='/ocen/'+type+','+parseInt(id)+','+parseInt(rank)+'?t='+(new Date()).getTime();
			document.body.appendChild(i);
			Voted(id,type,rank);
		}catch(e){}
		return false;
	};

	function Voted(id,type,rank)
	{
		var o=$(en+type+id).getElementsByTagName("LI"),i,a,c=$('VoteC'+type+id);
		
		if(c&&c.innerHTML=="-")
		{
			//c.innerHTML=parseInt(rank) + ".00";
			if(rank==0)
			{
				c.innerHTML="0%";
			}
			else
			{
				c.innerHTML="100%";
			}
		}

		//$(en+type+id+"Text").innerHTML = "Twoja ocena: " + rank;
		$(en+type+id+"Text").innerHTML = "";
		$(en+type+id+"Text").className = 'voted';
		$(en+type+id+"Text").innerHTML = "Ocene zapisano";

		for(i=0;i<o.length;i++)
		{
			a=o[i].childNodes[0];
			a.onclick = new Function('return false');
			a.onmouseover = null;
			a.onmouseout = null;
			a.style.cursor=d;
		}

	}

	function $(n){return document.getElementById(n);}
}
