/*
	Feel free to use your custom icons for the tree. Make sure they are all of the same size.
	If you don't use some keys you can just remove them from this config
*/

var TREE_TPL = {

	// general
	'target':'_self',				// name of the frame links will be opened in
						   	// other possible values are:
						   	// _blank, _parent, _search, _self and _top

	// icons - root	
	'icon_48':'Assets/Icons/base.gif', 		// root icon normal
	'icon_52':'Assets/Icons/basesel.gif', 		// root icon selected
	'icon_56':'Assets/Icons/base.gif', 		// root icon opened
	'icon_60':'Assets/Icons/basesel.gif', 		// root icon selected opened

	// icons - node	
	'icon_16':'Assets/Icons/folder.gif', 		// node icon normal
	'icon_20':'Assets/Icons/folderopen.gif',  	// node icon selected
	'icon_24':'Assets/Icons/folderopen.gif',  	// node icon opened
	'icon_28':'Assets/Icons/folderopen.gif',  	// node icon selected opened

	'icon_80':'Assets/Icons/folderopenover.gif',  	// mouse over node icon normal

	// icons - leaf
	'icon_0':'Assets/Icons/webpage.gif', 		// leaf icon normal
	'icon_4':'Assets/Icons/webpagesel.gif', 	// leaf icon selected
	'icon_64':'Assets/Icons/webpageover.gif', 	// leaf icon mouse over	

	// icons - junctions	
	'icon_2':'Assets/Icons/joinbottom.gif', 	// junction for leaf
	'icon_3':'Assets/Icons/join.gif', 		// junction for last leaf
	'icon_18':'Assets/Icons/plusbottom.gif', 	// junction for closed node
	'icon_19':'Assets/Icons/plus.gif', 		// junctioin for last closed node
	'icon_26':'Assets/Icons/minusbottom.gif', 	// junction for opened node
	'icon_27':'Assets/Icons/minus.gif', 		// junctioin for last opended node

	// icons - misc
	'icon_e':'Assets/Icons/empty.gif', 		// empty image
	'icon_l':'Assets/Icons/line.gif', 		// vertical line
	
	// styles - root
	'style_48':'mout', 				// normal root caption style
	'style_52':'mout', 				// selected root caption style
	'style_56':'mout', 				// opened root caption style
	'style_60':'mout', 				// selected opened root caption style
	'style_112':'mover', 				// mouse over normal root caption style
	'style_116':'mover', 				// mouse over selected root caption style
	'style_120':'mover', 				// mouse over opened root caption style
	'style_124':'mover', 				// mouse over selected opened root caption style
	
	// styles - node
	'style_16':'node', 				// normal node caption style
	'style_20':'node',				// selected node caption style
	'style_24':'node', 				// opened node caption style
	'style_28':'node', 				// selected opened node caption style
	'style_80':'node', 				// mouse over normal node caption style
	'style_84':'node', 				// mouse over selected node caption style
	'style_88':'node', 				// mouse over opened node caption style
	'style_92':'node', 				// mouse over selected opened node caption style

	// styles - leaf
	'style_0':'mout', 				// normal leaf caption style
	'style_4':'mout', 				// selected leaf caption style
	'style_64':'mover', 				// mouse over normal leaf caption style
	'style_68':'mover', 				// mouse over selected leaf caption style
	
	'style_32':'mout', 				// selected leaf caption style
	'style_36':'mout', 				// selected leaf caption style	
	'style_96':'mout', 				// selected leaf caption style
	'style_100':'mout', 				// selected leaf caption style


	// Event handlers - item
	'onItemSelect':'onItemSelectHandler',       	// opens node on single click
	'onItemOpen':'onItemOpenHandler'            	// automatically closes other nodes that are open
	// MAKE SURE THERE IS NOT A COMMA AFTER THE LAST KEY-VALUE PAIR!
};

function collapse_all (n_index, n_depth) {
	 var o_tree = TREES[n_index ? n_index : 0];

	 if (!n_depth) n_depth = 1;
	 if (!o_tree)
	     alert("Tree is not initialized yet");

 	 var a_nodes = o_tree.a_nodes;

 	 for (var i = a_nodes.length - 1; i >= 0; i--)
	      if (a_nodes[i].n_depth >= n_depth && a_nodes[i].open)
		  a_nodes[i].open(1, 1);
	 o_tree.ndom_refresh();
}


function openItemByCaption (s_caption, o_tree) {
      // set to true when debugging the application
	 var B_DEBUG = false;


      // exit if required parameter isn't specified
	 if (!s_caption)
	     return (B_DEBUG
		     ? alert("Required parameter to function openItemByCaption is missing")
		     : false
		    );

      // use first tree on the page if tree object isn't explicitly defined
	 if (!o_tree)
	      o_tree = (TREES[0]);
	 if (!o_tree)
	      return (B_DEBUG
	              ? alert("No Tigra Tree Menu PRO instances can be found on this page")
		      : false
		     );


      // find item with specified caption
         var a_item = o_tree.find_item(s_caption);

         for(var n=0; n < a_item.length; n++) {
	     o_item=a_item[n];

	  // collect info about all item's parents
	     var n_id = o_item.n_id,
		        n_depth = o_item.n_depth,
		        a_index = o_item.o_root.a_index,
		        a_parents = [o_item];

	     while (n_depth) {
	            if (a_index[n_id].n_depth < n_depth) {
		        a_parents[a_parents.length] = a_index[n_id];
		        n_depth--;
	            }
	            n_id--;
	     }

	  // open all parents starting from root
	     for (var i = a_parents.length-1; i >= 0; i--)
	       // check if node or root
	          if (a_parents[i].n_state & 48)
	              a_parents[i].open();
	          else
	              if (B_DEBUG) 
	                  alert("Item with caption '" + a_parents[i].a_config[0]+ 
	                  "' is a leaf.\nHierarchy will be opened to its parent node only.")
        }

     // The following selects the item so the PageSelect icon will display.
        var o_state = o_item.state();
	    o_item.select();
}


function onItemOpenHandler (o_item) {
      // get current block
	 var a_curblock = o_item.o_parent.a_children;
	
      // close all nodes except current
	 for (var i = 0; i < a_curblock.length; i++)
	      if (a_curblock[i].n_state & 48 && a_curblock[i] != o_item)
		  a_curblock[i].open(true);
	 return true;
}


function onItemSelectHandler (o_item) {
      // if node with no link then toggle
         var o_state = o_item.state();
         
         if (o_state['node'] && !o_item.a_config[1]) {
             o_item.o_root.toggle(o_item.n_id);
          
          // cancel default action
             return false;
         }

      // proceed to default handler
         return true;
}


function InfoPopUp(url_pop,ht,adj,off) {

  	 var lef = ((window.screen.width-440)/2) + off;
	 var to = (window.screen.height-(300-adj))/2;

	 DP=window.open(url_pop,'InfoWindow','width=595,height='+ht+',left='+lef+',top='+to);
	 DP.focus();
	
      // setTimeout('DP.close();',12000);	
}
