Poll = function( i_poll, i_body ){
	this.body = document.getElementById( i_body );
	this.poll_node = document.getElementById( i_body );
	this.button = document.getElementById( 'POLL_button' );
	this.html = '';
	this.ok = false;
	this.state = 'poll';
	
	if( this.poll_node && this.body ) this.ok = true;
	
	this.result = new Array();
	this.polls_num = 0;
	
	this.ajax = new sack();
	this.ajax.parent = this;
	
	
	this.get = function(){
		this.ajax.reset();
		this.ajax.setVar('mode', 'get_poll');
		this.ajax.method = 'POST';
		this.ajax.requestFile = "/inc/site_lib/poll.php";
		this.ajax.onCompletion = this.onGetPollReady;
		this.ajax.runAJAX();

	}
	
	this.onGetPollReady = function(){
		var html = '';

		var poll_ar  = this.responseXML.getElementsByTagName('poll');
		if( poll_ar ){
			for( var i = 0; i < poll_ar.length; i++ ){
				var i_poll = "i_poll_"+poll_ar[i].getAttribute('id');
								
				var names = poll_ar[i].getElementsByTagName('name');
				var name = names[0].firstChild.nodeValue;
				
				html += name;
				html += '<ul class="POLL_items" id="'+i_poll+'">';

				var items = poll_ar[i].getElementsByTagName('item');
				for ( j = 0; j < items.length; j++ ) {
					var  i_poll_item_ = 'i_poll_item_'+items[j].getAttribute('id');
					html += '<li  id="'+i_poll_item_+'" onclick="Poll.click(this, '+i+')">'+items[j].firstChild.nodeValue;
				}
				
				html += '</ul>';
			}
		}
		
		html += '\
		<div style="text-align: center;">\
			<div><img src="/images/poll/submit.gif" style="margin-top: 5px;" onclick="Poll.submit()" class="hand"></div>\
			<div><a href="#" class="results_a" onclick="Poll.show_results(); return false;">результаты</a></div>\
		</div>'
		
		this.polls_num = poll_ar.length;
		this.parent.body.innerHTML = html;
	}
	
	this.click = function( node, n ) {
		if( node ){
			var parent  = node.parentNode;
			if ( !parent ) return;
			var lis = parent.getElementsByTagName('li');
			for ( var i = 0; i < lis.length; i++ ) lis[i].className = '';
			node.className = 'active';
			this.result[n] = node.getAttribute('id');
		}
	}
	
	this.submit = function() {
		var vote = "";
		for( var i = 0; i < this.result.length; i++ ) {
			vote += this.result[i]+";";
		}
		
		this.ajax.reset();
		this.ajax.method = 'POST';
		this.ajax.requestFile = "/inc/site_lib/poll.php";
		this.ajax.setVar('mode', 'get_result');
		this.ajax.setVar('vote', vote);
		this.ajax.onCompletion = this.show_results;
		this.ajax.runAJAX();
		
		this.state = 'results';
	}	
	
	this.show_results = function() {
	
	}
}