$(document).ready(function(){
	// set up comment dialog box
	$('#post_commentCount a').click(function(e){
		e.preventDefault();
		// if the dialog doesn't already exist:
		if($('#comments-dialog').length === 0){
			var 
			// create holder
			holder = $('<div />')
				.attr('id', 'comments-dialog')
				.css({
					zIndex: 999,
					opacity:0,
					top:0,
					left:0,
					position:($.browser.msie?'':'fixed')
				}),
			// create overlay
			overlay = $('<div />')
				.addClass('comment-overlay')
				.css({
					width: $(window).width(),
					height: $(window).height(),
					background: '#000',
					opacity: 0.5,
					position: ($.browser.msie?'absolute':'fixed'),
					top: 0, 
					left: 0, 
					zIndex: 1000
				})
				.click(function(){
					$('#comments-dialog').stop().animate({opacity:0},250, function(){if($.browser.msie){$(this).remove();}else{$(this).hide();}});
				}),
			// generate shadow
			shadow = $('<div />')
				.addClass('comment-shadow')
				.css({
					width: 800,
					height: $(window).height() * 0.9,
					background: '#000',
					opacity: 0.5,
					position: ($.browser.msie?'absolute':'fixed'),
					top: ($(window).height() / 2) - (($(window).height() * 0.9) /2 ), 
					left: ($(window).width() / 2)  - 400, 
					zIndex: 1001
				}),
			// generate dialog
			dialog = $('<div />')
				.addClass('comment-dialog-content')
				.addClass('comment-dialog-loading')
				.css({
					width: 770,
					height: ($(window).height() * 0.9) - 30,
					position: 'fixed',
					top: ($(window).height() / 2) - ((($(window).height() * 0.9) / 2) - 15), 
					left: ($(window).width() / 2)  - 385, 
					zIndex: 1002
				})
				.append(
					$('<div />')
						.addClass('comment-dialog-closer')
						.css({
							top: -15,
							right: -15,
							height:30, 
							width:30, 
							cursor: 'pointer',
							position: 'absolute',
							zIndex: 1004
						})
						.click(function(){
							$('#comments-dialog').stop().animate({opacity:0},250, function(){if($.browser.msie){$(this).remove();}else{$(this).hide();}});
						})
				)
				.append(
					$('<div />')
						.addClass('comment-dialog')
						.css({
							width: 770,
							height: ($(window).height() * 0.9) - 30,
							zIndex: 1003
						})
				);
			// combine.. and display
			$('body').append(holder.append(overlay).append(shadow).append(dialog).animate({opacity:1}, 250));
			// load link into block...
			$.ajax({
				url: $(this).attr('href'), 
				dataType: 'html',
				success: function(data){
					$('.comment-dialog-content').removeClass('comment-dialog-loading');
					$('.comment-dialog').html(data);
				}
			});
			$(window).resize(function(){
				$('.comment-overlay').stop().animate({
					width: $(window).width(),
					height: $(window).height()
				},1);
				$('.comment-shadow').stop().animate({
					height: $(window).height() * 0.9,
					top: ($(window).height() / 2) - (($(window).height() * 0.9) /2 ), 
					left: ($(window).width() / 2)  - 400
				},100);
				$('.comment-dialog-content').stop().animate({
					height: ($(window).height() * 0.9) - 30,
					top: ($(window).height() / 2) - ((($(window).height() * 0.9) / 2) - 15), 
					left: ($(window).width() / 2)  - 385
				},100);
				$('.comment-dialog').stop().animate({
					height: ($(window).height() * 0.9) - 30
				},100);
			});
		}else{
			// div already exists
			$('#comments-dialog').stop().show().animate({opacity:1},250);
		}
	});
});
