var Sondy = {
	pokaz : function(iPoll) {
		$.ajax({
			url: "/sondy/pokaz/" + iPoll,
			cache: false,
			dataType: 'json',
			type: 'post',
			success: function(data) {
				if (data.status == 1) {				
					var layer = '#poll_' + iPoll;
					$(layer).html(data.html);
					Sondy.glosujClick(iPoll);
					Sondy.wynikiClick(iPoll);
				}
			}
		});
	},
	
	wyniki : function(iPoll) {
		$.ajax({
			url: "/sondy/wyniki/" + iPoll,
			cache: false,
			dataType: 'json',
			type: 'post',
			success: function(data) {
				if (data.status == 1) {				
					var layer = '#poll_' + iPoll;
					$(layer).html(data.html);
				}
			}
		});
	},
	
	glosujClick : function(iPoll) {
		$('input#_sondyGlosuj').click(function () {
			var selected = $('div#poll_'+iPoll+' input:checked').val();
			if (typeof(selected) != 'undefined') {
				$.ajax({
					url: "/sondy/glosuj/",
					cache: false,
					dataType: 'json',
					type: 'post',
					data: 'answer=' + selected,
					success: function(data) {
						if (data.status == 1) {				
							Sondy.wyniki(iPoll);
						}
						else if (data.status == 0) {
							if (data.message) {
								$('p#_sondyMessage').html(data.message);
							}
						}
					}
				});
			}
			
			return false;
		});
	},
	
	wynikiClick : function(iPoll) {
		$('input#_sondyWyniki').click(function () {
			Sondy.wyniki(iPoll);
			return false;
		});
	}
}

