$(function()
{
	/* Loading the language phrases and script configuration */
	esyndicat.loader({
		lang: 'apply,change'
	});

	/* Setting up the tree categories */
	var treeCat = new esyndicat.tree({
		id: 'tree',
		type: 'radio',
		state: '',
		hideRoot: true,
		callback: function()
		{
			var idCategory = $(this).val();
			var titleCategory = $(this).attr('title');

			$('#category_id').val(idCategory);
			$('#category_title').val(titleCategory);

			$('#categoryTitle > strong').text(titleCategory);
		}
	});

	/* Initialization tree categories */
	treeCat.init();

	/* Event handler for displaying tree categories */
	$('#changeLabel').click(function()
	{
		esyndicat.display('#treeContainer', 'auto'); 

		if(esyndicat.lang.change == $(this).text())
		{
			$(this).text(esyndicat.lang.apply);
		}
		else
		{
			$(this).text(esyndicat.lang.change);
		}
	});
});

