// Title: Tigra Menu GOLD
// URL: http://www.softcomplex.com/products/tigra_menu_gold/
// Version: 1.3
// Date: 01-03-2003 (mm-dd-yyyy)
// Technical Support: support@softcomplex.com (specify product title and order ID)
// Notes: Registration needed to use this script legally.
// Visit official site for details.

// A path to Tigra Menu GOLD files from the PAGE containinig Menu
var TMenu_path_to_files = 'menu_files/';

// Please, don't change below this line
// ----------------------------------------------------------------------------------
var menus = [], o_doc, states = ['mout', 'mover', 'mdown'], 
actions = ['click', 'mouseout', 'mouseover', 'mousedown'];

document.write ('<scr' + 'ipt language="JavaScript" src="' + TMenu_path_to_files + 'menu.' 
	+ (document.layers ? 'lay' : !window.opera ? 'dom' : 'opr') + '.js"></scr' + 'ipt>')
// 
function doc_load (myfunc) {	
	var s = new String(window.onload), pos;
	if ((pos = s.indexOf("{")) > -1) s = s.substring(pos + 1, s.lastIndexOf("}") - 1)	
	window.onload = Function(s + ";" + myfunc)
}

function doc_redraw () {
	for (var i in menus) {
		menus[i].redraw();
		menus[i].active = true;
	}
}

function doc_update () {
	var n_value, b_refresh;
// verify if any environment paramenters changed
	if (this.width != (n_value = this.f_width(window))) {
		this.width = n_value;
		b_refresh = true;
	}
	if (this.height != (n_value = this.f_height(window))) {
		this.height = n_value;
		b_refresh = true;
	}
	if (this.xscroll != (n_value = this.f_xscroll(window))) {
		this.xscroll = n_value;
		b_refresh = true;
	}
	if (this.yscroll != (n_value = this.f_yscroll(window))) {
		this.yscroll = n_value;
		b_refresh = true;
	}
	if (b_refresh) this.redraw()
	window.setTimeout('o_doc.update()', 500);
}

// --------------------------------------------------------------------------------
// menu class constructor
// --------------------------------------------------------------------------------
function menu (item_struct, geom_struct, frameLayout, key) {
	this.is_master = typeof(frameLayout) == 'object' ? true : false;
	this.item_struct = item_struct;
	this.geom_struct = geom_struct;
//	this.frameLayout  = frameLayout;
	this.items       = [];
	this.children    = [];
	this.over_items  = 0;
	
	this.exec        = menu_exec;
	this.hide        = menu_hide;
	this.onclick     = menu_onclick;
	this.onmouseout  = menu_onmouseout;
	this.onmouseover = menu_onmouseover;
	this.onmousedown = menu_onmousedown;
	this.redraw      = menu_redraw;
	this.build       = menu_build;
	// prepare environment object
	if (!o_doc) o_doc = new doc();
	// register in global menus collection
	this.id = key != null ? key : 
		frameLayout && typeof(frameLayout) != 'object' ? frameLayout : menus.length;
	menus[this.id] = this;

	this.subling = window;
	this.subHTML = '';
	this.child_count = this.item_struct.length;
	this.geom_struct[0].hide_delay = 
		this.geom_struct[0].hide_delay ? Math.max(this.geom_struct[0].hide_delay, 100) : 100

	for (var i = 0; i < this.child_count; i++)
		new menu_item(i, this, this);
	// calculate menu sizes
	this.build(this.geom_struct[0].table ? this.geom_struct[0].table : [0, 0, 0])
	for (i = 0; i < this.child_count; i++) this.children[i].links();
	
	if (top != window) {
		if (!top.TMenu) top.TMenu = [];
		if (!top.TMenu[this.id]) top.TMenu[this.id] = { 'frames' : [] }
		this.sync = top.TMenu[this.id];
		if (this.is_master) {
			this.sync.win = window;	
			this.frameLayout = [];
			for (i in frameLayout) {
				this.frameLayout[i] = [];
				for (var j in frameLayout[i])
					this.frameLayout[i][j] = eval('top.' + frameLayout[i][j]);
			} 
		}
		this.sync.frames[window.name] = window;
	}
	o_doc.onload ("o_doc.update()")
}

// --------------------------------------------------------------------------------
// menu event handlers
// --------------------------------------------------------------------------------
function menu_redraw () {
	if (this.sync) {	
		if (typeof(this.frameLayout) != 'object') {
			if (!this.sync.main) return setTimeout('menus["' + this.id + '"].redraw()', 100);
			this.frameLayout = this.sync.win.menus[this.id].frameLayout
		}
		if (this.is_master) {
			var me, y_shift = 0, x_shift;			
			if (!this.sync.matrix) this.sync.matrix = []
			for (i in this.frameLayout) {
				x_shift = 0;
				for (j in this.frameLayout[i]) {
					this.sync.matrix[this.frameLayout[i][j].name] = {
						'x' : x_shift,
						'y' : y_shift
					}
					if (o_doc.is_IE)
						if (!this.frameLayout[i][j].document.body) 
							return setTimeout('menus["' + this.id + '"].redraw()', 100);
					x_shift += o_doc.f_width(this.frameLayout[i][j]);
				}
				y_shift += o_doc.f_height(this.frameLayout[i][j]);
			}
				
			this.sync.main = o_doc.getOffs(this.main, 
				this.sync.matrix[window.name].x - o_doc.f_xscroll(window), 
				this.sync.matrix[window.name].y - o_doc.f_yscroll(window))

			for (var i in this.sync.frames) 
				if (this.sync.frames[i] != window) this.sync.frames[i].o_doc.redraw()
		}
		else
			o_doc.divMove(this.main, {
				'x' : this.sync.main.x - this.sync.matrix[window.name].x + o_doc.f_xscroll(window), 
				'y' : this.sync.main.y - this.sync.matrix[window.name].y + o_doc.f_yscroll(window)
				}
			)
	}
	for (var i in this.children) 
		this.children[i].pos()
	if (!this.is_master && top != window) o_doc.divBlink(this.main, true)
}

function menu_exec (id, action) {
	if (!this.active) return;
	if (this.sync && action > 0)
		for (var i in this.sync.frames) 
			this.sync.frames[i].menus[this.id]['on' + actions[action]](id)	
	else return menus[this.id]['on' + actions[action]](id)
}

function menu_hide () {
	if (!this.hide_timer || this.over_items || !this.last_item)	return;
	this.last_item.collapse(0);
	this.last_item = null;
}

function menu_onclick (id) {
	var b_go = Boolean(this.items[id].fields[1]);
	if (b_go && this.sync)
		for (var i in this.sync.frames) 
			this.sync.frames[i].menus[this.id].last_item.collapse(0);	
	return b_go;
}

function menu_onmouseout (id) {
	this.over_items--;
	if (this.items[id].expd_timer) clearTimeout(this.items[id].expd_timer);
	this.hide_timer = setTimeout('menus["'+ this.id +'"].hide()',
		this.geom_struct[this.items[id].depth].hide_delay);
}

function menu_onmouseover (id) {
	this.over_items++;
	clearTimeout(this.hide_timer);
	this.hide_timer = null;
	this.items[id].light();
}

function menu_onmousedown (id) {
	this.items[id].set_state('mdown');
}
// --------------------------------------------------------------------------------
// menu item class constructor
// --------------------------------------------------------------------------------
function menu_item (path, parent, container) {
	this.path = new String (path);
	this.parent = parent; this.container = container;
	this.arrpath = this.path.split('_');
	this.depth = this.arrpath.length - 1;

	// get reference to item's data in the structure
	var struct_path = '';
	for (var i = 0; i <= this.depth; i++)
		struct_path += '[' + (Number(this.arrpath[i]) + (i ? 2 : 0)) + ']';
	eval('this.fields = this.container.item_struct' + struct_path);
	if (!this.fields) return;

	// register self in the collections
	this.id = this.container.items.length;
	this.container.items[this.id] = this;
	parent.children[parent.children.length] = this;

	this.set_state = mitem_state;
	this.pos = mitem_position;
	this.build = mitem_build;
	this.buildSub = mitem_buildSub;
	this.links = mitem_links;
	// assign crossbrowser functions
	this.collapse = mitem_collapse;
	this.expand = mitem_expand;
	this.light = mitem_light;
	this.expd_delay = this.container.geom_struct[this.depth].expd_delay;
// init self	
	this.children = [];

	this.parent.subHTML += this.build();
	this.child_count = this.fields.length - 2;
	if (this.child_count > 0) {
		this.container.geom_struct[this.depth + 1].hide_delay = 
			this.container.geom_struct[this.depth + 1].hide_delay ? 
			Math.max(this.container.geom_struct[this.depth + 1].hide_delay, 100) : 100
		this.subHTML = '';
		for (var i = 0; i < this.child_count; i++) new menu_item (this.path + '_' + i, this, this.container);
		this.buildSub();
		document.write (this.subHTML);
		this.subling = o_doc.getElem('m' + this.container.id + 'c' + this.id)
		for (var i = 0; i < this.child_count; i++) this.children[i].links();
	}
}
// --------------------------------------------------------------------------------
// menu item handlers
// --------------------------------------------------------------------------------
// collapses menu to the level specified
function mitem_collapse(to_level) {
	if (this.subling) {
		if (this.container.trans) this.container.trans.stop();
		if (this.filterCol != null) {
			this.container.trans = this.subling.filters[this.filterCol];
			this.subling.filters[this.filterCol].apply();
		}
		o_doc.divBlink(this.subling);	
		if (this.filterCol != null) this.subling.filters[this.filterCol].play();
	}
	for (var i in this.children)
		this.children[i].set_state('mout');
	if (to_level >= this.depth) this.set_state('mout');
	else this.parent.collapse(to_level);
}

function mitem_light() {
	if (this.container.last_item && this.depth <= this.container.last_item.depth)
		this.container.last_item.collapse(this.container.last_item.parent == this ? this.depth+1 : this.depth);
  this.set_state('mover');
	this.container.last_item = this;
	if (this.expd_delay)
		this.expd_timer = setTimeout('menus["'+ this.container.id +'"].items['+ this.id +'].expand()', this.expd_delay);
	else this.expand();
}
// expands menu to calling items
function mitem_expand() {
	if ((!this.container.last_item || this.container.last_item.parent != this) 
		&& this.container.last_item == this && this.subling) {	
		if (this.container.trans) this.container.trans.stop();
		if (this.filterExp) {
			this.container.trans = this.subling.filters[0];
			this.subling.filters[0].apply();
		}
		o_doc.divBlink(this.subling, true);
		if (this.filterExp) this.subling.filters[0].play();
	}
}

// sets item's position on the page
function mitem_position (coord, value) {
	this.set_state('mout');
	if (this.child_count > 0) {	
		var depth_sub = this.depth + 1, 
		pos_dflt = o_doc.getOffs(this.elements['mout'], 
			this.container.geom_struct[depth_sub].block_left, this.container.geom_struct[depth_sub].block_top);
		if (this.container.geom_struct[depth_sub].wise_pos && !this.container.sync) {
			var wise = this.container.geom_struct[depth_sub].wise_pos,
			w_div = o_doc.divSize(this.subling, 0), h_div = o_doc.divSize(this.subling, 1),
			w_win = o_doc.f_width(window), h_win = o_doc.f_height(window),
			w_scr = o_doc.f_xscroll(window), h_scr = o_doc.f_yscroll(window);
			if (pos_dflt.x + w_div > w_win + w_scr) 
				pos_dflt.x = (wise == 1 ? w_win + w_scr : pos_dflt.x) - w_div;
			if (pos_dflt.y + h_div > h_win + h_scr) pos_dflt.y = (wise == 1 ? h_win + w_scr : pos_dflt.y) - h_div;
			if (pos_dflt.x < w_scr) pos_dflt.x = w_scr;
			if (pos_dflt.y < h_scr) pos_dflt.y = h_scr;
		}

		o_doc.divMove(this.subling, pos_dflt)
		for (var j in this.children)
			this.children[j].pos();
	}
}

// DEFAULTS
var TMenu_DEFAULT = {
	'pix' : TMenu_path_to_files + 'pixel.gif'
}