// Title: Tigra Menu GOLD
// URL: http://www.softcomplex.com/products/tigra_menu_gold/
// Version: 2.0
// Date: 01-31-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, actions = ['click', 'mouseout', 'mouseover', 'mousedown'];

function doc_load (myfunc) {	
	var s = new String(window.onload ? 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, o_config, a_frames, s_key, a_forms) {
	this.is_master = Boolean(a_frames);
	this.a_forms = a_forms;
	this.item_struct = item_struct;
	this.o_config = o_config;
	this.o_config_ch = this.o_config[0];
	if (!this.o_config_ch.css) this.o_config_ch.css = [];
//	this.a_frames  = a_frames;
	this.items       = [];
	this.children    = [];
	this.over_items  = 0;
	
	this.exec        = menu_exec;
	this.hide        = menu_hide;
	this.on = [];
	this.onclick     = menu_onclick;
	this.onmouseout  = menu_onmouseout;
	this.onmouseover = menu_onmouseover;
	this.onmousedown = menu_onmousedown;
	this.redraw      = menu_redraw;
	this.build       = menu_build;
	this.selectsHide = TMGSelectsHide;

	// prepare environment object
	if (!o_doc) o_doc = new doc();
	// register in global menus collection
	this.id = s_key != null ? s_key : menus.length;
	menus[this.id] = this;

	this.subling = window;
	this.subHTML = '';
	this.child_count = this.item_struct.length;
	this.o_config_ch.hide_delay = 
		this.o_config_ch.hide_delay ? Math.max(this.o_config_ch.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.o_config_ch.table ? this.o_config_ch.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.a_frames = [];
			for (i in a_frames) {
				this.a_frames[i] = [];
				for (var j in a_frames[i])
					this.a_frames[i][j] = eval('top.' + a_frames[i][j]);
			} 
		}
		this.sync.frames[window.name] = window;
		o_doc.onload ("o_doc.update()")
	}
	else o_doc.onload ("o_doc.redraw()")
}

// --------------------------------------------------------------------------------
// menu event handlers
// --------------------------------------------------------------------------------
function menu_redraw () {
	if (this.sync) {	
		if (typeof(this.a_frames) != 'object') {
			if (!this.sync.main) return setTimeout('menus["' + this.id + '"].redraw()', 100);
			this.a_frames = this.sync.win.menus[this.id].a_frames
		}
		if (this.is_master) {
			var me, y_shift = 0, x_shift;			
			if (!this.sync.matrix) this.sync.matrix = []
			for (i in this.a_frames) {
				x_shift = 0;
				for (j in this.a_frames[i]) {
					this.sync.matrix[this.a_frames[i][j].name] = {
						'x' : x_shift,
						'y' : y_shift
					}
					if (o_doc.isIE)
						if (!this.a_frames[i][j].document.body) 
							return setTimeout('menus["' + this.id + '"].redraw()', 100);
					x_shift += o_doc.f_width(this.a_frames[i][j]);
				}
				y_shift += o_doc.f_height(this.a_frames[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)
				}
			)
	}
}

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.sync && o_doc.isIE) document.body.focus();
	if (!this.hide_timer || this.over_items || !this.last_item)	return;
	this.last_item.collapse(0);
	this.last_item = null;
	if (!o_doc.isIE6) this.selectsHide(true);
}

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.items[id].o_config.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(2);
}
// --------------------------------------------------------------------------------
// 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;
	this.o_config = this.parent.o_config_ch;
	if (!this.o_config.css) this.o_config.css = [];

	// 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;
// init self	
	this.children = [];
	if (o_doc.isIE4) this.sublingCnt = 0;

	this.parent.subHTML += this.build();
	this.child_count = this.fields.length - 2;
	if (this.child_count > 0) {
		var n_depth = this.depth + 1, i;
		this.o_config_ch = this.container.o_config[this.depth + 1] ? 
			this.container.o_config[this.depth + 1] : this.o_config;
		if (!this.o_config_ch.css) this.o_config_ch.css = [];
		this.o_config.hide_delay = 
			this.o_config.hide_delay ? Math.max(this.o_config_ch.hide_delay, 100) : 100
		if (window.opera) {
			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
// --------------------------------------------------------------------------------
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(1);
	this.container.last_item = this;
	if (this.o_config.expd_delay)
		this.expd_timer = setTimeout('menus["'+ this.container.id +'"].items['+ this.id +'].expand()', this.o_config.expd_delay);
	else this.expand();
}

// sets item's position on the page
function mitem_position (coord, value) {
	if (this.child_count > 0) {	
		var pos_dflt = o_doc.getOffs(this.elements[0], 
			this.o_config_ch.block_left, this.o_config_ch.block_top);
		if (this.o_config_ch.wise_pos && !this.container.sync) {
			var wise = this.o_config_ch.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)
		if (this.sublingBack) o_doc.divMove(this.sublingBack, pos_dflt);
		if (this.sublingShad) 
			o_doc.divMove(this.sublingShad, {
				'x' : pos_dflt.x + this.o_config_ch.shadow.offX, 
				'y' : pos_dflt.y + this.o_config_ch.shadow.offY
			}
		)
	}
}

// DEFAULTS
var TMenu_DEFAULT = {
	'pix' : TMenu_path_to_files + 'pixel.gif'
}
// Linking
document.write ('<scr' + 'ipt language="JavaScript" src="' + TMenu_path_to_files + 'menu.' 
	+ (document.layers ? 'lay' : !window.opera ? 'dom' : 'opr') + '.js"></scr' + 'ipt>')
