function ajax()
{ }

ajax.prototype =
{
	req   : null,
	timer : null,
	data  : null,
	func  : null,
	wrap  : null,
	req_stop : function ()
	{
		alert('stop');
		this.req.abort();
	},
	reqChange : function ()
	{
		if (this.req.readyState == 4)
		{
			clearTimeout(this.timer);
			if (this.req.status == 200)
			{
				this.data = '' + this.req.responseText + '';
				this.req.abort();
				this.func();
			}
			else
			{
				//alert('ERR ' + this.req.status + this.req.statusText);
				alert('Ошибка запроса');
				this.req.abort();
			}
		}
	},
	reqDoc : function (url)
	{
		if (!this.func || !this.wrap)
		{
			alert('set func!');
			return;
		}

		url += '&ajax=' + Math.random();
		if (window.XMLHttpRequest)
		{
			this.req = new XMLHttpRequest();
			this.req.onreadystatechange = this.wrap;
			this.req.open('GET', url, true);
			this.req.send(null);
		}
		else if (window.ActiveXObject)
		{
			this.req = new ActiveXObject("Microsoft.XMLHTTP");
			this.req.onreadystatechange = this.wrap;
			this.req.open('GET', url, true);
			this.req.send();
		}
		else
		{
			//alert('Cannot create request');
			alert('Ошибка создания');
			return;
		}

		this.timer = window.setTimeout("ajax_vote.req_stop()", 15000);
	}
}


function $(s)
{
	return document.getElementById(s);
}


function rate(id, val)
{
	var num, tmp;

	$('rate' + id).style.display = 'none';
	$('ratePic'+id).style.display = '';

	ajax_vote = new ajax();
	ajax_vote.func = function()
	{
		if (this.data.indexOf('ok') != 0)
		{
			//alert('request error ' + this.data);
			alert('Ошибка ответа');
			return;
		}

		$('rateWrap' + id).innerHTML = this.data.substring(2, this.data.length);
	}

	ajax_vote.wrap = function()
	{
		ajax_vote.reqChange();
	}

	ajax_vote.reqDoc('foto.php?rate=' + id + '&val=' + val);

	return false;
}


function seeOn(elm)
{
	var tmp;
	do
	{
		if (elm.className.indexOf(' rateOver') == -1)
		{
			elm.className += ' rateOver';
		}

		elm = elm.previousSibling;
		if (elm && elm.nodeType == 3)
		{
			elm = elm.previousSibling;
		}
	}
	while (elm);
}


function seeOff(elm)
{
	elm = elm.parentNode.getElementsByTagName('A');
	for (i = 0; i < elm.length; ++i)
	{
		elm[i].className = elm[i].className.replace(' rateOver', '');
	}
}