/**
 * JavaScript to integrate document browsing and selection with the editor.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2012 fusionLib. All rights reserved.
 * @link http://clearfusioncms.com
 */

$fl(document).ready(function() {
	$fl('.treeviewwidget a').bind('click', function(evt) {
		var tgt = evt.target.tagName != 'A' ? $fl(evt.target).parent().attr('href').replace(/^#/, '') : $fl(evt.target).attr('href').replace(/^#/, '');
		var txt = $fl(evt.target).html().replace(/\s+\[\d+\]$/, '');
		parent.oUtil.obj.insertHTML('<a href="' + tgt + '">' + txt + '</a>');
		evt.preventDefault();
		evt.stopPropagation();
		return false;
	});
});