/*
 *
 */

$(document).ready(function () {
	// load the news form using ajax
	$.get("news/data/news.php", function(data){
		// create a modal dialog with the data
		$(data).modal({
			close: false,
			position: ["15%",],
			overlayId: 'news-overlay',
			containerId: 'news-container',
			onOpen: news.open,
			onShow: news.show,
			onClose: news.close
		});
	});

	// preload images
	var img = ['form_bottom.gif', 'form_top.gif'];
	$(img).each(function () {
		var i = new Image();
		i.src = 'news/img/' + this;
	});
});

var news = {
	message: null,
	open: function (dialog) {
		// dynamically determine height
		var h = 380;
		var title = $('#news-container .news-title').html();
		$('#news-container .news-title').html('Betöltés...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					$('#news-container .news-content').animate({
						height: h
					}, function () {
						$('#news-container .news-title').html(title);
						$('#news-container .news-loading').fadeIn(200, function () {
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
		$('#news-container .news-send').click(function (e) {
			e.preventDefault();
		});
	},
	close: function (dialog) {
		$('#news-container .news-message').fadeOut();
		$('#news-container .news-title').html('Viszlát...');
		$('#news-container .news-loading').fadeOut(100);
		$('#news-container .news-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
					});
				});
			});
		});
	}
};

