//----------------------------------------------------------------------------------------------------------------------
/**
 * This file contains the {@link ML} class
 *
 * @author      Blue Moon IT <info@bluemoonit.net>
 * @copyright   2011, Blue Moon IT
 * @version     SVN: $Id: ml.js 231 2011-10-25 14:07:01Z johan $
 */
//----------------------------------------------------------------------------------------------------------------------
/*jslint browser:true white:false devel:true onevar:true nomen:false forin:true undef:true */
/*global jQuery,window,BlueMoonIT_ImageResizer,ACP,gapi */
//----------------------------------------------------------------------------------------------------------------------
/**
 * Main singleton class for the ML webapp
 *
 * @author      Johan B.W. de Vries <johan@bluemoonit.net>
 */
var ML = {};

ML.singlePage = false;
ML.isFull = false;
ML.curPost = null;
ML.ldPostCount = null;
ML.resizer = new BlueMoonIT_ImageResizer();
ML.showOtherArrows = false;
ML.isArchiveMoving = false;
ML.isArchiveOpen = false;
ML.thumbnailIndex = -1;

ML.tweetTimer = null;
ML.curTweet = false;
//----------------------------------------------------------------------------------------------------------------------
ML.textFull = function()
{
	var post, cont, col, list;

	if( ML.isFull ) {
		return;
	}

	post = jQuery('#post-list li:eq(' + ML.curPost + ')');
	if( 0 === post.length ) {
		return false;
	}

	ML.isFull = true;

	if( post.find('div.full').length ) {
		jQuery('#main-txt-cnt')
			.empty()
			.append(post.find('div.full').children().clone());
	} else {
		cont = jQuery('#main-txt-cnt');
		if( cont.find('span.readmore').length ) {
			cont.find('div.column:lt(3)').children().addClass('wasRead');
			cont.find('span.readmore').remove();
		}

		cont.children().children().appendTo('#main-txt-cnt');
		cont.find('div.column').remove();

		ML.finishFull();
	}

	if( post.find('span.h1-full').length ) {
		ML.showHeader(post.find('span.h1-full').contents().clone());
	}

	jQuery('#main-txt').animate({height: jQuery(window).height() - 10});

	jQuery('#main-txt').addClass('isFull');
};
//----------------------------------------------------------------------------------------------------------------------
ML.textSmall = function()
{
	if( !ML.isFull ) {
		return;
	}

	ML.isFull = false;
	ML.showPost();

	jQuery('#main-txt').animate({height: 340});

	jQuery('#main-txt').removeClass('isFull');
};
//----------------------------------------------------------------------------------------------------------------------
ML.textToggle = function()
{
	if( !ML.isFull ) {
		ML.textFull();
	} else {
		ML.textSmall();
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.textResize = function()
{
	if( ML.isFull ) {
		jQuery('#main-txt').stop().animate({height: jQuery(window).height() - 10});
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.resizeVis = function()
{
	var ifr, h, l, w, cw;

	if( 0 < jQuery('#main-vis-img').length ) {
		return;
	}

	ifr = jQuery('#main-vis iframe');
	h = jQuery('#main-vis').height();

	cw = jQuery(document).width();
	w = Math.min(1500, cw);
	l = (cw - w) / 2;

	ifr.css({
		height: h + 'px',
		width: w + 'px',
		marginLeft: l + 'px'
	});

	jQuery('#leftbar').css({
		left: (l - 365) + 'px',
		top: '0px',
		height: h + 'px'
	}).show();

	jQuery('#centerbar').css({
		width: w + 'px',
		height: h + 'px',
		left: l + 'px',
		top: '0px'
	}).show();

	jQuery('#rightbar').css({
		left: (l + w) + 'px',
		top: '0px',
		height: h + 'px'
	}).show();
};
//----------------------------------------------------------------------------------------------------------------------
ML.startSlider = function()
{
	ML.resizer.next();

	if( 1 < ML.resizer.images.length ) { 
		ML.sliderInterval = window.setInterval(ML.onSliderTimer, 4000);
	} else if( 0 === ML.resizer.images.length ) { 
		ML.stopSlider();
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.onSliderTimer = function()
{
	jQuery(ML.resizer.imgNode).fadeOut(400, function() {
		ML.resizer.next();
		jQuery(ML.resizer.imgNode).fadeIn();
	});
};
//----------------------------------------------------------------------------------------------------------------------
ML.stopSlider = function()
{
	window.clearInterval(ML.sliderInterval);
};
//----------------------------------------------------------------------------------------------------------------------
ML.setup = function()
{
	jQuery('#post-list').hide();
	ML.ldPostCount = jQuery('#post-list li').length;

	ML.prevLink = jQuery('#main-txt-c a.navlnk.prev').attr('href');
	ML.nextLink = jQuery('#main-txt-c a.navlnk.next').attr('href');

	ML.showCurPost(true);
};
//----------------------------------------------------------------------------------------------------------------------
ML.showCurPost = function(isFirst)
{
	var pid, isImg;

	if( window.location.hash === '#first' ) {
		pid = ML.ldPostCount - 1;
	} else if( window.location.hash.substring(0, 6) === '#post_' ) {
		pid = jQuery('#post-list li[data-id="' + window.location.hash.substring(6) + '"]').index();
	} else {
		pid = 0;
	}

	if( pid === ML.curPost ) {
		return true;
	}

	ML.curPost = pid;

	isImg = 0 < jQuery('#main-vis-img').length;
	if( isImg ) {
		ML.resizer.select(ML.curPost);
	} else {
		jQuery('#main-vis iframe').attr('src', (jQuery('#post-list li:eq(' + ML.curPost + ') span.media-page').text()));
	}

	return ML.showPost(false, isFirst);
};
//----------------------------------------------------------------------------------------------------------------------
ML.showPrevPost = function()
{
	var left, w, tl, isImg;

	if( ML.curPost < ML.ldPostCount - 1 ) {
		w = jQuery(document).width();
		tl = jQuery('#main-txt').css('left').replace('px', '');

		isImg = 0 < jQuery('#main-vis-img').length;

		jQuery('#main-vis-img').animate({'margin-left': -1500});
		jQuery('#main-txt h1').animate({left: w + 1500 - tl});
		jQuery('#main-txt-cnt').animate({left: w + 1500 - tl}, function() {
			ML.curPost += 1;
			ML.showPost();

			if( isImg ) {
				jQuery('#main-vis-img').hide();
				ML.resizer.next();
				left = jQuery('#main-vis-img').css('margin-left').replace('px', '');
				jQuery('#main-vis-img').css('margin-left', w + 1500);
				jQuery('#main-vis-img').show();
			} else {
				jQuery('#main-vis iframe').attr('src', (jQuery('#post-list li:eq(' + ML.curPost + ') span.media-page').text()));
			}

			setTimeout(function() {
				jQuery('#main-txt-cnt, #main-txt h1').css('left', -1500 - tl).animate({left: 70});
				jQuery('#main-vis-img').animate({'margin-left': left});
			}, 10);
		});
		return false;
	} else {
		return true;
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.showNextPost = function()
{
	var w, left, tl, isImg;

	if( 0 < ML.curPost ) {
		w = jQuery(document).width();
		tl = jQuery('#main-txt').css('left').replace('px', '');

		isImg = 0 < jQuery('#main-vis-img').length;

		jQuery('#main-vis-img').animate({'margin-left': w + 1500});
		jQuery('#main-txt h1').animate({left: -1500 - tl});
		jQuery('#main-txt-cnt').animate({left: -1500 - tl}, function() {
			ML.curPost -= 1;
			ML.showPost();

			if( isImg ) {
				jQuery('#main-vis-img').hide();
				ML.resizer.previous();
				left = jQuery('#main-vis-img').css('margin-left').replace('px', '');
				jQuery('#main-vis-img').css('margin-left', -1500);
				jQuery('#main-vis-img').show();
			} else {
				jQuery('#main-vis iframe').attr('src', (jQuery('#post-list li:eq(' + ML.curPost + ') span.media-page').text()));
			}

			setTimeout(function() {
				jQuery('#main-txt-cnt, #main-txt h1').css('left', w + 1500 - tl).animate({left: 70});
				jQuery('#main-vis-img').animate({'margin-left': left});
			}, 10);
		});
		return false;
	} else {
		return true;
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.showPost = function(addSeparator, isFirst)
{
	var post, a, t, p, rest, restChildren, list, col;

	post = jQuery('#post-list li:eq(' + ML.curPost + ')');
	if( 0 === post.length ) {
		return false;
	}

	rest = post.find('div.rest');
	restChildren = rest.children();

	//remove old post
	jQuery('#main-txt-c > h1').remove();
	jQuery('#main-txt-cnt').empty();

	//Show new header
	ML.showHeader(post.find('h1').clone());

	//Show new post
	if( ML.isFull ) {
		jQuery('#main-txt-cnt').append(post.find('div.part').children().clone())
			.append(post.find('div.rest').children().clone());

		ML.finishFull();

		t = jQuery('#main-txt-cnt div.column:first');
		while( t.contents().length ) {
			p = t;
			t = t.contents().eq(0);
		}
		t.remove();
		p.prepend(t.text().substring(1))
			.prepend('<span class="firstLet">' + t.text().substring(0, 1) + '</span>');
	} else {
		ML.showSmall(post.find('div.part').children().clone());
		if( post.find('div.full').length ) {
			col = ML.showSmallColumnMap[ML.showSmallColumn];

			if( post.find('span.readmore').length ) {
				a = post.find('span.readmore').clone();
			} else {
				a = jQuery('<span class="readmore">&hellip; <a class="readmore">Lees verder</a></span>');
			}
			a.bind('click', ML.textFull);
			col.append(a);
		}
	}

	jQuery('#main-txt-c h1').bind('click', function(e) {
		if( 'H1' === e.target.nodeName ) {
			ML.textToggle();
		}
	});

	jQuery('#archive a').removeClass('active');
	a = jQuery('#archive a[href="#post_' + post.attr('data-id') + '"]');
	if( a.length ) {
		a.addClass('active');
	}

	if( !isFirst && post.attr('data-id') ) {
		window.location.hash = 'post_' + post.attr('data-id');
	}

	jQuery('#main-txt-c').find('.navlnk').remove();

	if( ML.singlePage ) {
		return true;
	}

	if( ML.curPost < ML.ldPostCount - 1 ) {
		jQuery('#main-txt-c').append('<a class="prev navlnk"><span>Vorige post</span></a>');
		jQuery('#main-txt-c').find('.navlnk.prev').bind('click', ML.showPrevPost);
	} else if( ML.prevLink ) {
		jQuery('#main-txt-c').append('<a class="prev navlnk" href="' + ML.prevLink + '"><span>Vorige post</span></a>');
	} else {
		jQuery('#main-txt-c').append('<div class="prev navlnk"><span>Vorige post</span></div>');
	}

	if( 0 < ML.curPost ) {
		jQuery('#main-txt-c').append('<a class="next navlnk"><span>Volgende post</span></a>');
		jQuery('#main-txt-c').find('.navlnk.next').bind('click', ML.showNextPost);
	} else if( ML.nextLink ) {
		jQuery('#main-txt-c').append('<a class="next navlnk" href="' + ML.nextLink + '#first"><span>Volgende post</span></a>');
	} else {
		jQuery('#main-txt-c').append('<div class="next navlnk"><span>Volgende post</span></div>');
	}

	if( ML.curPost < ML.ldPostCount - 1 ) {
		jQuery('#archive').append('<a class="prev navlnk"><span>Vorige post</span></a>');
		jQuery('#archive').find('.navlnk.prev').bind('click', ML.showPrevPost);
	} else if( ML.prevLink ) {
		jQuery('#archive').append('<a class="prev navlnk" href="' + ML.prevLink + '"><span>Vorige post</span></a>');
	} else {
		jQuery('#archive').append('<div class="prev navlnk"><span>Vorige post</span></div>');
	}

	if( 0 < ML.curPost ) {
		jQuery('#archive').append('<a class="next navlnk"><span>Volgende post</span></a>');
		jQuery('#archive').find('.navlnk.next').bind('click', ML.showNextPost);
	} else if( ML.nextLink ) {
		jQuery('#archive').append('<a class="next navlnk" href="' + ML.nextLink + '#first"><span>Volgende post</span></a>');
	} else {
		jQuery('#archive').append('<div class="next navlnk"><span>Volgende post</span></div>');
	}

	jQuery('#archive a.navlnk').bind('mousedown', function() { jQuery(this).addClass('mousedown'); });
	jQuery('#archive a.navlnk').bind('mouseup', function() { jQuery(this).removeClass('mousedown'); });

	return true;
};
//----------------------------------------------------------------------------------------------------------------------
ML.addThumbnail = function (pid, imgUrl, title, lnk)
{
	ML.thumbnailIndex += 1;

	var a = jQuery('<a href="' + (lnk ? lnk : '#post_' + pid) + '" style="background-image: url(\'' + imgUrl + '\');" class="lnk" data-idx="' + ML.thumbnailIndex + '"></a>'),
		d = jQuery('<div data-idx="' + ML.thumbnailIndex + '"></div>'),
		s = jQuery('<span></span>'),
		h = jQuery('#archive-hovers');

	s.text(title); a.append(s);
	d.append(s.clone()); h.append(d);

	jQuery('#archive').prepend(a);
	a.bind('click', function() {
		ML.hideArchive();
		jQuery(this).blur();
	});
};
//----------------------------------------------------------------------------------------------------------------------
ML.doneThumbnails = function()
{
	var list = jQuery('#archive a'), h = jQuery('#archive-hovers');

	list.each(function() {
		var $this = jQuery(this), o = $this.offset(), d = h.find('div[data-idx="' + $this.attr('data-idx') + '"]');

		$this.attr({'data-top': o.top, 'data-left': o.left});
		d.css({top: o.top - 70, left: o.left - 55});
	});

	list.hover(
		function(){
			var $this = jQuery(this), d = h.find('div[data-idx="' + $this.attr('data-idx') + '"]'),
				l = $this.attr('data-left'), t = $this.attr('data-top');

			d.css({display: 'block', opacity: 0})
				.stop().animate(
					{opacity: 1, top: t - 80}, 
					{duration: 400}
				);
		},
		function(){
			var $this = jQuery(this), d = h.find('div[data-idx="' + $this.attr('data-idx') + '"]'),
				l, t;

			if( !ML.isArchiveOpen ) {
				d.hide();
				return;
			}

			t = $this.attr('data-top');

			d.stop().animate(
				{opacity: 0, top: t - 70},
				{
					queue: false,
					duration: 400,
					complete: function(){
						d.css('display', 'none');
					}
				}
			);
		}
	);
};
//----------------------------------------------------------------------------------------------------------------------
ML.toggleArchive = function()
{
	if( ML.isArchiveOpen ) {
		ML.hideArchive();
	} else {
		ML.showArchive();
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.showArchive = function()
{
	if( ML.isArchiveMoving ) {
		return;
	}

	var post, a, o;

	ML.isArchiveMoving = true;
	ML.isArchiveOpen = true;

	post = jQuery('#post-list li:eq(' + ML.curPost + ')');
	a = jQuery('#archive a[href="#post_' + post.attr('data-id') + '"]');
	if( a.length ) {
		o = a.position();
		jQuery('#archive-ar').animate({left: 85 + o.left});
	}

	jQuery('#main-txt-footer div.archive-text').css('text-decoration', 'underline');

	jQuery('#main-txt-footer').animate({height: 105});
	jQuery('#archive-ar').animate({bottom: 86}, {queue: false});
	jQuery('#main-txt-footer-hide').animate({height: 61}, function() {
		ML.isArchiveMoving = false;
	});
};
//----------------------------------------------------------------------------------------------------------------------
ML.hideArchive = function()
{
	if( ML.isArchiveMoving ) {
		return;
	}

	ML.isArchiveMoving = true;
	ML.isArchiveOpen = false;

	jQuery('#main-txt-footer div.archive-text').css('text-decoration', '');

	jQuery('#main-txt-footer-hide').animate({height: 0});
	jQuery('#archive-ar').animate({bottom: 29, left: 350}, {queue: false});
	jQuery('#main-txt-footer').animate({height: 48}, function() {
		ML.isArchiveMoving = false;
	});
};
//----------------------------------------------------------------------------------------------------------------------
ML.archiveArrowDrop = function(slow)
{
	if( slow ) {
		jQuery('#archive-ar .imgdiv')
			.css({backgroundPosition: '10px -10px'})
			.animate({backgroundPosition: '10px -3px'}, {duration: 600, queue:false});
	} else {
		jQuery('#archive-ar .imgdiv').css({backgroundPosition: '10px -3px'});
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.archiveArrowOver = function()
{
	jQuery('#archive-ar .imgdiv').animate({backgroundPosition: '10px 0px'}, {duration: 200, queue:false});
};
//----------------------------------------------------------------------------------------------------------------------
ML.archiveArrowOut = function(slow)
{
	jQuery('#archive-ar .imgdiv').animate({backgroundPosition: '10px -3px'}, {duration: 600, queue:false});
};
//----------------------------------------------------------------------------------------------------------------------
ML.startTweets = function()
{
	var c = jQuery('#main-vis.twit').find('li').length;

	jQuery('#main-vis.twit').css('height', jQuery(window).height() - jQuery('#main-txt').height());

	ML.addBarsToTweets();

	ML.curTweet = jQuery('#main-vis.twit li:hidden').length;
	ML.tweetTimer = window.setInterval(ML.nextTweet, 1000);
};
//----------------------------------------------------------------------------------------------------------------------
ML.resizeTweets = function()
{
	jQuery('#main-vis.twit').css('height', jQuery(window).height() - jQuery('#main-txt').height());
};
//----------------------------------------------------------------------------------------------------------------------
ML.addBarsToTweets = function()
{
	var c, marginLeft, marginTop, imgW, imgH;

	c = jQuery('#main-vis.twit div.twit-cont');
	marginLeft = c.offset().left;
	imgW = c.width();
	imgH = c.height();

	jQuery('#leftbar').css({
		left: (marginLeft - 365) + 'px',
		top: '0px',
		height: imgH + 'px'
	}).show();
	jQuery('#rightbar').css({
		left: (marginLeft + imgW) + 'px',
		top: '0px',
		height: imgH + 'px'
	}).show();
};
//----------------------------------------------------------------------------------------------------------------------
ML.stopTweets = function()
{
	window.clearInterval(ML.tweetTimer);
};
//----------------------------------------------------------------------------------------------------------------------
ML.nextTweet = function(isFirst)
{
	var t = jQuery('#main-vis.twit');

	if( ML.curTweet < 0 ) {
		ML.stopTweets();
		return;
	}

	ML.curTweet -= 1;

	t.find('li:eq(' + ML.curTweet + ')').fadeIn();
};
//----------------------------------------------------------------------------------------------------------------------
ML.showSmall = function(data)
{
	var i, r;

	jQuery('#main-txt-cnt').append('<div class="first column"></div><div class="second column"></div><div class="third column"></div><div class="fourth column"></div>');

	ML.showSmallColumn = 0;
	ML.showSmallColumnFirst = true;
	ML.showSmallColumnMap = {
		0: jQuery('#main-txt-cnt div.first'),
		1: jQuery('#main-txt-cnt div.second'),
		2: jQuery('#main-txt-cnt div.third'),
		3: jQuery('#main-txt-cnt div.fourth')
	};

	ML.showSmallColumnHeight = {
		0: 205,
		1: 205,
		2: 190,
		3: 100000
	};

	ML.showSmallNode = ML.showSmallColumnMap[ML.showSmallColumn];
	ML.showSmallNodePath = [ML.showSmallNode];

	for(i = 0; i < data.length; i += 1) {
		r = ML.showSmallPart(data.eq(i));
		if( !r ) {
			return;
		}
	}
};
//----------------------------------------------------------------------------------------------------------------------
ML.showSmallPart = function(data)
{
	var i, j, r, node, list, list2, old, col, a;

	if( '#text' === data.get(0).nodeName.toLowerCase() ) {
		list = data.text().split(' ');
		for(i = 0; i < list.length; i += 1) {
			node = ML.showSmallNode.get(0);
			old = node.innerHTML;

			if( ML.showSmallColumnFirst ) {
				node.innerHTML = '<span class="firstLet">' + list[i].substring(0, 1) + '</span>' + list[i].substring(1);
				ML.showSmallColumnFirst = false;
			} else {
				node.innerHTML += ' ' + list[i];
			}

			col = ML.showSmallColumnMap[ML.showSmallColumn];
			if( ML.showSmallColumnHeight[ML.showSmallColumn] < col.height() ) {
				//Reset text
				node.innerHTML = old;

				//Clean up the last nodes
				list2 = [];
				for(j = 0; j < ML.showSmallNodePath.length; j += 1) {
					list2.push(ML.showSmallNodePath[j].clone());
				}

				while( '' === ML.showSmallNode.text() ) {
					ML.showSmallNode.remove();

					ML.showSmallNodePath.pop();
					ML.showSmallNode = ML.showSmallNodePath[ML.showSmallNodePath.length - 1];
				}

				col.find('p:last').addClass('last');

				if( 2 === ML.showSmallColumn ) {
					a = jQuery('<span class="readmore">&hellip; <a class="readmore">Lees verder</a></span>');
					a.bind('click', ML.textFull);

					col.append(a);
				}

				//Next column
				ML.showSmallColumn += 1;

				col = ML.showSmallColumnMap[ML.showSmallColumn];

				//Pick the column
				ML.showSmallNode = col;
				ML.showSmallNodePath = [col];

				//Rebuild the nodes path. Skip the first one, that's the column
				for(j = 1; j < list2.length; j += 1) {
					node = list2[j].clone();
					node.empty();

					ML.showSmallNode.append(node);

					ML.showSmallNode = node;
					ML.showSmallNodePath.push(node);
				}

				col.find('p:first').addClass('first');

				//Readd the word to the next column
				ML.showSmallNode.get(0).innerHTML += ' ' + list[i];
			}
		}
	} else {
		node = data.clone();
		node.empty();

		ML.showSmallNode.append(node);

		ML.showSmallNode = node;
		ML.showSmallNodePath.push(node);

		//Add a first class here so the margin style gets applied
		col = ML.showSmallColumnMap[ML.showSmallColumn];
		col.find('p:first').addClass('first');

		list = data.contents();
		for(i = 0; i < list.length; i += 1) {
			r = ML.showSmallPart(list.eq(i));
			if( !r ) {
				return false;
			}
		}

		ML.showSmallNodePath.pop();
		ML.showSmallNode = ML.showSmallNodePath[ML.showSmallNodePath.length - 1];
	}

	return true;
};
//----------------------------------------------------------------------------------------------------------------------
ML.finishFull = function()
{
	var post, cont, nh1, sca, h;

	post = jQuery('#post-list li:eq(' + ML.curPost + ')');
	nh1 = jQuery('#main-txt-c > h1');
	h = post.find('a.perm').attr('href');

	sca = jQuery('<div id="show-comments">{<a>' + post.attr('data-cc') + ' comment(s)</a>}</div>');
	sca.find('a').bind('click', ML.showComments);

	cont = jQuery('#main-txt-cnt');
	cont.append(
			'<a href="http://twitter.com/share" class="twitter-share-button" data-url="' +
			h + '" data-text="' + nh1.text() +
			'" data-count="none" data-via="mlanting">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>')
		.append(
			'<iframe class="fb" src="http://www.facebook.com/plugins/like.php?href=' + 
			encodeURIComponent(h) +
			'&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true"></iframe>')
		.append('<div id="g-plusone"></div>')
		.append(
			'<a href="./?feed=rss2" class="rss"><img src="./wp-content/themes/mennolanting/img/rss.png" width="20" height="20" /></a>'
		)
		.append(sca);

	gapi.plusone.render('g-plusone', {size: 'medium', count: 'false', href: h});

	cont.columnize({columns: 3});
	cont.find('.column').css('width', '280px');
};
//----------------------------------------------------------------------------------------------------------------------
ML.showComments = function()
{
	var post = jQuery('#post-list li:eq(' + ML.curPost + ')');

	jQuery.ajax({
		url: 'index.php',
		data: {
			action: 'cpage_ajax',
			post: post.attr('data-id'),
			commentPage: 1
		},
		dataType: 'text',
		success: function(d, t, x) {
			var w = jQuery('<div id="comment-wrap"></div>'),
				l = jQuery('<div id="comment-list"></div>'),
				c = jQuery('<div id="post-comment"></div>'),
				u = jQuery('<ul></ul>');

			c.append(jQuery('#comments-src .comments').clone());
			c.find('input[name="comment_post_ID"]').attr('value', post.attr('data-id'));

			u.append(d);
			l.append(u);
			w.append(l);
			w.append(c);

			jQuery('#main-txt-cnt div.column').fadeOut();
			jQuery('#main-txt-cnt').append(w);

			ACP.setup();
		}
	});
};
//----------------------------------------------------------------------------------------------------------------------
ML.showHeader = function(data)
{
	var fs, nh1;

	if( 'H1' === data.get(0).nodeName ) {
		jQuery('#main-txt-c').append(data);
	} else {
		jQuery('#main-txt-c > h1')
			.empty()
			.append(data);
	}

	fs = 60; nh1 = jQuery('#main-txt-c > h1');
	while( 60 < nh1.height() ) {
		nh1.css('font-size', fs + 'px');
		fs -= 5;
	}
	nh1.css('margin-top', (((60 - nh1.height()) / 2) + 10) + 'px');
	if( nh1.height() < 30 ) {
		nh1.css('height', '30px');
	}
};
//----------------------------------------------------------------------------------------------------------------------

