// Title: Tigra Tree
// Description: See the demo at url
// URL: http://www.softcomplex.com/products/tigra_menu_tree/
// Version: 1.1 (size optimized)
// Date: 11-12-2002 (mm-dd-yyyy)
// Notes: This script is free. Visit official site for further details.
/*
function tree(tm0,tm1){this.tm2=tm1;this.tm3=tm0;this.tm4=this;this.tm5=[];this.tm6=null;this.tm7=-1;var tm8=new Image(),tm9=new Image();tm8.src=tm1['icon_e'];tm9.src=tm1['icon_l'];tm1['im_e']=tm8;tm1['im_l']=tm9;for(var i=0;i<64;i++)if(tm1['icon_'+i]){var tmA=new Image();tm1['im_'+i]=tmA;tmA.src=tm1['icon_'+i]}this.tmB=function(tmC){var tmD=this.tm5[tmC];tmD.tmE(tmD.tmF)};this.tmG=function(tmC){return this.tm5[tmC].tmG()};this.tmH=function(tmC){this.tm5[tmC].tmI(true)};this.tmJ=function(tmC){this.tm5[tmC].tmI()};this.tmK=[];for(var i=0;i<tm0.length;i++)new tmL(this,i);this.tmC=trees.length;trees[this.tmC]=this;for(var i=0;i<this.tmK.length;i++){document.write(this.tmK[i].tmM());this.tmK[i].tmE()}}function tmL(tmN,tmO){this.tm7=tmN.tm7+1;this.tm3=tmN.tm3[tmO+(this.tm7?2:0)];if(!this.tm3)return;this.tm4=tmN.tm4;this.tmN=tmN;this.tmO=tmO;this.tmF=!this.tm7;this.tmC=this.tm4.tm5.length;this.tm4.tm5[this.tmC]=this;tmN.tmK[tmO]=this;this.tmK=[];for(var i=0;i<this.tm3.length-2;i++)new tmL(this,i);this.tmP=tmQ;this.tmE=tmR;this.tmG=tmS;this.tmM=tmT;this.tmI=tmU;this.tmV=function(){return this.tmO==this.tmN.tmK.length-1}}function tmR(tmW){var tmX=tmY('i_div'+this.tm4.tmC+'_'+this.tmC);if(!tmX)return;if(!tmX.innerHTML){var tmK=[];for(var i=0;i<this.tmK.length;i++)tmK[i]=this.tmK[i].tmM();tmX.innerHTML=tmK.join('')}tmX.style.display=(tmW?'none':'block');this.tmF=!tmW;var tmZ=document.images['j_img'+this.tm4.tmC+'_'+this.tmC],tma=document.images['i_img'+this.tm4.tmC+'_'+this.tmC];if(tmZ)tmZ.src=this.tmP(true);if(tma)tma.src=this.tmP();this.tmI()}function tmS(tmb){if(!tmb){var tmc=this.tm4.tm6;this.tm4.tm6=this;if(tmc)tmc.tmG(true)}var tma=document.images['i_img'+this.tm4.tmC+'_'+this.tmC];if(tma)tma.src=this.tmP();tmY('i_txt'+this.tm4.tmC+'_'+this.tmC).style.fontWeight=tmb?'normal':'bold';this.tmI();return Boolean(this.tm3[1])}function tmU(tmd){window.setTimeout('window.status="'+(tmd?'':this.tm3[0]+(this.tm3[1]?' ('+this.tm3[1]+')':''))+'"',10)}function tmT(){var tme=[],tmf=this.tmN;for(var i=this.tm7;i>1;i--){tme[i]='<img src="'+this.tm4.tm2[tmf.tmV()?'icon_e':'icon_l']+'" border="0" align="absbottom">';tmf=tmf.tmN}return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap>'+(this.tm7?tme.join('')+(this.tmK.length?'<a href="javascript: trees['+this.tm4.tmC+'].tmB('+this.tmC+')" onmouseover="trees['+this.tm4.tmC+'].tmJ('+this.tmC+')" onmouseout="trees['+this.tm4.tmC+'].tmH('+this.tmC+')"><img src="'+this.tmP(true)+'" border="0" align="absbottom" name="j_img'+this.tm4.tmC+'_'+this.tmC+'"></a>':'<img src="'+this.tmP(true)+'" border="0" align="absbottom">'):'')+'<a href="'+this.tm3[1]+'" target="'+this.tm4.tm2['target']+'" onclick="return trees['+this.tm4.tmC+'].tmG('+this.tmC+')" ondblclick="trees['+this.tm4.tmC+'].tmB('+this.tmC+')" onmouseover="trees['+this.tm4.tmC+'].tmJ('+this.tmC+')" onmouseout="trees['+this.tm4.tmC+'].tmH('+this.tmC+')" class="t'+this.tm4.tmC+'i" id="i_txt'+this.tm4.tmC+'_'+this.tmC+'"><img src="'+this.tmP()+'" border="0" align="absbottom" name="i_img'+this.tm4.tmC+'_'+this.tmC+'" class="t'+this.tm4.tmC+'im">'+this.tm3[0]+'</a></td></tr></table>'+(this.tmK.length?'<div id="i_div'+this.tm4.tmC+'_'+this.tmC+'" style="display:none"></div>':'')}function tmQ(tmg){return this.tm4.tm2['icon_'+((this.tm7?0:32)+(this.tmK.length?16:0)+(this.tmK.length&&this.tmF?8:0)+(!tmg&&this.tm4.tm6==this?4:0)+(tmg?2:0)+(tmg&&this.tmV()?1:0))]}var trees=[];tmY=document.all?function(tmh){return document.all[tmh]}:function(tmh){return document.getElementById(tmh)};
*/
function tree (a_items, a_template, a_unfold) {

	this.a_tpl      = a_template;
	this.a_config   = a_items;
	this.o_root     = this;
	this.a_index    = [];
	this.o_selected = null;
	this.n_depth    = -1;
	
	var o_icone = new Image(),
		o_iconl = new Image();
	o_icone.src = a_template['icon_e'];
	o_iconl.src = a_template['icon_l'];
	a_template['im_e'] = o_icone;
	a_template['im_l'] = o_iconl;
	for (var i = 0; i < 64; i++)
		if (a_template['icon_' + i]) {
			var o_icon = new Image();
			a_template['im_' + i] = o_icon;
			o_icon.src = a_template['icon_' + i];
		}
	
	this.toggle = function (n_id) {	var o_item = this.a_index[n_id]; o_item.open(o_item.b_opened) };
	this.select = function (n_id) { return this.a_index[n_id].select(); };
	this.mout   = function (n_id) { /*this.a_index[n_id].upstatus(true) */};
	this.mover  = function (n_id) { /*this.a_index[n_id].upstatus() */ };

	this.a_children = [];
	for (var i = 0; i < a_items.length; i++)
		new tree_item(this, i);

	this.n_id = trees.length;
	trees[this.n_id] = this;
	
	for (var i = 0; i < this.a_children.length; i++) {
		document.write(this.a_children[i].init());
		this.a_children[i].open();
	}
    //unfolder
    if (a_unfold.length > 0) {
        for (var i = 1; i < this.a_index.length; i++)
            for (var j = 1; j < a_unfold.length; j++)
                if ( i == a_unfold[j] )
                    this.toggle(i);
    }
}
function tree_item (o_parent, n_order) {

	this.n_depth  = o_parent.n_depth + 1;
	this.a_config = o_parent.a_config[n_order + (this.n_depth ? 2 : 0)];
	if (!this.a_config) return;

	this.o_root    = o_parent.o_root;
	this.o_parent  = o_parent;
	this.n_order   = n_order;
	this.b_opened  = !this.n_depth;

	this.n_id = this.o_root.a_index.length;
	this.o_root.a_index[this.n_id] = this;
	o_parent.a_children[n_order] = this;

	this.a_children = [];
	for (var i = 0; i < this.a_config.length - 2; i++)
		new tree_item(this, i);

	this.get_icon = item_get_icon;
	this.open     = item_open;
	this.select   = item_select;
	this.init     = item_init;
	//this.upstatus = item_upstatus;
	this.is_last  = function () { return this.n_order == this.o_parent.a_children.length - 1 };
}

function item_open (b_close) {
	var o_idiv = get_element('i_div' + this.o_root.n_id + '_' + this.n_id);
	if (!o_idiv) return;
	
	if (!o_idiv.innerHTML) {
		var a_children = [];
		for (var i = 0; i < this.a_children.length; i++)
			a_children[i]= this.a_children[i].init();
		o_idiv.innerHTML = a_children.join('');
	}
	o_idiv.style.display = (b_close ? 'none' : 'block');
	
	this.b_opened = !b_close;
	var o_jicon = document.images['j_img' + this.o_root.n_id + '_' + this.n_id],
		o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id];
	if (o_jicon) o_jicon.src = this.get_icon(true);
	if (o_iicon) o_iicon.src = this.get_icon();
	//this.upstatus();
}

function item_select (b_deselect) {
	if (!b_deselect) {
		var o_olditem = this.o_root.o_selected;
		this.o_root.o_selected = this;
		if (o_olditem) o_olditem.select(true);
	}
	var o_iicon = document.images['i_img' + this.o_root.n_id + '_' + this.n_id];
	if (o_iicon) o_iicon.src = this.get_icon();
	get_element('i_txt' + this.o_root.n_id + '_' + this.n_id).style.fontWeight = b_deselect ? 'normal' : 'bold';
	
	//this.upstatus();
	return Boolean(this.a_config[1]);
}

function item_upstatus (b_clear) {
	//window.setTimeout('window.status="' + (b_clear ? '' : this.a_config[0] + (this.a_config[1] ? ' ('+ this.a_config[1] + ')' : '')) + '"', 10);
}

function item_init () {
	unfold_target = UNFOLD_ITEMS[UNFOLD_ITEMS.length-1];
	var a_offset = [],
		o_current_item = this.o_parent;
	for (var i = this.n_depth; i > 1; i--) {
		a_offset[i] = '<img style="float: left" src="' + this.o_root.a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absmiddle" width=8 height='+(this.a_config[0]=='Products & Factories'?'30':'30')+'>';
		o_current_item = o_current_item.o_parent;
	}
	return '<table width="242" cellpadding="0" cellspacing="0" border="0" style="border-top:1px solid white;'+(this.n_id==unfold_target?'background:#000099;':'')+'"><tr><td nowrap valign="middle" onmouseover="this.style.background=\'#333399\';" onmouseout="this.style.background=\'\';">' + (this.n_depth ? a_offset.join('') + (this.a_children.length
		? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + this.n_id + ');" onmouseout="trees[' + this.o_root.n_id + '].mout(' + this.n_id + ');" style="display: block; text-decoration:none;"><img style="float: left" src="' + this.get_icon(true) + '" border="0" align="absbottom" name="j_img' + this.o_root.n_id + '_' + this.n_id + '" width=8 height='+(this.a_config[0]=='Products & Factories'?'30':'30')+'></a>'
		: '<img style="float: left;" src="' + this.get_icon(true) + '" border="0" align="absbottom" width=8 height='+(this.a_config[0]=='Products & Factories'?'30':'30')+'>') : '') 
		+ (this.a_children.length && this.n_id > 0
		   ? '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="this.style.fontWeight=\'bold\';trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="this.style.fontWeight=\'normal\';trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" onfocus="this.blur();" style="display: block; text-decoration:none;">'
		   : '<a href="' + this.a_config[1] + '" target="' + (this.a_config[0]=='Jan' || this.a_config[0]=='Feb' || this.a_config[0]=='Mar' || this.a_config[0]=='Apr' || this.a_config[0]=='May' || this.a_config[0]=='Jun' || this.a_config[0]=='Jul' || this.a_config[0]=='Aug' || this.a_config[0]=='Sep' || this.a_config[0]=='Oct' || this.a_config[0]=='Nov' || this.a_config[0]=='Dec' ?'newsletter':this.o_root.a_tpl['target']) + '" onclick="return trees[' + this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="this.style.fontWeight=\'bold\';trees[' + this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="this.style.fontWeight=\'normal\';trees[' + this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + this.o_root.n_id + 'i" id="i_txt' + this.o_root.n_id + '_' + this.n_id + '"  style="display: block; text-decoration:none;">')
		+ '<img style="" src="' + this.get_icon() + '" border="0" align="absmiddle" name="i_img' + this.o_root.n_id + '_' + this.n_id + '" class="t' + this.o_root.n_id + 'im" width=8 height='+(this.a_config[0]=='Products & Factories'?'30':'30')+'><span style="color:white;text-decoration:none;font-size:14;'+(this.a_config[0]=='PRODUCT RANGES' || this.a_config[0]=='Search Products & Factories'?'font-weight:bold;':'')+'">' + this.a_config[0] + '</span></a></td></tr></table>' + (this.a_children.length ? '<div id="i_div' + this.o_root.n_id + '_' + this.n_id + '" style="display:none"></div>' : '');
}

function item_get_icon (b_junction) {
	return this.o_root.a_tpl['icon_' + ((this.n_depth ? 0 : 32) + (this.a_children.length ? 16 : 0) + (this.a_children.length && this.b_opened ? 8 : 0) + (!b_junction && this.o_root.o_selected == this ? 4 : 0) + (b_junction ? 2 : 0) + (b_junction && this.is_last() ? 1 : 0))];
}

var trees = [];
get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };
