// Title: Tigra Menu GOLD
// URL: http://www.softcomplex.com/products/tigra_menu_gold/
// Version: 2.2
// Date: 03-20-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 = '/pages/includes/menu_files/';
var MENU_POS0=[
{'width': 75,'height': 20,'vertical':false,'table':[0, 1, 0],'expd_delay' : 75,'css' : {'table':'m0table','inner':'m0inner','outer' : ['m0mouto', 'm0movero', 'm0mdowno']}},
{'width':200,'height':20,'block_top':20,'block_left':0,'vertical':true,'wise_pos':1,'table':[0, 1, 0],'hide_delay' : 500,'expd_delay' : 300,'transition' : [0, 0.5, 6, 0.3],
'shadow':{'offX' : 3,'offY' : 2,'color' : '#888888'	},	'css' : {'table' : 'm1table','inner' : 'm1inner','outer' : ['m1mouto', 'm1movero', 'm1mdowno']}}
]
// 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_cfg, a_frames, s_key, a_forms) {
	this.is_master = Boolean(a_frames);
	this.a_forms = a_forms ? a_forms : [];
	this.item_struct = item_struct;
	this.o_cfg = o_cfg;
	this.o_cfg_ch = this.o_cfg[0];
	if (!this.o_cfg_ch.css) this.o_cfg_ch.css = [];
	this.o_cfg_cust = [];
//	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();
		o_doc.f_width   = window.innerWidth != null ? 
			function (w) { return w.innerWidth } : function (w) { return w.document.body.offsetWidth };
		o_doc.f_height  = window.innerHeight != null ?
			function (w) { return w.innerHeight } : function (w) { return w.document.body.offsetHeight };
		o_doc.f_xscroll = window.pageXOffset != null ? 
			function (w) { return w.pageXOffset } : function (w) { return w.document.body.scrollLeft };
		o_doc.f_yscroll = window.pageYOffset != null ?
			function (w) { return w.pageYOffset } : function (w) { return w.document.body.scrollTop };
		o_doc.redraw = doc_redraw;
		o_doc.update = doc_update;
	}
	// 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_cfg_ch.hide_delay = 
		this.o_cfg_ch.hide_delay ? Math.max(this.o_cfg_ch.hide_delay, 100) : 100;

	for (var i = 0; i < this.child_count; i++)
		new menu_item(i, this, this, i);
	// calculate menu sizes
	this.build(this.o_cfg_ch.table ? this.o_cfg_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)
		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;
	if (o_doc.isIE && !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.items[id].set_state(0);
	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_cfg.hide_delay);
	if (this.items[id].o_cfg_cust.sb != null) top.status = '';
}

function menu_onmouseover (id) {
	for (var item = this.items[id]; item.elements; item = item.parent) item.set_state(1);
	this.over_items++;
	clearTimeout(this.hide_timer);
	this.hide_timer = null;
	this.items[id].light();
	if (this.items[id].o_cfg_cust.sb != null) 
		setTimeout('menus["'+ this.id + '"].items['+ id + '].set_status()', 10);
}

function menu_onmousedown (id) {
	this.items[id].set_state(2);
}
// --------------------------------------------------------------------------------
// menu item class constructor
// --------------------------------------------------------------------------------
function menu_item (path, parent, container, n_index) {
	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 ? 3 : 0)) + ']';
	eval('this.fields = this.container.item_struct' + struct_path);
	if (!this.fields) return;
	this.o_cfg = this.parent.o_cfg_ch;
	if (!this.o_cfg.css) this.o_cfg.css = [];
	this.o_cfg_cust = this.fields[2] ? this.fields[2] : [];

	// 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.set_status = mitem_status;
	this.pos = mitem_position;
	this.build = mitem_build;
	this.buildSub = mitem_buildSub;
	this.links = mitem_links;
	this.collapse = mitem_collapse;
	this.expand = mitem_expand;
	this.light = mitem_light;
	this.children = [];

	var w = this.o_cfg.width, h = this.o_cfg.height;
	if (this.o_cfg.vertical) {
		if (this.parent.o_cfg_cust.bw != null) w = this.parent.o_cfg_cust.bw;
		if (this.o_cfg_cust.sh != null) h = this.o_cfg_cust.sh;
	}
	else {
		if (this.parent.o_cfg_cust.bh != null) h = this.parent.o_cfg_cust.bh;
		if (this.o_cfg_cust.sw != null) w = this.o_cfg_cust.sw;
	}

	this.parent.subHTML[n_index] = this.build(w, h);
	this.child_count = this.fields.length - 3;
	if (this.child_count > 0) {
		var n_depth = this.depth + 1, i;
		this.o_cfg_ch = this.container.o_cfg[this.depth + 1] ? 
			this.container.o_cfg[this.depth + 1] : this.o_cfg;
		if (!this.o_cfg_ch.css) this.o_cfg_ch.css = [];
		this.o_cfg.hide_delay = 
			this.o_cfg.hide_delay ? Math.max(this.o_cfg_ch.hide_delay, 100) : 100;
		if (TMG_b_notDOM) {
			this.subHTML = [];
			for (var i = 0; i < this.child_count; i++) 
				new menu_item (this.path + '_' + i, this, this.container, i);
			this.buildSub();
			document.write (this.subHTML.join(''));
			this.subling = o_doc.getElem('m' + this.container.id + 'c' + this.id);
			for (i in this.children) this.children[i].links();
		}
	}
}
// --------------------------------------------------------------------------------
// menu item handlers
// --------------------------------------------------------------------------------
function mitem_status () {
	top.status = this.o_cfg_cust.sb;
}

function mitem_light() {
	if (this.o_cfg.expd_delay)
		this.expd_timer = setTimeout('menus["'+ this.container.id +'"].items['+ this.id +'].expand()', this.o_cfg.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_cfg_cust.bl ? this.o_cfg_cust.bl : this.o_cfg_ch.block_left, 
			this.o_cfg_cust.bt ? this.o_cfg_cust.bt : this.o_cfg_ch.block_top);
		if (this.o_cfg_ch.wise_pos && !this.container.sync) {
			var wise = this.o_cfg_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_cfg_ch.shadow.offX, 
				'y' : pos_dflt.y + this.o_cfg_ch.shadow.offY
			}
		)
	}
}

// DEFAULTS
var TMenu_DEFAULT = {
	'pix' : TMenu_path_to_files + 'pixel.gif'
}, TMG_b_notDOM = window.opera || (navigator.appVersion.indexOf("Mac") > -1 && navigator.appVersion.indexOf("MSIE") > -1);

document.write ('<scr' + 'ipt language="JavaScript" src="' + TMenu_path_to_files + 'menu.' 
	+ (document.layers ? 'lay' : TMG_b_notDOM ? 'opr' : 'dom') + '.js"></scr' + 'ipt>');

