$(document).ready(function() {
	jQuery.fn.getComputedStyle = function(properties) {
		properties = properties.split(' ')
		var len = properties.length, obj = {};
		for (var i = 0; i < len; i++)
			obj[properties[i]] = jQuery.fn.css.call(this, properties[i]);

		return obj;
	}

	$('a#zapytanie_link').click(function(event) {
		$window = $(window)
		$overlay = $('#zapytanie_overlay')
		var percents = {
			left: 0,
			top: 0,

			recalculate: function() {
				this.left = parseInt((100 - ($overlay.outerWidth() / $window.width() * 100)) / 2);
				this.top = parseInt((100 - ($overlay.outerHeight() / $window.height() * 100)) / 2);
			}
		}
		percents.recalculate()

		$window.resize(function() {
			percents.recalculate();
			$('.blockPage').css({
				top: percents.top + '%',
				left: percents.left + '%'
			})
		})

		$message = $overlay.clone().css($overlay.getCSS()).css({
			fontSize: '12px',
			margin: '1em'
		})
		$message.find('#zapytanie_frm').validate()

		$.blockUI({
			message: $message,
			css: {
				cursor: 'default',
				width: 'auto',
				top: percents.top + '%',
				left: percents.left + '%',
				width: '330px'
			}
		})
		$('.blockOverlay').css({cursor: 'pointer'}).click($.unblockUI)
		event.preventDefault()
	})

})
