var glyph_opts = {
  	preset: "bootstrap3",
  	map: {
  	}
};

function initFancyTree(selector) {
	$(selector).fancytree({
		extensions: ["dnd5", "edit", "glyph", "wide"],
		checkbox: true,
		selectMode: 3,
		dnd5: {
			dragStart: function(node, data) {
				return true;
			},
			dragEnter: function(node, data) {
				return true;
			},
			dragDrop: function(node, data) {
				data.otherNode.copyTo(node, data.hitMode);
			}
		},
		glyph: glyph_opts,
	  	// source: {url: "ajax-tree-taxonomy.json", debugDelay: 1000},
	  	source: {
	  		url: "ajax-tree-products.json",
	  		debugDelay: 1000
	  	},
	  	// toggleEffect: { effect: "drop", options: {direction: "left"}, duration: 400 },
	  	wide: {
			iconWidth: "1em",       // Adjust this if @fancy-icon-width != "16px"
			iconSpacing: "0.5em",   // Adjust this if @fancy-icon-spacing != "3px"
			labelSpacing: "0.1em",  // Adjust this if padding between icon and label != "3px"
			levelOfs: "1.5em"       // Adjust this if ul padding != "16px"
		},

		icon: function(event, data) {
			// if( data.node.isFolder() ) {
			//   return "glyphicon glyphicon-book";
			// }
		},
		lazyLoad: function(event, data) {
			data.result = {
				url: "ajax-sub2.json",
				debugDelay: 1000
			};
		}
	});
}

function initFancyTreeTable(selector) {
	$(selector).fancytree({
		extensions: ["dnd5", "edit", "glyph", "table"],
		checkbox: true,
		dnd5: {
			dragStart: function(node, data) {
				return true;
			},
			dragEnter: function(node, data) {
				return true;
			},
			dragDrop: function(node, data) {
				data.otherNode.copyTo(node, data.hitMode);
			}
		},
		glyph: glyph_opts,
		source: {
			url: "ajax-tree-taxonomy.json",
			debugDelay: 1000
		},
		table: {
			checkboxColumnIdx: 1,
			nodeColumnIdx: 2
		},
		activate: function(event, data) {
		},
		lazyLoad: function(event, data) {
			data.result = {
				url: "ajax-sub2.json",
				debugDelay: 1000
			};
		},
		renderColumns: function(event, data) {
			var node = data.node,
			$tdList = $(node.tr).find(">td");
			$tdList.eq(0).text(node.getIndexHier());
			$tdList.eq(3).text(!!node.folder);
		}
	});	
}

$(function() {

});
