jQuery(function ($) {

	var modal = {
		message: null,
		init: function () {
			$('#notices-btn').click(function (e) {
				e.preventDefault();
				
				  $('#ajax-loader').show();

				$.get("/ajax/notices/", {rand: randomNumber (10,1000)}, function(data){

					$(data).modal({
						closeHTML: "<a href='#' title='Закрыть' class='notice-close'>x</a>",
						position: ["15%",],
						overlayId: 'notice-overlay',
						containerId: 'notice-container',
						onOpen: modal.open,
						onShow: modal.show,
						onClose: modal.close
					});
				});
			});
		},
		open: function (dialog) {
			
			 $('#ajax-loader').hide();

			var h = 350; // my height

			var title = $('#notice-container .notice-title').html();
			$('#notice-container .notice-title').html('Загрузка...');
			dialog.overlay.fadeIn(100, function () {
				dialog.container.fadeIn(100, function () {
					dialog.data.fadeIn(100, function () {
						$('#notice-container .notice-content').animate({
							height: h
						}, function () {
							$('#notice-container .notice-title').html(title);
							$('#notice-container form').fadeIn(100, function () {
								$('#notice-container textarea').focus();

								// fix png's for IE 6
								if ($.browser.msie && $.browser.version < 7) {
									$('#notice-container .notice-button').each(function () {
										if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
											var src = RegExp.$1;
											$(this).css({
												backgroundImage: 'none',
												filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
											});
										}
									});
								}
							});
						});
					});
				});
			});
		},

		close: function (dialog) {
			$('#notice-container .notice-message').fadeOut();
			$('#notice-container .notice-title').html('');
			$('#notice-container form').fadeOut(100);
			$('#notice-container .notice-content').animate({
				height: 40
			}, function () {
				dialog.data.fadeOut(100, function () {
					dialog.container.fadeOut(100, function () {
						dialog.overlay.fadeOut(100, function () {
							$.modal.close();
						});
					});
				});
			});
		},

	};

	modal.init();

});
