﻿//Developed By: Abhinay Rathore
//Blog: web3o.blogspot.com
$(function() { //initialize Tree Menu when page loads...
	//For all nodes with children under tree: hide all child nodes initially and change list image
	$('.tree li:has(ul)').css({ cursor: 'pointer', 'list-style-image': 'url(../images/plus.gif)' }).children().hide();
	//Assign Click event to all nodes with children
	$('.tree li:has(ul)').click(function(event) {
		if (this == event.target) { //if target element of the event matches 'this'
			//toggle list image and show/hide children using toggle('fast') method
			$(this).css('list-style-image', ($(this).children().is(':hidden')) ? 'url(../images/minus.gif)' : 'url(../images/plus.gif)');
			$(this).children().toggle('fast');
		}
		return false;
	});

	$('.coltree li:has(ul)').css({ cursor: 'pointer' }).children().hide();
	$('.coltree li:has(ul)').click(function(event) {
		if (this == event.target) { //if target element of the event matches 'this'
			//toggle list image and show/hide children using toggle('fast') method
			$(this).children().toggle('fast');
		}
		return false;
	});
	//For all nodes with no children remove click event
	//$('.tree li:not(:has(ul))').unbind('click');

	//For all nodes with no children: change list image to blank
	$('.tree li:not(:has(ul))').css({ cursor: 'pointer', 'list-style-image': 'url(../images/blank.gif)' });
	//remove click event for every last child
	//$('.tree li:last-child').unbind('click');
});
//Expand all tree nodes
function ExpandTree() {
	$('.tree li:has(ul)').css('list-style-image', 'url(../images/minus.gif)');
	$('.tree li:has(ul)').children().show('normal');
}
//Contract all tree nodes
function ContractTree() {
	$('.tree li:has(ul)').css('list-style-image', 'url(../images/plus.gif)');
	$('.tree li:has(ul)').children().hide('normal');
}
//Toggle all tree nodes
function ToggleTree() {
	$('.tree li:has(ul)').click();
} 