
    // +--------------------------------------------------------------------------+
    // | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"> |
    // +--------------------------------------------------------------------------+ 

	var voteLimit = 10;
	var lock = false;

	Event.observe 
	(
		window,
		'load',
		function ()
		{
			var votable = $$ ('.votable');
			
			votable.each
			(
				function (item)
				{
					var checkBoxItems = Element.select (item, 'input');
					
					if (checkBoxItems)
					{
						var checkBox = checkBoxItems[0];
					}
					
					Event.observe 
					(
						item,
						'mouseover',
						function ()
						{
							item.style.backgroundColor='#cce2e9';
						}
					);
					
					Event.observe 
					(
						item,
						'mouseout',
						function ()
						{
							item.style.backgroundColor='#ffffff';
						}
					);
					
					Event.observe 
					(
						checkBox,
						'click',
						function ()
						{
							if (checkBox.disabled == false)
							{
								vote (item, checkBox);
							}
						}
					);
				}
			);
		}
	);
	
	function vote (item, checkBox)
	{
		var acceptItems = Element.select (item, '.accept');
		
		if (acceptItems)
		{
			var accept = acceptItems[0];
		}
		
		var failedItems = Element.select (item, '.fail');
		
		if (failedItems)
		{
			var fail = failedItems[0];
		}
		
		var loadingItems = Element.select (item, '.loading');
		
		if (loadingItems)
		{
			var loading = loadingItems[0];
		}
		
		var labelItems = Element.select (item, 'label');
		
		if (labelItems)
		{
			var label = labelItems[0];
		}
		
		var url = 'Konkursy,Glosuj.html';
		
		if (! lock)
		{
			new Ajax.Request
			(
				url, 
				{
					method: 'post',
					parameters: 'article=' + checkBox.value,
					onCreate: function ()
					{
						checkBox.style.display = 'none';
						loading.style.display = 'block';
						
						lock = true;
					},
					onFailure: function ()
					{
						alert ('Error reading data...');
					},
					onSuccess: function (transport)
					{
						voted = transport.responseText;
						
						loading.style.display = 'none';
						
						$ ('message').style.display = 'block';
						
						if (voted == 9999)
						{
							disableCheckBoxes ();
	
							fail.style.display = 'block';
	
							$ ('message').innerHTML = 'Tylko zalogowani użytkownicy forum mog± głosować.<br /><a href="forum/login.php?redirect=../Konkursy.html">Kliknij tutaj aby się zalogować.';
						}
						else
						{
							accept.style.display = 'block';
							
							$ ('message').innerHTML = 'Twój głos został oddany na: "' + label.innerHTML + '"';

							checkBox.disabled = true;

							if (voted >= voteLimit)
							{
								disableCheckBoxes ();
		
								$ ('message').innerHTML += '<br />Twój limit głosów został wła¶nie wyczerpany.';
							}					
						}
						
						lock = false;
					}
				}
			);
		}
	}
	
	function disableCheckBoxes ()
	{
		var checkBoxes = $$ ('#konkursy-lista input[type="checkbox"]');
		
		checkBoxes.each
		(
			function (item)
			{
				item.disabled = true;
			}
		);
	}
