// CodeThatMenu PRO
// Version: 2.3.1 (12.09.04.1)
// IT IS ILLEGAL TO USE UNREGISTERED VERSION OF THE SCRIPT. WE PERFORM
// MONITORING OF THE SITES THAT USE SCRIPT USING GOOGLE AND SPECIAL WORDS
// INCLUDED INTO THE SCRIPT. WE WILL INITIATE LEGAL ACTIONS AGAINST THE
// PARTIES THAT VIOLATE LICENSE AGREEMENT. PLEASE REGISTER THE SCRIPT.
// Copyright (c) 2003-04 by CodeThat.Com
// http://www.codethat.com/

var CT_IMG_BLANK = "img/1x1.gif";

function CT_pre (src) { return CodeThat.preload(src) }
function CT_FALSE () { return false }

var CT_fnv = ua.old ? CT_vis : CT_inhvis;

function CT_copy (src, dest, menu, box)
{
	for (var i in src)
		if (Und(dest[i]))
			if (menu || !box || i != 'bgcolor' && i != 'bgimg' && i != 'border' && i != 'shadow' && i != 'itemoffset' && i != 'opacity')
				dest[i] = src[i]
}

function CT_mnuLrSource (w,h,t,l,ox,oy,z,a,v,bgc,bgi,b,html,ev,al)
{
	var i = this._l.length, lw = w, lh = h;
	var st, lr = this._l[i] = [CodeThat.newID(),ox,oy,0];
	if (b) {
		var bw = b.width;
		lr[3] = bw;
		if (ua.moz || ua.old || ua.css1cm) {
			lw -= 2*bw;
			if (lh) lh -= 2*bw
		} 
		if (!ua.nn4 && bw > 0)
			st = "border:"+bw+"px "+(b.style || 'solid')+' '+b.color
		else {
			html = 	CT_lrSource(
				's'+lr[0], //make sublayer ID
				lw,lh,
				bw,bw,
				1,1,
				'',
				bgc || this._p.style.bgcolor,bgi,
				'','','','',
				z+1,'',
				'',
				html
			);
			lw = w; lh = h;
			bgc = b.color; bgi = ''
		}
	}
	return CT_lrSource(
		lr[0],
		lw,lh, //width, height
		t+oy,l+ox, //top, left
		a,v, //absolute, visible
		'', //css
		bgc,bgi, //bgcolor, bgimage
		'', //clip
		'', //overflow
		'', st, //display, style
		z, al, //z-index, alpha
		ev, //events
		html //html
	)
}

function CT_Border (d, b, hor, w) {
 	var bw = b.width, bc = b.color;
	var def = d || {}, bsrc = '', sz = def.size || w;
	if (Def(d)) {
		var i, tdw, tblw, tblh, atr, add, diff = sz;
		bw = pI(def.width || bw);
		bc = def.color || bc;
		tblw = hor ? sz : bw;
		tblh = hor ? bw : sz;
		atr = hor ? ' width=' : ' height=';
		add = hor ? ' height='+tblh : ' width='+ tblw;
		if (Def(def.el)) {
			var elw, elm = def.el;
			//calculate size for element without one
			for (i=0; i<elm.length; i++) {
				elw = pI(elm[i].width);
				if (!isNaN(elw))
					diff -= elw
			}
			if (diff<0) diff = 0;
			//build html
			bsrc = '<table cellpadding=0 cellspacing=0 border=0 width='+tblw+' height='+tblh+'>'+(hor ? '<tr>' : '');
			for (i=0; i<elm.length; i++) {
				var imsrc = '', bgimg = '';
				if (!hor)
					bsrc += '<tr>';
				tdw = elm[i].width;
				imsrc = elm[i].src || CT_IMG_BLANK;
				if (Undef(tdw)) {
					tdw = diff;
					bgimg = imsrc;
					imsrc = CT_IMG_BLANK
				}
				tdw = atr + tdw;
				bsrc += '<td'+ tdw + (Def(bgimg) ? ' background="'+ bgimg+ '"': '') +
						(Def(elm[i].color) ? ' bgcolor="'+elm[i].color+'"' : '')+
						add +
					'>'+
						'<img src="'+imsrc+'"'+ tdw + add+'></td>'
				if (!hor)
					bsrc += '</tr>';
			}
                        bsrc += (hor ? '</tr>' : '') + '</table>'
		}
	}
	return Def(d) || Def(bw) && Und(d) ? [bsrc, hor ? sz : bw, bc, pI(def.offset || (hor ? -bw : 0)), hor ? bw : sz] : null
}

function CMenu (def, id)
{
	var t = this;
	t.id = id;
	t.open = [];
	if (Undef(def)) def = {};
	if (Undef(def.type)) def.type = "bar";
	t.dd = def.type == "dropdown"; //dd == true means 'dropdown', different anchors are used
	if (Undef(def.style)) def.style = {};
	var o = def.style;
	o.box = pB(o.box, 1);
	if (Und(o.bgcolor)) o.bgcolor = 'white';
	o.z = o.z || 1;
	if (Undef(def.position)) def.position = {};
	o = def.position;
	o.pos = o.pos || [0,0];
	o.pos[0] = pI(o.pos[0]);
	o.pos[1] = pI(o.pos[1]);
	o.anchor_side = o.anchor_side || "nw";
	//<!--
	o.absolute = pB(o.absolute, 1);
	//-->
	t.menu = new CPopupMenu(def, t, null, t.id+".menu");
	t.timer = def.timer || 1000;
	t.otime = def.otime || 10;
	t.aclose = pB(def.autoclose, 0);

	CT_IMG_BLANK = def.imgblank || CT_IMG_BLANK;
	CT_pre(CT_IMG_BLANK);
	_CT_menus.push(t)
}

{

var CMp = CMenu.prototype;
CMp.create = function () { this.menu.createTop() };

CMp.handleEvent = function (e, s1, s2, src) {
	if (!this._dis) {
		var t = this;
		t.clearTimer();
		if (e == 'i') { //in
			var o = t.open, l = o.length;
			if (Undef(s1)) t.hide()
			else if (Undef(s2) || (l != 0 && o[l-1].id != s2.id))
				t.hideAfter(s1);
			if (Def(s2)) t.showTimer(s2);
			if (Def(src)) src.over();
		} else if (e == 'o') { //out
			t.setTimer();
			if (Def(src)) src.out()
		}
	}
};

CMp.clearTimer = function () {
	if (Def(this._to)) clearTimeout(this._to);
	this._to = ''
};

CMp.setTimer = function () {
	if (this._to) return;
	this._to = setTimeout(this.id+'.hide()', this.timer)
};

CMp.showTimer = function (m) {
	if (this._to) return;
	this._to = setTimeout(this.id+'.show('+m._path+')', this.otime)
};

CMp.show = function(path) {
	var t = this;
	path.visible(1);
	t.open.push(path);
	t._to = '';
	//type is set only for top level, autoclose will not be set for sublevels
	if (path.type == 'popup' && t.aclose)
		t.setTimer()
};

CMp.hide = function () {
	if (this.open.length > 0)
		this.hideAfter({"id":''}); //all will be closed
	this._to = ''
};

CMp.hideAfter = function (path) {
	var i, l, o;
	while ((l=(o=this.open).length) > 0 && o[l-1].id != path.id) {
		i = l-1; o[i].visible(0);
		this.open = o.slice(0,i)
	}
};

CMp.popupAt = function (x,y) {
	this.menu.moveRel(x,y);
//<!--
	this._ap = this.menu.AbsPos();
//-->
	this.popup()
};

CMp.popupEv = function (e) { this.popupAt(e.x, e.y) };

CMp.popup = function () { this.handleEvent('i',null,this.menu) };

CMp.run = function () {
//<!--
	var r = arguments.length > 0;
	if (!r)
//-->
		this.menu.create();
//<!--
	if (!(ua.ie4up && !ua.ie55up || ua.oldOpera) || r) {
//-->
		this.menu.moveLayers();
		if (this.menu.type != 'popup') this.menu.visible(1);

		this._op = 1; //menu is in operation mode - for menu-across-frames
//<!--
		this._ap = this.menu.AbsPos();
		this.checkMove()
	} else if (!ua.oldOpera) setTimeout(this.id + '.run(1)',1);
//-->
};

//<!--
CMp.checkMove = function () {
	if (this.menu.AbsPos().join() != this._ap.join())
		this.movePos();
	this._mv = setTimeout(this.id + '.checkMove()', 200)
};

CMp.movePos = function () {
	var ap = this.menu.AbsPos();
	if (ap.join() == this._ap.join()) return;
	this._ap = ap;
	this.menu.Repos()
};


CMp.state = function (b) {
	if (b)
		this.checkMove()
	else if (Def(this._mv))
		clearTimeout(this._mv);
	this._dis = !b
};

CMp.obj = function () { return this.menu }
//-->

}

function CPopupMenu (def, p, p_lvl, path)
{
	var t = this;
	t.id = CodeThat.newID();
	if (Undef(def)) def = {};
	t._p = p;
	t._p_lvl = p_lvl; //parent level menu
	t._top = Undef(p_lvl);
	t._tid = t._p._tid || t._p.id;
	t.dd = p_lvl && p_lvl.dd || p.dd;
	t._path = path;
	var o = t.style = def.style || {};
	if (Def(o.box))
		o.box = pB(o.box, 1);
	if (Def(o.itemoffset)) {
		o.itemoffset.x = pI(o.itemoffset.x || 0);
		o.itemoffset.y = pI(o.itemoffset.y || 0)
	}
	if (Def(o.size)) {
		o.size[0] = pI(o.size[0]);
		o.size[1] = pI(o.size[1])
	}
	if (Def(o.shadow))
		o.shadow.width = pI(o.shadow.width || 5);
	if (Def(o.border))
		o.border.width = pI(o.border.width || 1);

	t.itemover = def.itemover || {} ;
//<!--
	t.itemon = def.itemon || {};
//-->
	o = t.position = def.position || {};
	if (Def(o.pos)) {
		o.pos[0] = pI(o.pos[0]);
		o.pos[1] = pI(o.pos[1])
	} else o.pos = [0,0];
	if (Def(o.menuoffset)) {
		o.menuoffset.x = pI(o.menuoffset.x || 0);
		o.menuoffset.y = pI(o.menuoffset.y || 0)
	}

	//dropdown and default settings
	if (t._top || t.dd) {
		t.style.direction = t.style.direction || (t._top && t.dd ? "h" : "v");
		o.anchor = o.anchor || (p_lvl && p_lvl._p.dd ? "sw" : "ne")
	}

	t.separator = def.separator || {};
	t.defaction = def.defaction || {};
	if (!t._top) {
		t.style.z = t.style.z || (p.style.z + 5);
		CT_copy(p_lvl.style, t.style, 1);
		CT_copy(p_lvl.itemover, t.itemover, 1);
//<!--
		CT_copy(p_lvl.itemon, t.itemon, 1);
		CT_copy(p_lvl.separator, t.separator, 1);
//-->
		CT_copy(p_lvl.position, t.position, 1);
		CT_copy(p_lvl.defaction, t.defaction, 1);
	} else {
		t.type = def.type;
		t.style.z = t.style.z || 1;
//<!--
		if (t.type == 'toolbar') {
			o = t.style.bar = t.style.bar || {};
			o.drag = pB(o.drag, 1)
		}
//-->
	}

//<!--
	if (Def(o = t.style.bar)) {
		o.size = o.size || [10,10];
		if (!o.src && !o.bgcolor) o.bgcolor = "blue";
		o.dir = o.dir || t.style.direction;
		o.size[0] = pI(o.size[0]);
		o.size[1] = pI(o.size[1])
	}
//-->
	t.createItems(def);
	t._l = [];
}

{

var CPp = CPopupMenu.prototype;

CPp.createTop = function () {
	var mw, mh, t = this, st = t.style;
	var p = t.position.pos, w = t.width(), h = t.height();
	if (st.box) {
		mw = w;
		mh = h
	} else {
		mw = pI(st.fixwidth) || w;
		mh = pI(st.fixheight) || h
	}
//<!--
	var y, x = t.getAlignX(p[0]);
	if (Def(x))
		p[0] = x;
	y = t.getAlignY(p[1]);
	if (Def(y))
		p[1] = y;
//-->
	t.createLr(mw,mh,p[1],p[0],0,0,st.z,
//<!--
		t.position.absolute
//-->

	,0)
};

CPp.createLr = function (w,h,t,l,ox,oy,z,a,v,bgc,bgi,html,ev,al) {
	var i = this._l.length;
	var lr = this._l[i] = [CodeThat.newID(),ox,oy];
	var b = this.style.box;
	CT_createLayer(
		lr[0],
		w,h, //width, height
		t+oy,l+ox, //top, left
		a,v,
		'', //css
		bgc,bgi, //bgcolor, bgimage
		'', //clip
		b || ua.nn4 ? 'hidden': 'visible', //overflow
		'','',
		z, al, //z-index, alpha
		ev, //events
		html //html
	);
	return i
};

//<!--
CPp.apply = function () { //called for popups added to items
	this.create();
	this._p.refresh()
};
//-->

CPp.create = function () {
	var t = this;
	var i, b = t.style.box;
	var p = t.position.pos, w = t.width(), h = t.height(), st = t.style, z=st.z;
//<!--
	var al = st.opacity;
//-->
	//box
//<!--	
	if (!st.autosize)
//-->
		t.moveItems();
	var itsrc = t.itSrc();
	t._b = t.createLr(
	//w,h,t,l,ox,oy,z,a,v,bgc,bgi,html,ev,al
		w,h,p[1],p[0],0,0,b ? z+2 : z,
		1,
		0,
		b ? st.bgcolor : '',
		b ? st.bgimg: '',
		ua.nn4 ? '' : itsrc,
		['mouseover',t._tid+'.clearTimer()','mouseout',t._tid+'.setTimer()']
//<!--
		,b ? al : '' //when the layer is inside another layer, opacities are multiplied, so we need to switch it off
//-->
	);
	//layers for NN4 are created outside
	if (ua.nn4)
		dw(itsrc);
//<!--
	if (st.autosize) { //resize and move items
		t.sizeItems();
		t.moveItems(1);
		h = t.height(1); //menu size MUST be recalculated
		CT_resize(t._l[t._b][0], w, h);
		if (t._top && b)
			CT_resize(t._l[0][0], w, h)
	}
//-->
	var iw = w, ih = h, iox = 0, ioy = 0; //iframe and non-box properties


	if (b) {
	//shadow
		var j = st.shadow;
		if (j) {
			t.createLr(j.width,h,p[1],p[0],w,j.width,z,1,0,j.color,'','',''
//<!--
			,j.opacity || al
//-->
			);
			t.createLr(w,j.width,p[1],p[0],j.width,h,z,1,0,j.color,'','',''
//<!--
			,j.opacity || al
//-->
			)
		}
		//border
		j = st.border;
		if (j) {
			var bpr, bw = w;
			//left border
			bpr = CT_Border(j.l, j, 0, h);
			if (bpr) {
				iox = -bpr[1];
				t.createLr(bpr[1],bpr[4],p[1],p[0],-bpr[1],bpr[3],z+1,1,0,bpr[2],'',bpr[0],''
//<!--
				,al
//-->
				);
				bw += bpr[1]
			}
			//right border
			bpr = CT_Border(j.r, j, 0, h);
			if (bpr) {
				t.createLr(bpr[1],bpr[4],p[1],p[0],w,bpr[3],z+1,1,0,bpr[2],'',bpr[0],''
//<!--
				,al
//-->
				);
				bw += bpr[1]
			}
			//top border
			bpr = CT_Border(j.t, j, 1, bw);
			if (bpr) {
				ioy = -bpr[4];
				t.createLr(bpr[1],bpr[4],p[1],p[0],bpr[3],-bpr[4],z+1,1,0,bpr[2],'',bpr[0],''
//<!--
				,al
//-->
				);
			}
			//bottom border
			bpr = CT_Border(j.b, j, 1, bw);
			if (bpr) {
				ih += bpr[4];
				t.createLr(bpr[1],bpr[4],p[1],p[0],bpr[3],h,z+1,1,0,bpr[2],'',bpr[0],''
//<!--
				,al
//-->
				)
			}
			iw = bw
		}
//<!--
		//bar
		j = st.bar;
		if (j) {
			var o, bh = j.size[1], bw = j.size[0];
			if (bh < 0) bh = h;
			if (bw < 0) bw = w;
			bh = Math.min(bh, h); bw = Math.min(bw, w);
			t._bar = t.createLr(bw,bh,p[1],p[0],0,0,z+3,1,0,j.bgcolor,j.src,'',
				['mouseover',t._tid+'.clearTimer()','mouseout',t._tid+'.setTimer()']
				,al);
			CT_pre(j.src);
			if (j.drag) {
				t._dragbar = t._bar;
				var o = CT_el(t._l[t._bar][0])[0];
				CodeThat.regEventHandler("mousedown", t._path+".startDrag(ev)", o);
				CodeThat.regEventHandler("mouseup", t._path+".stopDrag()", o)
			}
		}
//-->
	} else {
		iox = t._fx1;
		ioy = t._fy1;
		iw = Math.max(iw, t._fx2-iox);
		ih = Math.max(ih, t._fy2-ioy)
	}
	t._iw = iw; t._ih = ih;
	if (ua.ie55up)
		t.createLr(iw,ih,p[1],p[0],iox,ioy,z-1,1,0,'','',
			'<iframe frameborder=0 '+(location.protocol == 'https:' ? ' src="/blank.html"' : '')+
			' style="filter:Alpha(Opacity=0);visibility:inherit;position:absolute;top:0px;left:0px;height:100%;width:100%"></iframe>'
		);
	for (i=t.items.length;i>0;)
		t.items[--i].createChild();
	t.created = 1
};

CPp.itSrc = function () {
	var i=0, src = '', it = this.items;
	for (;i<it.length;)
		src += it[i++].src();
	return src
};

//<!--
CPp.St = function (a, v){ this.style[a] = v };

CPp.StOver = function (a, v){ this.itemover[a] = v };

CPp.StOn = function (a, v) { this.itemon[a] = v };

CPp.Pos = function (a, v) { this.position[a] = v };

CPp.z = function (z) { this.style.z = z };

CPp.Separator = function (v) { this.separator = v };
//-->

CPp.AbsPos = function () {
	var p;
	if (this._top)
		p = this.created ? CT_getAbsPos(this._l[0][0]) : this.position.pos
	else
		p = this.position.pos || [0,0];
	return [p[0],p[1]] //return values, not the 'pos' object
};

//<!--
CPp.sizeItems = function () {
	for (var i=0; i<this.items.length; i++)
		this.items[i].autoSize()
};
//-->

CPp.moveItems = function (mv) {
	var i, ap, ix, iy, ox, oy, t = this;
	var dh = t.hor(), it = t.items, b = t.style.box, ioff = t.style.itemoffset;
	t._fx1 = t._fy1 = t._fx2 = t._fy2 = ox = oy = 0; //calculate also offsets and dimensions for <iframe> in non-box config
	if (ua.nn4) //in NN4 we have to move items directly
		ap =
//<!--  
		(t._top && !t.position.absolute ? t.AbsPos() : 
//-->
		t.position.pos
//<!--
		)
//-->
		|| [0,0];
	if (b) {
//<!--
		var bar = t.style.bar;
//-->
		ix =
//<!--
			Def(bar) && bar.dir == 'v' ? bar.size[0] :
//-->
			0;
		iy =
//<!--
			Def(bar) && bar.dir == 'h' ? bar.size[1] :
//-->
		0
	}
	else iy = ix = 0;
	if (Def(ioff)) {
		ox = pI(ioff.x || 0);
		oy = pI(ioff.y || 0);
		if (b) { ix += ox; iy += oy }
	}
	for (i=0; i<it.length; i++) {
		var p, s = it[i].style.size;
		if (b || !it[i].Pos()) {
			it[i].Pos([ix,iy]);
			if (dh) ix += s[0] + ox
			else iy += s[1] + oy;
		}
		if (ua.nn4)
			it[i].moveRel(ap[0],ap[1]);
//<!--
		else if (mv)
			it[i].moveRel(0, 0);
//-->

		if (!b) { //for non-box menus with free positioned items we need to know min and max coordinates
			p = it[i].Pos();
			t._fx1 = Math.min(t._fx1, p[0]);
			t._fy1 = Math.min(t._fy1, p[1]);
			t._fx2 = Math.max(t._fx2, p[0]+s[0]);
			t._fy2 = Math.max(t._fy2, p[1]+s[1])
		}
	}
};

CPp.moveSubs = function () {
	var o,p = this.AbsPos(), i = this._top ? 1 : 0;
	for (;i<this._l.length;)
	{
		o = this._l[i++];
		CT_moveTo(o[0], p[0]+o[1], p[1]+o[2])
	}
};

CPp.moveLayers = function () {
	this.moveSubs();
	if (ua.nn4)
		this.moveItems()
};

//<!--
CPp.Repos = function () {
	var t = this, p = t.position.pos, x = t.getAlignX(p[0]), y = t.getAlignY(p[1]), v = t.vis;
	if (Def(x) && Def(y)) {
		if (v) t.visible(0);
		this.moveTo(x, y);
		if (v) t.visible(v)
	}
}

CPp.getAlignX = function (x) {
	var ww = CodeThat.getWinWidth(), al = this.position.align, w = this.width();
	if (Def(al)) {
		if (al == 'left')
			x = 0
		else if (al == 'right')
			x = ww - w
		else if (al == 'center')
			x = (ww - w)/2;
		x += CodeThat.getScrollX()
	}
	return x
}

CPp.getAlignY = function (y) {
	var wh = CodeThat.getWinHeight(), al = this.position.valign, h = this.height();
	if (Def(al)) {
		if (al == 'top')
			y = 0
		else if (al == 'bottom')
			y = wh - h
		else if (al == 'center')
			y = (wh - h)/2;
		y += CodeThat.getScrollY()
	}
	return y
}
//-->

CPp.imVis = function (v) {
	var i, it = this.items;
	for (i=0; i<it.length; i++)
		it[i].visible(v)
};

CPp.visible = function (v) {
	var i, t = this;
	t.vis = v;
	if (v && t._p.width) //move menu to correct position
		t._p.moveChild();
	for (i=0; i<t._l.length; i++)
		CT_vis(t._l[i][0], v);
	if (ua.old)
		t.imVis(v);
	if (t._p.setOver) t._p.setOver(v);
};

CPp.moveTo = function (x,y) {
	var i,o,p = this.position;
	p.pos = [x,y];
	if (this._l.length > 0) {
		CT_moveTo(this._l[0][0], x, y);
		this.moveLayers()
	}
};

CPp.moveRel = function (x,y) {
	var w, h, off, wp, t = this, p = t.position, a = p.anchor, as = p.anchor_side;
	if (t._p.width) { //CMenuItem, not CMenu
		w = t._p.width(); h = t._p.height();
		if (a == 'nw' || a == 'sw' || a == 'w') {}
		else if (a == 'ne' || a == 'se' || a == 'e') x += w;
		if (a == 'nw' || a == 'ne' || a == 'n') {}
		else if (a == 'sw' || a == 'se' || a == 's') y += h;
		if (a == 'n' || a == 's') x = Math.ceil(x+w/2);
		if (a == 'e' || a == 'w') y = Math.ceil(y+h/2);
	}
	w = t.width(), h = t.height();
	if (as == 'nw' || as == 'sw' || as == 'w') {} //don't change
	else if (as == 'ne' || as == 'se' || as == 'e') x -= w;
	if (as == 'nw' || as == 'ne' || as == 'n') {}
	else if (as == 'sw' || as == 'se' || as == 's') y -= h;
	if (as == 'n' || as == 's') x -= Math.floor(w/2);
	if (as == 'e' || as == 'w') y -= Math.floor(h/2);
	if (Def(off = p.menuoffset)) {
		x += off.x;
		y += off.y
	}
	//correct position if out of view
	wp = CodeThat.getScrollX() + CodeThat.getWinWidth() - t._iw;
	if (x > wp) x = wp;
	if (x < 0) x = 0;
	wp = CodeThat.getScrollY() + CodeThat.getWinHeight() - t._ih;
	if (y > wp) y = wp;
	if (y < 0) y = 0;
	t.moveTo(x,y)
};

CPp.hor = function () { return this.style.direction == 'h' };

CPp.width = function (c) { //1 means 'count anyway'
	var i, obj, h, r = 0, ix = 0, t = this, it = t.items;
	if (t.style.box)
		if (!Und(t._b) && !c) r = CT_getWidth(t._l[t._b][0])
		else {
			h = t.hor();
			if (Def(obj = t.style.itemoffset))
               			ix = obj.x;
			for (i=0; i<it.length; i++) {//items of different width are supposed, '*' doesn't work :(
				var iw = it[i].style.size[0];
				r = h ? r+iw+ix : Math.max(r, iw)
			}
               		r += (h ? 1 : 2)*ix;
//<!--
			if (Def(obj = t.style.bar) && obj.dir == 'v')
				r += obj.size[0];
//-->
		}
	else r = it[0].style.size[0]
	return r
};

CPp.height = function (c) { //true means 'count anyway'
	var i, h, obj, r = 0, iy = 0, t = this, it = t.items;
	if (t.style.box)
		if (!Und(t._b) && !c) r = CT_getHeight(t._l[t._b][0]);
		else {
			h = t.hor();
			if (Def(obj = t.style.itemoffset))
				iy = obj.y;
			for (i=0; i<it.length; i++) {//items of different height are supposed
				var ih = it[i].style.size[1];
				r = h ? Math.max(r, ih) : r+ih+iy
			}
			r += (h ? 2 : 1)*iy;
//<!--
			if (Def(obj = t.style.bar) && obj.dir == 'h')
				r += obj.size[1];
//-->
		}
	else r = it[0].style.size[1]
	return r
};

CPp.createItems = function (def) {
	this.items = [];
        var i, it = def.items;
	if (Und(it)) return;
        if (Und(it.length) && Def(it.item)) it = it.item; //XML <items><item></item><item></item>...</items> structure support
	if (Und(it.length)) it = [it]; //set to array if only one
	for (i=0; i<it.length; i++)
		this.addItem(it[i]);
};

CPp.addItem = function (def) {
	var it = this.items, itm = new CMenuItem(def, this, this._path+".items["+it.length+"]");
	it.push(itm);
	return itm
};

//<!--

CPp.delItem = function (i) {
	var j, it = this.items;
	if (i<it.length && i>=0) {
		it[i] = null;
		it = this.items = it.slice(0,i).concat(it.slice(i+1));
		for (j=0;j<it.length;) 
			it[j]._path = this._path+".items["+j+++"]"
	}
};

CPp.getItem = function (i) { return i < this.items.length ? this.items[i] : null };

CPp.startDrag = function (e) {
	var t = this;
	if (!t.position.absolute) return;
	if (ua.ie4up) {
		var d = document;
		t._dragOld = d.ondragstart;
		t._selOld = d.onselectstart;
		d.ondragdtart = CT_FALSE;
		d.onselectstart = CT_FALSE
	}
	CodeThat.regEventHandler('mousemove', t._path+'.dragTo(ev)');
	var p = t.AbsPos();
	t._drdX = p[0]-e.x;
	t._drdY = p[1]-e.y;
	t._p.hide();
	t._p.state(0)
};

CPp.stopDrag = function () {
	CodeThat.clearEventHandler('mousemove');
	if (ua.ie4up) {
		document.ondragstart = this._dragOld;
		document.onselectstart = this._selOld
	}
	this.Repos();
	this._p.state(1)
};

CPp.dragTo = function (e) {
	this.moveTo(e.x+this._drdX, e.y+this._drdY)
}

//-->

}

function CMenuItem (def, p, path)
{
	this._p = p;
	this._tid = p._tid;
	this._path = path;
	if (Def(def) && def.type == 'separator')
	{
		def = p.separator;
		def.type = 'separator'; //because old type value is lost
	}
	this.initDef(def);
	this._l = [];
}

{

var CMp = CMenuItem.prototype;

CMp.lrSrc = CT_mnuLrSource;

CMp.initDef = function (def) {
	var t = this;
	if (Undef(def)) def = {};
	t.text = def.text;
	t.textover = def.textover;
//<!--
	t.texton = def.texton;
//-->

	var o = t.style = def.style || {};
	if (Def(o.size)) {
		o.size[0] = pI(o.size[0]);
		o.size[1] = pI(o.size[1])
	}
	if (Def(o.shadow))
		o.shadow.width = pI(o.shadow.width || 5);
	if (Def(o.border))
		o.border.width = pI(o.border.width || 1);
	o.z = o.z || (t._p.style.z + 5);
	t.styleover = def.styleover || {};
//<!--
	t.styleon = def.styleon || {};
//-->

	CT_copy(t._p.style, t.style, 0, t._p.style.box);
	CT_copy(t._p.itemover, t.styleover, 0);
//<!--
	CT_copy(t._p.itemon, t.styleon, 0);
//-->

	if (def.menu) t.menu = new CPopupMenu(def.menu, t, t._p, t.child())
	else t.menu = null;
	t.action = def.action || {};

	CT_copy(t._p.defaction, t.action, 0);

	var o = t.position = def.position || {};
	if (Def(o.pos)) {
		o.pos[0] = pI(o.pos[0]);
		o.pos[1] = pI(o.pos[1])
	}
	t.type = def.type;
	t.sep = def.type == 'separator';
//<!--
	t.bool = def.type == 'bool';
	t.val = pB(def.value, 0);
	t.frm = pB(def.frm, 0)
//-->
}

CMp.src = function () {
	var t = this, src = '';
	var p = t.Pos() || [0,0], st = t.style, s = st.size, _z = st.z, vis = !ua.nn4 || t._p.vis,
		m_o = t.sep || t.frm;//main layer only
//<!--
	var op = st.opacity;
//-->
	var w = s[0], h =
//<!--
			st.autosize && !t.sep? '' : 
//-->
			s[1], x=p[0], y=p[1], ox=0, oy=0;
	var act = t.action, js = act.js, url=act.url, target = act.target;
	var anch = !m_o && (js || url
//<!--
		|| t.bool
//-->
		);
	//clickable layer
	var p_p = t._p._path;
	if (anch) {
		src += '<a href="'+(url||'#')+
			(target?'" target="'+target:'')+
			'" onClick="'+
//<!--
			(t.bool ? t._path + '.toggle();':'')+
//-->
			(ua.nn4 ? '' : 'this.blur();')+t._tid+'.hide();'+(js ? js : url ? '' : 'return false')+
			'" title="'+(act.title || '')+'">'
	}
	if (!m_o) {
		t._imid = CodeThat.newID();
		src = t.lrSrc(w,h,y,x,0,0,_z+5,1,vis,'','','',
			//HTML
			src + '<img border=0 '+(ua.nn4 ? 'name=' : 'id=')+t._imid+' src="'+CT_IMG_BLANK+'" width='+w+' height='+s[1]+'>'+(anch?'</a>':''),
			//events
			['mouseover',t._tid+".handleEvent('i',"+p_p+(!m_o ? ","+t.child()+","+t._path:'')+");CodeThat.cancelEvent(event)",
			 'mouseout',t._tid+".handleEvent('o',"+p_p+",null"+(!m_o ? ","+t._path:'')+");CodeThat.cancelEvent(event)"]
		)
	}
	var bg = st.bgimg, bgc = st.bgcolor, brd = st.border;
	//main layer [index = 1]
	src += t.lrSrc(w,h,y,x,ox,oy,_z+2,1,vis,bgc,bg,brd,t.sep ? '' : t.gHTML(0)
//<!--
	,'',op
//-->
	);
	//mouseover layer [index = 2]
	if (!m_o)
		src += t.lrSrc(w,h,y,x,ox,oy,_z+4,1,0,t.styleover.bgcolor || bgc, t.styleover.bgimg || bg,t.styleover.border || brd,t.gHTML(1)
//<!--
		,'',op
//-->
		);
//<!--
	//switched-on layer [index = 3]
	if (!m_o && t.bool && !t.menu)
		src += t.lrSrc(w,h,y,x,ox,oy,_z+3,1,vis&&t.val,t.styleon.bgcolor || bgc,t.styleon.bgimg || bg,t.styleon.border || brd,t.gHTML(2),'',op);
//-->
	//shadow layer
	var v = st.shadow;
	if (v)
		src += t.lrSrc(w,h,y,x,v.width,v.width,_z,1,vis,v.color
//<!--
		,'','','','',v.opacity || op
//-->
		);
	return src
};

CMp.gHTML = function (n) {
	var t = this;
	var sto, st = t.style;
	var im, ei, sub_ei, brd = st.border, w = st.size[0], h = st.size[1], txt = t.text;
	sub_ei = ei = st.imgendoff;
	if (t.menu)
		im = st.imgdir;
	else {
		im = st.imgitem;
		ei = st.imgitemend;
		if (sub_ei && !ei) ei = { src:CT_IMG_BLANK, width:sub_ei.width, height:sub_ei.height }
	}
	var al = st.align, css = st.css, tcol = st.color;
	if (n == 0)
		return t.mkHTML(w, h, tcol,css,al,t.text,im,ei,brd);
	//mouseover layer
	if (n == 1) {
		txt = t.textover || txt;
		sto = t.styleover;
		if (t.menu) {
			im = sto.imgdir || st.imgdiropen || im;
			ei = st.imgendon || ei
		} else { 
			im = sto.imgitem || im;
			ei = sto.imgitemend || ei
		}
	}
//<!--
	//switched-on layer
	else if (n == 2) {
		txt = t.texton || txt;
		sto = t.styleon;
		im = sto.imgitem || im;
		ei = sto.imgitemend || ei
	}
//-->
	return t.mkHTML(w, h, sto.color || tcol,sto.css || css,sto.align || al,txt,im,ei,sto.border || brd)
};

CMp.apply = function () { if (this._p.created) this.fillLr() };

CMp.fillLr = function () {
	var t = this;
	CT_HTML(t._l[1][0], t.gHTML(0));
	//mouseover layer
	if (!t.sep)
		CT_HTML(t._l[2][0], t.gHTML(1))
//<!--
	//switched-on layer
	if (t.bool)
		CT_HTML(t._l[3][0], t.gHTML(2));
//-->
};

CMp.mkHTML = function (lw,lh,fn,css,al,txt,img,ei,b) {
	var spc, iw, ih, w, isrc = '', src = '';
	if (txt || Def(img) || Def(ei)) {
		src = '<table border=0 cellpadding=0 cellspacing=0 width=100%><tr>';
		if (b) {
			lw -= 2*b.width;
			lh -= 2*b.width;
		}
		if (img) {
			spc = img.space || this.style.imgspace;
			spc = pI(spc || 0);
			iw = pI(img.width);
			ih = pI(img.height);
			w = iw + spc*2;
			lw -= w;
			src += '<td width='+w+' height='+ih+'><img src="'+img.src+'" width='+iw+' height='+ih+' hspace='+spc+' border=0></td>'
		}
		if (ei) {
			spc = ei.space || this.style.imgspace;
			spc = pI(spc || 0);
			iw = pI(ei.width);
			ih = pI(ei.height);
			w = iw + spc*2;
			lw -= w;
			isrc = '<td width='+w+' height='+ih+' align=right><img src="'+ei.src+'" width='+iw+' height='+ih+' hspace='+spc+' border=0></td>'
		}
		if (txt) src += '<td'+(al?' align='+al:'')+' height="'+lh+'" width="'+lw+'"><div'+(css ? ' class="'+css+'"':'')+'>'+
			(fn ? '<font color='+fn+'>'+txt+'</font>' : txt)+'</div></td>';
		src += isrc + '</tr></table>';
	}
	return src
}

CMp.createChild = function () { if (this.menu) this.menu.create() };

CMp.child = function () { return this._path+".menu" };

//<!--
CMp.St = function (a,v){ this.style[a] = v };

CMp.StOver = function (a,v) { this.styleover[a] = v };

CMp.StOn = function (a,v) { this.styleon[a] = v };

CMp.z = function (z) { this.style.z = z };

CMp.Act = function (a,v) { this.action[a] = v };
//-->

CMp.visible = function (v) {
	var i, t = this;
	if (t._l.length) {
		for(i=0;i<t._l.length;)
			CT_fnv(t._l[i++][0], v);
//<!--
		if (t.bool) t.setBool(true)
		else
//-->
			if (t._l[2]) CT_hide(t._l[2][0]);
	}
};

CMp.Pos = function (p) {
	//item doesn't have other than 'pos'
	return	Def(p) ? this.position.pos = p : this.position.pos
};

CMp.Type = function (
//<!--
t
//-->
) {
//<!--
	if (Def(t)) {
		if (t == 'separator') {
			this.initDef(this._p.separator);
			this.sep = 1;
		}
		this.type = t;
		this.bool = t == 'bool';
	}
//-->
	return this.type
};

CMp.AbsPos = function () {
	var pos = this._p.AbsPos();
	pos[0] += this.Pos()[0];
	pos[1] += this.Pos()[1];
	return pos
};

CMp.width = function () { return this.style.size[0] };

CMp.height = function () { return this.style.size[1] };

//<!--
CMp.autoSize = function () {
	var i, t = this, h=0, b=0;
	if (t.sep) return;
	//autosize base is calculated from maximum dimensions of all main layers
	var inc = ua.moz || ua.old || ua.css1cm ? 0 : 1; //whether to increase the content size
	for (i=0; i < t._l.length; i++)
		h = Math.max(h, CT_getContentHeight(t._l[i][0] = CT_el(t._l[i][0])[0]) + 2*t._l[i][3]*inc)
	t.style.size = [t.style.size[0], h];
	for (i=0; i < t._l.length; i++)
		CT_setHeight(t._l[i][0], h - 2*t._l[i][3]*(!inc && !ua.oldOpera));
	if (t._imid)
		CodeThat.findElement(t._imid).height = h
};
//-->

CMp.moveChild = function () {
	if (this.menu) {
		var ap = this.AbsPos();
		this.menu.moveRel(ap[0],ap[1])
	}
};

CMp.moveRel = function (x,y) {
	var i=0, l = this._l, p = this.Pos();
	for(;i<l.length;i++)
		CT_moveTo(l[i][0], x+p[0]+l[i][1], y+p[1]+l[i][2])
};

CMp.over = function () {
	var t = this;
	CT_fnv(t._l[2][0], 1);
	CT_hide(t._l[1][0]);
	var scr = t.action.over;
	if (Def(scr)) eval(scr);
//<!--
	if (t.bool) CT_hide(t._l[3][0])
//-->
};

CMp.out = function () {
	if (!this.menu || !this._over) {
		this.setBool(1);
		var scr = this.action.out;
		if (Def(scr)) eval(scr)
	}
};

CMp.setOver = function (v) {
	this._over = v;
	this.setBool(!v)
};

CMp.setBool = function (v) {
	var t = this;
	if (v) {
		CT_hide(t._l[2][0]);
		if (!ua.old || t._p.vis) {
//<!--
			if (t.bool) {
				CT_fnv(t._l[1][0], !t.val);
				CT_fnv(t._l[3][0], t.val)
			} else
//-->
				CT_fnv(t._l[1][0], 1)
		}
	}
};

//<!--
CMp.toggle = function () {
	var t = this;
	t.val = !t.val;
	CT_fnv(t._l[1][0], !t.val);
	CT_fnv(t._l[3][0], t.val);
	var code = t.val ? t.action.on : t.action.off;
	if (Def(code)) eval(code)
};

CMp.addPopup = function (def) {
	var t = this;
	delete t.menu;
	t.menu = new CPopupMenu(def, t, t._p, t.child());
	t.apply();
	return t.menu
};

CMp.delPopup = function () {
	var t = this;
	if (t.menu) {
		t.menu.visible(0);
		delete t.menu
	}
	t.apply()
};

CMp.refresh = function () { this.moveChild() };

CMp.setText = function (s,t) { //t can be "over" or "on"
	this['text'+(t||'')] = s;
/*
	if (this._p.created)  //update layers with new text (autosize will not work here, though...)
		this.apply()
*/
};
//-->

}

var _CT_menus = [];

function CT_m_load () {
//<!--
	for (var i=0;i<_CT_menus.length;)
		_CT_menus[i++].run(1);
//-->
	CodeThat.setOnResize(CT_m_res, 1)
}

function CT_m_res () {
	if (ua.old) {
		if (Undef(window._CT_reloading)) {
			window._CT_reloading = 1;
			location.reload(1)
		}
	}
//<!--
	else for (var i=0;i<_CT_menus.length;) _CT_menus[i++].movePos()
//-->
}

CodeThat.setOnLoad(function(){CodeThat.loaded = 1}); //"page loaded" flag

if (ua.oldOpera)
	CodeThat.setOnLoad(CT_m_load)
else
	CodeThat.setOnResize(CT_m_res);

