$(document).ready(function(){

	// init highslide
	hs.graphicsDir     = '/site/bins/js/highslide/graphics/';
	hs.creditsText     = '';
	hs.restoreTitle    = 'Левый щелчок закроет изображение. Чтобы передвинуть, зажмите мышь и ведите в нужную сторону. Используйте кнопки со стрелками, для просмотра следующего/предыдущего изображения.';
	hs.loadingText     = 'Загрузка...';
	hs.loadingTitle    = 'Нажмите чтобы отменить';
	hs.fullExpandTitle = 'Развернуть на натуральный размер изображения';
	hs.creditsTitle    = 'Перейти на главную';
	$('a.highslide').each(function() {
		this.onclick = function() {
			return hs.expand(this);
		};
	});

	if($("#poll").size() == 1) {

		function process_form(event){
			event.preventDefault();

			var id = $("input[@name='poll']:checked").attr("value");
			id = id.replace("opt", '');

			$("#poll").fadeOut("300", function() {
				load_results(id);
				$.cookie('poll_id', $('#poll_id').val(), {
					expires: 365
				});
			});
		}

		function load_results(vote_id) {
			$.ajax({
				url: "poll/" + vote_id + (vote_id == 'none' ? '/' + $('#poll_id').val() : ''),
				type: 'GET',
				success: function(data) {
					$('#poll')
						.html(data)
						.fadeIn(300);
				}
			});
		}
		
		$("#vote", $('#poll')).click(process_form); // setup the submit handler

		if($.cookie('poll_id') == $('#poll_id').val()) {
			$("#poll").fadeOut("300", function() {
				load_results('none');
			});
		}
		
	}

	$('#id_send')
		.mouseover(function() {
			$(this).css('backgroundPosition', '0 -26px');
		})
		.mousedown(function() {
			$(this).css('backgroundPosition', '0 -52px');
		})
		.mouseout(function() {
			$(this).css('backgroundPosition', '0 0');
		})
		.click(function() {
			$(this).parents('form').submit();
			return false;
		});

});