// JavaScript Document
//<%= IconBase %>
$(document).ready(function(){
	//expand
	$("a[id*='assetTreeShaderExpand']").click(function(){
				//groups - not locators
				$("ul.assetTreeS ul").not("[id*='Locator']").show();
				//$("img.assetTreeShaderArrow").parent().children("ul").show();
				$("img.assetTreeShaderArrow").attr('src',iconBase + 'arrowopen.png');
	});
	
	//collapse
	$("a[id*='assetTreeShaderCollapse']").click(function(){
				//groups and locators
				$("ul.assetTreeS ul").hide();
				//$("img[class*='assetTreeShader']").parent().children("ul").hide();
				$("img.assetTreeShaderArrow").attr('src',iconBase + 'arrowclosed.png');
				$("img.assetTreeShaderPlus").attr('src',iconBase + 'plus.png');
	});

	//expand
	$("a[id*='assetTreeItemExpand']").click(function(){
				//groups - not locators
				$("ul.assetTreeI ul").not("ul[id*='assetTreeChanMod']").not("ul[id*='assetTreeLayer']").show();
				//$("img.assetTreeShaderArrow").parent().children("ul").show();
				$("img.assetTreeItemArrow").attr('src',iconBase + 'arrowopen.png');
	});
	
	//collapse
	$("a[id*='assetTreeItemCollapse']").click(function(){
				//groups and locators
				$("ul.assetTreeI ul").not("#assetTreeItemGroup\\:root").hide();
				//$("img[class*='assetTreeShader']").parent().children("ul").hide();
				$("img.assetTreeItemArrow").attr('src',iconBase + 'arrowclosed.png');
				$("img.assetTreeItemPlus").attr('src',iconBase + 'plus.png');
				$("ul[id*='assetTreeLayer']").hide();
	});

	
	$("span[id*='assetTreeItem']").click(function () {
		$("span[id*='assetTreeItem']").removeClass('layerSelect');
		$(this).addClass('layerSelect');
		$("ul[id*='assetTreeLayer']").hide();
		var idparts = ($(this).attr("id")).split(":");
		$("#assetTreeLayer\\:" + idparts[1]).show(); //.slideUp("fast");

	});
	
	$("img.assetTreeItemArrow").click(function() {
		if ($(this).parent().children("ul").not("ul[id*='assetTreeChanModGroup']").is(":visible")) {
			$(this).parent().children("ul").not("ul[id*='assetTreeChanModGroup']").hide();
			$(this).attr("src",iconBase + "arrowclosed.png");
		}else {
			$(this).parent().children("ul").not("ul[id*='assetTreeChanModGroup']").show();
			$(this).attr("src",iconBase + "arrowopen.png");
		}
	});

	$("img.assetTreeItemPlus").click(function() {
		if ($(this).parent().children("ul[id*='assetTreeChanModGroup']:first").is(":visible")) {
			$(this).parent().children("ul[id*='assetTreeChanModGroup']:first").hide();
			$(this).attr("src",iconBase + "plus.png");
		}else {
			$(this).parent().children("ul[id*='assetTreeChanModGroup']:first").show();
			$(this).attr("src",iconBase + "minus.png");
		}
	});

	$("img.assetTreeShaderArrow").click(function() {
		if ($(this).parent().children("ul:first").is(":visible")) {
			$(this).parent().children("ul:first").hide(); //.slideUp("fast");
			var idparts = ($(this).parent().children("ul:first").attr("id")).split(":");
			$("#assetTreeShaderEffectGroup\\:" + idparts[1]).hide(); //.slideUp("fast");
			$(this).attr("src",iconBase + "arrowclosed.png");
		}else {
			$(this).parent().children("ul:first").show(); //.slideDown("fast");
			var idparts = ($(this).parent().children("ul:first").attr("id")).split(":");
			$("#assetTreeShaderEffectGroup\\:" + idparts[1]).show(); //.slideDown("fast");
			$(this).attr("src",iconBase + "arrowopen.png");
		}
	});

	$("img.assetTreeShaderPlus").click(function() {
		if ($(this).parent().children("ul:first").is(":visible")) {
			$(this).parent().children("ul:first").hide(); //.slideUp("fast");
			var idparts = ($(this).parent().children("ul:first").attr("id")).split(":");
			$("#assetTreeShaderEffectLocator\\:" + idparts[1]).hide(); //.slideUp("fast");
			$(this).attr("src",iconBase + "plus.png");
		}else {
			$(this).parent().children("ul:first").show(); //.slideDown("fast");
			var idparts = ($(this).parent().children("ul:first").attr("id")).split(":");
			$("#assetTreeShaderEffectLocator\\:" + idparts[1]).show(); //.slideDown("fast");
			$(this).attr("src",iconBase + "minus.png");
		}
	});
	
	//hover over span - not li due to nesting of ul results in hover of top level items highlighting whole tree
	$("ul.assetTreeS li span").hover(
			function(){
				$(this).addClass('layerHover');
				var idparts = ($(this).parent().attr("id")).split(":");
				if (idparts[0].indexOf('Layer') != -1){
					$("li#assetTreeShaderEffect\\:" + idparts[1]).children("span:first").addClass('layerHover');
				}else{
					$("li#assetTreeShaderLayer\\:" + idparts[1]).children("span:first").addClass('layerHover');
				}
				
			},
			function(){
				$(this).removeClass('layerHover');
				var idparts = ($(this).parent().attr("id")).split(":");
				if (idparts[0].indexOf('Layer') != -1){
					$("li#assetTreeShaderEffect\\:" + idparts[1]).children("span:first").removeClass('layerHover');
				}else{
					$("li#assetTreeShaderLayer\\:" + idparts[1]).children("span:first").removeClass('layerHover');
				}
			}
	
	);

	$("ul.assetTreeI li span").hover(
			function(){
				$(this).addClass('layerHover');
			},
			function(){
				$(this).removeClass('layerHover');
			}
	
	);
});
