$(function()
{
	if('none' != $("#locationContainer").css('display'))
	{
		$("#locationChangeLable").text(intelli.lang.apply);
	}
	else
	{
		$("#locationChangeLable").text(intelli.lang.change);
	}

	$("#locationChangeLable").click(function()
	{
		if('none' != $("#locationContainer").css('display'))
		{
			$("#locationChangeLable").text(intelli.lang.change);
			intelli.display($("#locationContainer"), 'hide');
		}
		else
		{
			$("#locationChangeLable").text(intelli.lang.apply);
			intelli.display($("#locationContainer"), 'show');
		}

		return false;
	});

	/* Setting up the tree categories */
	var treeLocations = new intelli.tree({
		id: 'location_box',
		type: 'radio',
		hideRoot: true,
		menuType: intelli.config.categories_tree_type,
		url: 'controller.php?plugin=locations&file=get-locations',
		dropdownInputId: 'locations',
		dropdownItemId: 'location_dropdown',
		callback: function()
		{
			$("#location_id").val($(this).val());
			$("#locationTitle > strong").text($(this).attr('title'));
		},
		dropDownCallback: function(id, title)
		{
			$("#location_id").val(id);
			$("#locationTitle > strong").text(title);
		}
	});

	treeLocations.init();
});

