var workSpaceObject;
function alertMessage(message) { alert(message); return false; }

function buildMenuObject(object,nest,cot,curDoc) {
	if(!curDoc)
		curDoc = document;
	if(bowser.docObjModel && cot) {
		this.occurrence = cot;
	} else {
		
		if(!nest) nest = "curDoc.";
		else nest = 'curDoc.layers.' + nest + '.';
		
		if(bowser.domCapable) this.occurrence = curDoc.getElementById(object);
			else if(bowser.msie4) this.occurrence = curDoc.all[object];
			else if(bowser.netscape4) this.occurrence = eval(nest + "layers."  + object);
			else this.occurrence = 0;
		
	}
	if(!this.occurrence) {
		return alertMessage('The layer does not exist (' + object
		+ ') - \nIf this has occurred in Netscape, please check'
		+ ' the nesting order of your tags wthin the page\nNest: ' + nest);
	}
	
	if(bowser.domCapable || bowser.msie4) this.css = this.occurrence.style;
		else this.css = this.occurrence;
	this.ok = 0;
	if(bowser.domCapable || bowser.msie4) this.ref = curDoc;
		else this.ref = this.css.document; 
	this.obj = object + "Object";
	eval(this.obj + " = this");
	this.x = 0;
	this.y = 0;
	this.w = 0;
	this.h = 0;
	this.vis = 0;
	return this;
}

buildMenuObject.prototype.newCoords = function(x, y) {
	this.x = x;
	this.y = y;
	this.css.left = x + bowser.px;
	this.css.top = y + bowser.px;
}

buildMenuObject.prototype.makeVisible = function(r) {
	this.css.visibility = "visible";
	this.vis = 1;
	if(bowser.opera5 && this.withChildren) {
		this.withChildren.makeVisible();
	}
}

buildMenuObject.prototype.makeHidden = function(a) {
	this.css.visibility = "hidden";
	this.vis = 0;
}

buildMenuObject.prototype.clip2Coords = function(t, r, b, l, setwidth) { 
	this.w = r;
	this.h = b;
	if(bowser.netscape4) {
		this.css.clip.top = t;
		this.css.clip.right = r;
		this.css.clip.bottom = b;
		this.css.clip.left = l;
	} else {
		if(t < 0) t = 0;
		if(r < 0) r = 0;
		if(b < 0) b = 0;
		if(b < 0) b = 0;
		this.css.clip = "rect(" + t + bowser.px + "," + r + bowser.px + "," + b + bowser.px + "," + l + bowser.px + ")";
		if(setwidth) {
			if(bowser.opera5 || bowser.opera6) {
				this.css.pixelWidth = r;
				this.css.pixelHeight = b;
			} else {
				this.css.width = r + bowser.px;
				this.css.height = b + bowser.px;
			}
		}
	}
}


function isActive(on,h) {
	if(this.o.withChildren) {
		on ? this.o.withChildren.makeHidden() : bowser.opera5 ? this.o.withChildren.makeVisible() : this.o.withChildren.css.visibility = "inherit";
	}
	if(bowser.recycle || bowser.docObjModel) {
		if(!this.onItemImage) {
			this.o.occurrence.className = on ? this.overClass : this.normalClass;
		} else {
			this.o.ref.images["img" + this.name].src = on ? this.onItemImage.src : this.offItemImage.src;
		}
		if(on && bowser.netscape6) {
			this.o.makeHidden();
			this.o.css.visibility = 'inherit'
		}
	} else {  
		if(!this.onItemImage) {
			if(on) {
				this.o.over.makeVisible();
			} else {
				this.o.over.makeHidden();
			}
		} else {
			if(on) this.o.ref.images["img" + this.name].src = this.onItemImage.src;
			else this.o.ref.images["img" + this.name].src = this.offItemImage.src;
		}
	}
	if(on) this.isactive = 1;
	else this.isactive = 0;
}


function workSpace(frame) {
	if(!frame) frame = self;
	this.x = 0;
	if(!bowser.msie) this.x2 = frame.innerWidth
		else this.x2  = frame.document.body.offsetWidth - 20;
	this.y = 0;
	if(!bowser.msie){
		this.orgy = frame.innerHeight;
		this.y2 = frame.innerHeight;
	} else {
		this.orgy = frame.document.body.offsetHeight - 6;
		this.y2 = frame.document.body.offsetHeight - 6;
	}
	return this;
}

function findLocation(num,w,minus) {
	if(num) {
		if(num.toString().indexOf("%") != -1) {
			var t = w ? workSpaceObject.x2 : workSpaceObject.y2;
			num = parseInt((t * parseFloat(num) / 100));
			if(minus) num -= minus;
		} else num = eval(num);
	} else num = 0;
	return num;
}

function tierObject() {
	var child = this;
	child.width = arguments[0] || null;
	child.height = arguments[1] || null; 
	child.normalClass = arguments[2] || null;
	child.overClass = arguments[3] || null;
	child.itemBorderX = arguments[4] > -1 ? arguments[4] : null; 
	child.itemBorderY = arguments[5] > -1 ? arguments[5] : null;
	child.borderClass = arguments[6] || null;
	child.itemLayout = arguments[7] > -1 ? arguments[7] : null; 
	child.subPosition = arguments[8] || null;
	child.subMenuOffSetX = arguments[9] || null;
	child.subMenuOffSetY = arguments[10] || null;
	child.arrowImage = arguments[11] || null;
	child.arrowWidth = arguments[12] || null;
	child.arrowHeight = arguments[13] || null;
	child.subMenuBorder = arguments[14] || null;
	return child;
}

function defineParent(menuName) {
	var parent = this;
	parent.itemCounter = 0;
	parent.name = menuName;
	parent.m = new Array();
	parent.scrollY =- 1;
	parent.tier = new Array();
	parent.l = new Array();
	parent.tim = 100;
	parent.isPageResized = 0;
	parent.isover = 0;
	parent.zIndex = 100;
	parent.frameStartTier = 1;
	parent.z = 0;
	parent.totw = 0;
	parent.toth = 0;
	parent.maxWidth = 0;
	parent.maxHeight = 0;
	workSpaceObject = new workSpace();
	parent.built = 0;
	return this;
}

defineParent.prototype.onMakeVisible = "";
defineParent.prototype.onhide = "";
defineParent.prototype.onBuild = "";

/***Creating layers**/
function divBuilder(id,className,linkedText,w,c,app,ex,txt2) {
	if(bowser.docObjModel) {
		var div = document.createElement("DIV");
		div.className = className;
		div.id = id;
		if(linkedText) div.innerHTML = linkedText;
		if(app) {
			app.appendChild(div);
			return div
		}
		if(w) document.body.appendChild(div);
		return div;
	} else {
		var dstr = '<div id = "' + id + '" class = "' + className + '"';
		if(ex && bowser.recycle) dstr += " " + ex;
		dstr += ">" + linkedText;
		if(txt2) { alert(txt2); dstr += txt2; }
		if(c) dstr += '</div>';
		if(w) document.write(dstr);
			else return dstr;
	}
	return "";
}


/***Getting layer string for each menu**/
function layerBuilder(m,app,name,spacer,clb,arrowImage,ah,aw,root) {

	var headerItem = m.headerItem;
	var withChildrenstr = "";
	var l = m.lev;
	var str = "";
	var txt = m.leftIcon ? m.leftIcon : "";
	var ev = "";
	var id = name + "_" + m.name;
	var d1;
	
	txt += m.txt;
	
	if(app) d1 = app;
	
	if((!bowser.recycle || l == 0) && !headerItem) {
		ev = ' onmouseover = "' + name + '.showSubMenu(\'' + m.name + '\')" onmouseout = "' + name + '.itemOnMouseOut(\'' + m.name + '\')" onclick = "' + name + '.itemOnClick(\'' + m.name + '\'); return false" ';
	}
	
	if(bowser.recycle && l != 0) txt = "";
	if(l == 0) str += d1 = divBuilder(id + "_0",clb,"");
	
	str += m.d2 = divBuilder(id, m.normalClass, txt, 0, 0, d1, ev)
	
	if(l == 0 && bowser.docObjModel) { 
		m.d2.onclick = new Function(name + '.itemOnClick("' + m.name + '")');
		m.d1 = d1;
		m.d2.onmouseover = new Function(name + '.showSubMenu("' + m.name + '")');
		m.d2.onmouseout = new Function(name + '.itemOnMouseOut("' + m.name + '")');
	}
	
	if(!bowser.recycle && !m.offItemImage && !headerItem) {
		str += divBuilder(id + "_1", m.overClass, txt, 0, 1);
		str += divBuilder(id + "_3", "PopUpMenuPro", '<a href = "#" ' + ev + '><img alt = "" src = "' + root + spacer + '" width = "' + m.w + '" height = "' + m.h + '" border = "0"></a>', 0, 1);
	}

	str += '</div>'; 

	if(l == 0) {
		if(arrowImage) str += m.d3 = divBuilder(id + '_a','PopUpMenuPro', '<img alt = "" height = "' + aw + '" width = "' + ah + '" src = "' + root + arrowImage + '">', 0, 1, d1);
		str += "</div>"
	}
	
	str += "\n";
		
	if(!bowser.recycle) {
		m.txt = null;
		m.d2 = null;
		m.d3 = null;
	}
	
	if(bowser.docObjModel) {
		if(l == 0) document.body.appendChild(d1);
		str = "";
	}
	return str
}


/***get subPosition num from text (better to evaluate numbers later)**/
function convertAlign2Number(subPosition) {
	switch(subPosition) {
		case "right" :
			return 1;
			break;
		case "left" :
			return 2;
			break;
		case "bottom" :
			return 3;
			break;
		case "top" :
			return 4;
			break;
	}
	return null
}


defineParent.prototype.addItem = function(name,parent,txt,itemHrefValue,targ,w,h,leftIcon,offItemImage,onItemImage,normalClass,overClass,subPosition,itemLayout,headerItem,hotKey,ctrlKey,altKey,shiftKey,onclick,onmouseover,onmouseout) {
	var pump = this;
	if(!name) name = pump.name + "" + pump.itemCounter;
	if(name=="divider"){
		name = name + pump.itemCounter;
		parent = parent;
		itemHrefValue = "";
		w = w;
		h = pump.dividerHeight;
		offItemImage = pump.dividerImg;
		onItemImage = pump.dividerImg;
	}
	if(parent && w) var lastWidth = w;
	var p = parent != "" && parent && pump.m[parent] ? parent : 0;
	if(pump.itemCounter == 0) {
		if(bowser.opera7 && this.frames) bowser.docObjModel = 0;
		var tmp = location.href;
		if(tmp.indexOf('file:') > -1 || tmp.charAt(1) == ':') {
			pump.root = pump.offlineRoot;
		} else {
			pump.root = pump.onlineRoot;
		}
	}
	if(!ctrlKey) var ctrlKey = 0;
	if(!altKey) var altKey = 0;
	if(!shiftKey) var shiftKey = 0;
	if(hotKey) addHotKey(hotKey, pump.root + itemHrefValue, ctrlKey, altKey, shiftKey);
	var create = 1;
	var img;
	var arrowImage;
	var LIstr = "";
	var m = pump.m[name] = new Object();
	m.name = name;
	m.subs = new Array();
	m.parent = p;
	m.arnum = 0;
	m.withChildren = 0;
	var l = m.lev = p ? pump.m[p].lev + 1 : 0;
	pump.itemCounter++;
	m.hide = 0;
	if(l >= pump.l.length) {
		var p1
		var p2 = 0;
		if(l >= pump.tier.length) p1 = pump.l[pump.tier.length-1];
		else p1 = pump.tier[l];
		pump.l[l] = new Array();
		if(!p2) p2 = pump.l[l-1];
		if(l != 0) {
			if(isNaN(p1.subPosition)) p1["subPosition"] = convertAlign2Number(p1.subPosition);
			for(var i in p1) {
				if(i != "str" && i != "m") {
					if(p1[i] == null) pump.l[l][i] = p2[i];
					else pump.l[l][i] = p1[i] ;
				}
			}
		} else {
			pump.l[l] = pump.tier[0];
			pump.l[l].subPosition = convertAlign2Number(pump.l[l].subPosition);
		}
		pump.l[l]["str"] = '';
		pump.l[l].m = new Array();
		if(!pump.l[l].borderClass) pump.l[l].borderClass = pump.l[l].normalClass;
		pump.l[l].app = 0;
		pump.l[l].max = 0;
		pump.l[l].arnum = 0;
		pump.l[l].o = new Array();
		pump.l[l].withChildren = new Array();
		pump.tier[l] = p1 = p2 = null;
		if(l != 0) pump.l[l].str = pump.l[l].app = divBuilder(pump.name +  '_'  + l + '_0', pump.l[l].borderClass,'');
	}
	if(p) {
		p = pump.m[p];
		p.subs[p.subs.length] = name; 
		if(p.subs.length == 1 && pump.l[l-1].arrowImage) {
			p.withChildren = 1; 
		if(p.parent) {
			pump.m[p.parent].arnum++;
			if(pump.m[p.parent].arnum>pump.l[l-1].arnum) {
				pump.l[l-1].str += pump.l[l-1].withChildren[pump.l[l-1].arnum] = divBuilder(pump.name +  '_a'  + (l-1) + '_' + pump.l[l-1].arnum,'PopUpMenuPro', '<img height = "' + pump.l[l-1].arrowHeight + '" width = "' + pump.l[l-1].arrowWidth + '" src = "' + pump.root + pump.l[l-1].arrowImage + '" alt = "">', 0, 1, pump.l[l-1].app);
				pump.l[l-1].arnum++;
			}
		}
	}
	if(bowser.recycle) if(p.subs.length > pump.l[l].max) pump.l[l].max = p.subs.length; else create = 0}
	m.itemLayout = itemLayout > -1 ? itemLayout : pump.l[l].itemLayout;
	m.w = findLocation(w || pump.l[l].width, 1);
	m.h = findLocation(h || pump.l[l].height, 0);
	if(leftIcon && name && parent) {
		if(!bowser.netscape4) LIstr = '<img align="absmiddle" src = "' + leftIcon + '" alt = "" border="0">';
		else LIstr = '<img align="left" src = "' + leftIcon + '" alt = "" border="0">';
	} else if(pump.leftIconWidth != 0 && parent) {
 		if(!bowser.netscape4) LIstr = '<img align="absmiddle" src = "' + pump.spacerImg + '" alt = "" border="0" width="'+pump.leftIconWidth+'" height="'+pump.leftIconHeight+'">';
		else LIstr = '<img align="left" src = "' + pump.spacerImg + '" alt = "" border="0" width="'+pump.leftIconWidth+'" height="'+pump.leftIconHeight+'">';
	} else {
		LIstr = "";
	}
	m.txt = LIstr + txt;
	m.itemHrefValue = itemHrefValue;
	if(subPosition) subPosition = convertAlign2Number(subPosition);
	m.subPosition = subPosition || pump.l[l].subPosition;
	m.normalClass = normalClass = normalClass || pump.l[l].normalClass;
	m.targ = targ;
	m.overClass = overClass || pump.l[l].overClass;
	m.create = create;
	m.mover = onmouseover;
	m.itemOnMouseOut = onmouseout;
	m.itemOnClick = onclick;
	m.active = isActive;
	m.isactive = 0;
	m.headerItem = headerItem;
	if(create) pump.l[l].m[pump.l[l].m.length] = name;
	if(offItemImage) {
		m.offItemImage = new Image();
		m.offItemImage.src = pump.root + offItemImage;
		if(!onItemImage) onItemImage = offItemImage;
		m.onItemImage = new Image();
		m.onItemImage.src = pump.root + onItemImage;
		m.normalClass = "PopUpMenuPro";
		m.txt = "";
		if(!bowser.recycle && !headerItem) m.txt = '<a href = "#" onmouseover = "' + pump.name + '.showSubMenu(\'' + name + '\')" onmouseout = "' + pump.name + '.itemOnMouseOut(\'' + name + '\')" onclick = "' + pump.name + '.itemOnClick(\'' + name + '\'); return false">';
		m.txt += '<img alt = "" src = "' + pump.root + offItemImage + '" width = "' + m.w + '" height = "' + m.h + '" id = "img' + m.name + '" ';
		if(bowser.domCapable && !headerItem) m.txt += 'style = "cursor : pointer; cursor : hand"';
		if(!bowser.recycle) {
			if(!bowser.domCapable) m.txt += 'name = "img' + m.name + '"';
			m.txt += ' border = "0"';
		}
		m.txt += '>';
		if(!bowser.recycle && !headerItem) m.txt += '</a>';
	} else {
		m.offItemImage = 0;
		m.onItemImage = 0;
	}
	if(l == 0 || create) pump.l[l].str += layerBuilder(m,pump.l[l].app,pump.name,pump.spacerImg,pump.l[l].borderClass,pump.l[l].arrowImage,pump.l[l].arrowWidth,pump.l[l].arrowHeight,pump.root);
	if(l == 0) {
		if(m.w>pump.maxWidth) pump.maxWidth = m.w;
		if(m.h>pump.maxHeight) pump.maxHeight = m.h;
		pump.totw += pump.topItemSpace + m.w + pump.l[0].itemBorderX;
		pump.toth += pump.topItemSpace + m.h + pump.l[0].itemBorderY
	}
	if(itemHrefValue && !onmouseover) {
		var path = itemHrefValue.indexOf("mailto:") > -1 || itemHrefValue.indexOf("http://") || itemHrefValue.indexOf("https://") || itemHrefValue.indexOf("mms://") || itemHrefValue.indexOf("ftp://") > -1 ? "" : pump.root;
		m.mover = "self.status = '" + path + m.itemHrefValue + "'";
		if(!m.itemOnMouseOut) m.itemOnMouseOut = "";
		m.itemOnMouseOut += ";self.status = '';";
	}
}



/**Getting x/y coords for subs **/
defineParent.prototype.getcoords = function(m,bx,by,x,y,maxWidth,maxHeight,ox,oy) {
	var subPosition = m.subPosition;
	x += m.o.x;
	y += m.o.y;
	switch(subPosition) {
		case 1 :
			x += m.w + bx;
			break;
		case 2 :
			x-= maxWidth + bx;
			break;
		case 3 :
			y += m.h + by;
			break;
		case 4 :
			y-= maxHeight + by;
			break;
	}
	if(m.lev == this.frameStartTier - 1 && this.frames) {
		switch(subPosition) {
			case 1 :
				x = 0;
				break; 
			case 2 :
				x = this.workSpaceObject.x2-maxWidth;
				break;
			case 3 :
				y = 0;
				break; 
			case 4 :
				y-= maxHeight + by;
				break;
		}
	}
	m.subx = x + ox;
	m.suby = y + oy;
}



/**Showing sub elements**/
defineParent.prototype.showSubMenu = function(el) {
	var pump = this;
	var parentMenu = pump.m[el];
	var m;
	var o;
	var nl;
	if(!parentMenu.b || (pump.isPageResized && parentMenu.lev > 0)) parentMenu.b = pump.l[parentMenu.lev].b;
	pump.isover = 1;
	clearTimeout(pump.tim);
	var ln = parentMenu.subs.length;
	var l = parentMenu.lev + 1;
	if(pump.l[parentMenu.lev].a == el && l != pump.l.length && !pump.openOnClick) {
		if(pump.l[parentMenu.lev + 1].a) pump.hidesub(l + 1, el);
		return;
	}
	pump.hidesub(l, el);
	if(parentMenu.mover) eval(parentMenu.mover);
	if(!parentMenu.isactive) parentMenu.active(1);
	pump.l[parentMenu.lev].a = el;
	if(ln == 0) return;
	if(pump.openOnClick && !pump.clicked) return;
	if(!pump.l[l].b) return;
	var b = pump.l[l].b;
	var bx = pump.l[l].itemBorderX;
	var by = pump.l[l].itemBorderY;
	var itemLayout = parentMenu.itemLayout;
	var subMenuBorder = pump.l[l].subMenuBorder;
	var x = bx + subMenuBorder;
	var y = by + subMenuBorder;
	var maxWidth = 0;
	var maxHeight = 0;
	var cn = 0;
	b.makeHidden();
	for(var i = 0; i < pump.l[l].m.length; i++ ) {  
		if(!bowser.recycle) m = pump.m[pump.l[l].m[i]];
		else m = pump.m[pump.m[el].subs[i]];
		if(m && m.parent == el && !m.hide) {
			if(!bowser.recycle) o = m.o; else o = m.o = pump.l[l].o[i]
			if(x != o.x || y != o.y) o.newCoords(x,y);
			nl = m.subs.length ;
			if(bowser.recycle) {
				if(o.w != m.w || o.h != m.h) o.clip2Coords(0,m.w,m.h,0,1);
				if(o.occurrence.className != m.normalClass) { 
					m.isactive = 0;
					o.occurrence.className = m.normalClass;
					if(bowser.netscape6) {
						o.makeHidden();
						o.css.visibility = 'inherit';
					}
				}
				if(bowser.msie6) b.makeVisible();
				o.occurrence.innerHTML = m.txt;
				if(bowser.msie6) b.makeHidden();
				if(!m.headerItem) {
					o.occurrence.onmouseover = new Function(pump.name + ".showSubMenu('" + m.name + "')");
					o.occurrence.onmouseout = new Function(pump.name + ".itemOnMouseOut('" + m.name + "')");
					o.occurrence.onclick = new Function(pump.name + ".itemOnClick('" + m.name + "')");
					if(o.oldcursor) {
						o.css.cursor = o.oldcursor;
						o.oldcursor = 0;
					}
				} else {
					o.occurrence.onmouseover = '';
					o.occurrence.onclick = ''; 
					if(o.css.cursor == '') o.oldcursor = bowser.netscape6 ? "pointer" : "hand";
						else o.oldcursor = o.css.cursor;
					o.css.cursor = "auto";
				}        
			}
			if(m.withChildren) {
				o.withChildren = pump.l[l].withChildren[cn];
				o.withChildren.newCoords(x + m.w-pump.l[l].arrowWidth - 3, y + m.h / 2-(pump.l[l].arrowHeight / 2));
				o.withChildren.css.visibility = "inherit";
				cn++;
			} else o.withChildren = 0;
			if(!itemLayout) {
				y += m.h + by;
				if(m.w > maxWidth) maxWidth = m.w;
				maxHeight = y;
			} else {
				x += m.w + bx;
				if(m.h > maxHeight) maxHeight = m.h;
				maxWidth = x;
			}
			o.css.visibility = "inherit";
			if(bowser.opera5 || bowser.opera6) o.makeVisible();
		} else {
			o = pump.m[pump.l[l].m[i]].o;
			o.makeHidden();
		}
	}
	if(!itemLayout) maxWidth += bx * 2 + subMenuBorder;
	else maxHeight += by * 2 + subMenuBorder;
	if(subMenuBorder) {
		maxWidth += subMenuBorder;
		maxHeight += subMenuBorder;
	}
	b.clip2Coords(0, maxWidth, maxHeight, 0, 1);
	if(pump.chkscroll) pump.chkscroll();
	if(pump.chkscroll || !parentMenu.subx || !parentMenu.suby || pump.scrollY > -1 || pump.isPageResized)
		pump.getcoords(parentMenu, pump.l[l-1].itemBorderX, pump.l[l-1].itemBorderY, parentMenu.b.x, parentMenu.b.y, maxWidth, maxHeight, pump.l[l-1].subMenuOffSetX, pump.l[l-1].subMenuOffSetY);
	x = parentMenu.subx;
	if(pump.chkscroll && l == pump.frameStartTier) parentMenu.suby += pump.scrollY;
	y = parentMenu.suby;
	b.newCoords(x, y);
	if(pump.onMakeVisible) eval(pump.onMakeVisible);
	b.makeVisible();
}

/* hiding sub menus */
defineParent.prototype.hidesub = function(l,el) { 
	var pump = this;
	var tmp;
	var m;
	var i;
	var j;
	var hide;
	
	if(!l) {
		l = 1;
		hide = 1;
		pump.clicked = 0;
	}
	for(i = l-1; i < pump.l.length; i++ ) {
		if(i > 0 && i > l - 1)
			if(pump.l[i].b) pump.l[i].b.makeHidden();
			if(pump.l[i].a && pump.l[i].a != el) {
				m = pump.m[pump.l[i].a];
				m.active(0, 1);
				if(m.itemOnMouseOut) eval(m.itemOnMouseOut);
					pump.l[i].a = 0;
			
			if(i > 0 && i > l - 1) if(bowser.opera5 || bowser.opera6) for(j = 0; j < pump.l[i].m.length; j++ ) pump.m[pump.l[i].m[j]].o.makeHidden();
		}
		if(i > l) {
			for(j = 0; j < pump.l[i - 1].arnum; j++) {
				pump.l[i-1].withChildren[j].makeHidden();
				if(bowser.opera6)
					pump.l[i-1].withChildren[j].newCoords(-1500, -1500);
			}
		}
	}
	if(hide && pump.onhide) eval(pump.onhide);
}

/***Make all menu div objects**/
defineParent.prototype.makeObjects = function(nowrite, fromframe) {
	var pump = this;
	var oc;
	var name;
	var bx;
	var by;
	var w;
	var h;
	var l;
	var headerItem;
	var ar;
	var id;
	var nest;
	var st = 0;
	var en = pump.l.length;
	var bobj;
	var o;
	var m;
	var i;
	var j;
	if(fromframe) {
		st = this.frameStartTier;
		this.body = fromframe.document.body;
		this.doc = fromframe.document;
		this.definedTarget = fromframe;
		this.workSpaceObject = new workSpace(fromframe);
	} else {
		this.body = document.body;
		this.doc = document;
		if(this.frames)
			en = this.frameStartTier;
		this.definedTarget = self;
	}
	if(!nowrite) {
		for(i = st; i < en; i++ ) {
			if(!bowser.docObjModel){
				this.doc.write(pump.l[i].str);
			}
			else if(i > 0)
				this.body.appendChild(pump.l[i].app);
			if(!this.frames)
				pump.l[i].str = null;
		}
	}
	pump.z = pump.zIndex + 2;
	for(i = st; i < en; i++) {
		oc = 0;
		if(i != 0) {
			bobj = pump.l[i].b = new buildMenuObject(pump.name + "_" + i + "_0", "", pump.l[i].app, this.doc);
			bobj.css.zIndex = pump.z;
			if(bowser.domCapable) bobj.css.overflow = 'hidden';
		}
		bx = pump.l[i].itemBorderX;
		by = pump.l[i].itemBorderY;
		pump.l[i].max = 0;
		for(j = 0; j < pump.l[i].m.length; j++) {
			m = pump.m[pump.l[i].m[j]];
			name = m.name;
			w = m.w;
			h = m.h;
			l = m.lev;
			headerItem = m.headerItem;
			if(i > 0) {
				m.b = bobj;
				nest = i;
			} else {
				m.b = new buildMenuObject(pump.name + "_" + name + "_0", "", m.d1, this.doc);
				m.b.css.zIndex = pump.z;
				m.b.clip2Coords(0, w + bx * 2, h + by * 2, 0, 1);
				nest = name;
			}
			
			id = pump.name + "_" + name;
			nest = pump.name + "_" + nest;
			
			if(m.create) {
				o = m.o = new buildMenuObject(id, nest + "_0", m.d2, this.doc);
				o.z = o.css.zIndex = pump.z + 1;
				
				if(bowser.recycle) {
					pump.l[l].o[oc] = o;
					oc++;
				}
				
				if(l == 0 && m.offItemImage)
					o.css.visibility = 'inherit';
				
				if(bowser.opera5)
					o.makeVisible();
				
				o.withChildren = 0;
			}

			if(!bowser.recycle || l == 0)
				o.clip2Coords(0, w, h, 0, 1);
		
			o.newCoords(bx, by);
			o.z = o.css.zIndex = pump.z + 2;
		
			if(j < pump.l[i].arnum) {
				pump.l[i].withChildren[j] = new buildMenuObject(pump.name + "_a" + i + "_" + j, nest + "_0", nowrite ? 0 : pump.l[i].withChildren[j], this.doc);
				pump.l[i].withChildren[j].css.zIndex = pump.z + 30 + j;
			} else if (l == 0 && m.withChildren == 1) {
				o.withChildren = new buildMenuObject(id + "_a", nest + "_0", m.d3, this.doc);
				o.withChildren.newCoords(bx + m.w - pump.l[i].arrowWidth - 3, by + m.h / 2 - (pump.l[i].arrowHeight / 2)); 
				o.withChildren.css.zIndex = pump.z + 20;
			}
		
			if(!headerItem && !bowser.recycle && !m.offItemImage) {  
				o.over = new buildMenuObject(pump.name + "_" + name + "_1",nest + "_0" + ".document.layers." + id, "", this.doc);
				o.over.newCoords(0,0);
				o.over.makeHidden();
				o.over.clip2Coords(0,w,h,0,1);
				o.over.css.zIndex = pump.z + 3;
				img = new buildMenuObject(pump.name + "_" + name + "_3",nest + "_0" + ".document.layers." + id,"",this.doc);
				img.newCoords(0,0);
				img.css.visibility = "inherit"; img.css.zIndex = pump.z + 4;
				if(bowser.opera5) img.makeVisible();
			}
			pump.z++; 
		}
	}
	if(fromframe) {	
		pump.chkscroll = function() {
			if (bowser.msie && !bowser.msie6) this.scrollY = this.body.scrollTop;
			else if (bowser.msie6 || bowser.opera7) {
				if (this.doc.compatMode && document.compatMode != "BackCompat") this.scrollY = this.doc.documentElement.scrollTop;
				else this.scrollY = this.body.scrollTop;
			} else this.scrollY = this.definedTarget.pageYOffset;
		}
	}
}



/**Onmouseout**/
defineParent.prototype.itemOnMouseOut = function() {
	var pump = this;
	clearTimeout(pump.tim);
	pump.isover = 0;
	var f = "if(!" + pump.name + ".isover)" + pump.name + ".hidesub()";
	
	if(!pump.closeOnClick) {
		pump.tim = setTimeout(f,pump.closeDelay);
	} else {
		
		if(bowser.netscape4) {
			document.captureEvents("Event.MOUSEDOWN");
			document.onmousedown = new Function(f);
		} else {
			document.onclick = new Function(f);
		}
		
		if(this.frames) {
			if(bowser.netscape4) {
				this.doc.captureEvents("Event.MOUSEDOWN");
				this.doc.onmousedown = new Function(f);
			} else this.doc.onclick = new Function(f);
		}
	}
}



/**Constructing and initiating top items**/
defineParent.prototype.construct = function(nowrite) {
	var pump = this;
	if(!pump.l[0] || pump.l[0].m.length == 0) return alertMessage('Hey! Come on! Define some menus so that I can buildem ...');
	if(!nowrite) {
		for(var i = 1; i < pump.l.length;i++) {
			pump.l[i].str += "</div>"
		}
	} 
	pump.makeObjects(nowrite);
	workSpaceObject = new workSpace();
	var mpa;
	var o;
	var maxWidth = pump.maxWidth;
	var maxHeight = pump.maxHeight;
	var i;
	var totw = pump.totw;
	var toth = pump.toth;
	var m;
	var px = pump.topItemSpace;
	var bx = pump.l[0].itemBorderX;
	var by = pump.l[0].itemBorderY;
	var x = pump.fromLeftPlacement;
	var y = pump.fromTopPlacement;
	var mp = pump.topTierPlacement;
	var itemLayout = pump.itemLayout;
	if(itemLayout) {
		toth = maxHeight + by*2;
		totw = totw-px + bx;
	} else {
		totw = maxWidth + bx * 2;
		toth = toth - px + by;
	}
	switch(mp) {
		case "center" :
			x = workSpaceObject.x2 / 2 - totw / 2;
			if(bowser.netscape4) x-= 9;
			break;
		case "right" :
			x = workSpaceObject.x2 - totw;
			break;
		case "bottomLeft" :
		case "bottomCenter" :
			 y = workSpaceObject.y2 - toth;
			 if(mp == "bottomCenter") x = workSpaceObject.x2 / 2 - totw / 2;
			 break;
		default :
			if(mp.toString().indexOf(",") > -1) mpa = 1;
			break;
	}
	for(var i = 0; i < pump.l[0].m.length; i++) {
		m = pump.m[pump.l[0].m[i]];
		o = m.b;
		if(mpa) itemLayout ? x = findLocation(mp[i]) : y = findLocation(mp[i],0,0,1); 
		o.newCoords(x, y);
		o.makeVisible();
		if(m.withChildren) m.o.withChildren.makeVisible();
		o.oy = y; 
		if(!mpa) itemLayout ? x += m.w + px + bx : y += m.h + px + by;
	}
	if(bowser.netscape4 || bowser.opera5 || bowser.opera6) setTimeout('window.eventPageResized = new Function("' + pump.name + '.resized()")',500);
		else window.eventPageResized = new Function(pump.name + ".resized()");
	pump.resized = cm_resized;
	if(bowser.opera5 || bowser.opera6) document.onmousemove = new Function(pump.name + ".resized()");
	if(pump.onBuild) eval(pump.onBuild);
	pump.built = 1;
	return true;
}



/**Capturing resize**/
var mozResize = 0;
function cm_resized() {
	if(mozResize) return;
	workSpace2 = new workSpace();
	var off = (bowser.opera6 || bowser.opera5) ? 20 : 5;
	if(workSpace2.x2 < workSpaceObject.x2 - off || workSpace2.y2 < workSpaceObject.orgy - off || workSpace2.x2 > workSpaceObject.x2 + off || workSpace2.y2 > workSpaceObject.orgy + off) {
		if(bowser.msie || bowser.netscape6 || bowser.opera7 || bowser.netscape4) {
			workSpaceObject = workSpace2;
			this.isPageResized = 1; 
			if(this.eventPageResized) eval(this.eventPageResized);
			this.construct(1);
			if(this.pageIsResized) eval(this.pageIsResized);
		} else {
			mozResize = 1;
			location.reload();
		} 
	}
}



/**Onclick of an item**/
defineParent.prototype.itemOnClick = function(m) {
	menuItem = this.m[m];
	if(menuItem.itemOnClick) eval(menuItem.itemOnClick);
	if(this.openOnClick && menuItem.subs.length > 0) {
		this.clicked = 1;
		this.showSubMenu(menuItem.name);
		return;
	} 
	var itemHrefValue = menuItem.itemHrefValue;
	var targ = menuItem.targ;
	if(itemHrefValue) {
	
		if(itemHrefValue.indexOf("mailto") != 0 && itemHrefValue.indexOf("http") != 0) itemHrefValue = this.root + itemHrefValue;
	
		if(String(targ) == "undefined" || targ == "" || targ == 0 || targ == "_self") {
			if(this.frames) {
				
				if(this.l[0].a) {
					this.m[this.l[0].a].active(0, 1);
					this.l[0].a  = 0;
				}
				
				for(i = this.frameStartTier; i < this.l.length; i++) {
					if(this.l[i].b) {
						this.l[i].b.makeHidden();
						this.l[i].b = null;
						for(j = 0; j < this.l[i].menuItem.length; j++) {
							this.menuItem[this.l[i].menuItem[j]].b = null;
						}
					}
				}
				
				this.isover = 0;
				
			}
			
			this.definedTarget.location.href = itemHrefValue;
			
		} else if(targ == "_blank") {
			window.open(itemHrefValue);
		} else if(targ == "_top" || targ == "window") {
			top.location.href = itemHrefValue;
		} else if(top[targ]) {
			top[targ].location.href = itemHrefValue;
		} else if(parent[targ]) {
			parent[targ].location.href = itemHrefValue;
		}
		
	} else {
		return false;
	}
}





if(bowser.domCapable && !bowser.opera) {
	defineParent.prototype.sel = 0;
	defineParent.prototype.onMakeVisible += ";this.hideSelect(parentMenu, parentMenu.subx, parentMenu.suby, maxWidth, maxHeight, parentMenu.lev)";
	defineParent.prototype.hideSelect = function(parentMenu, x, y, w, h, l) {
		var selx
		var sely
		var selw
		var selh
		var i
		if(!this.sel) {
			this.sel = this.doc.getElementsByTagName("SELECT");
			this.sel.tier = 0;
		}
		var sel = this.sel;
		for(i = 0; i < sel.length; i++) {
			selx = 0;
			sely = 0;
			var selp;
			if(sel[i].offsetParent) {
				selp = sel[i];
				while(selp.offsetParent) {
					selp = selp.offsetParent;
					selx += selp.offsetLeft;
					sely += selp.offsetTop;
				}
			}
			selx += sel[i].offsetLeft;
			sely += sel[i].offsetTop;
			selw = sel[i].offsetWidth;
			selh = sel[i].offsetHeight;
			if(selx + selw > x && selx < x + w && sely + selh > y && sely < y + h) {
				if(sel[i].style.visibility != "hidden") {
					sel[i].tier = l;
					sel[i].style.visibility = "hidden";
					if(parentMenu) {
						if(!parentMenu.itemOnMouseOut) parentMenu.itemOnMouseOut = "";
						parentMenu.itemOnMouseOut += this.name + ".sel[" + i + "].style.visibility = 'visible';";
					}
				}
			} else if(l <= sel[i].tier && !(parentMenu && l == 0)) {
				sel[i].style.visibility = "visible";
			}
		}
	}
}



function pumpScroll() {
	if(bowser.msie) defineParent.prototype.onBuild = 'document.body.onscroll = new Function(pump.name + ".scrollCheck(" + pump.name + ")")';
		else defineParent.prototype.onBuild = 'setTimeout(pump.name + ".scrollCheck()",200)';
	defineParent.prototype.leftScroll = 0;
	defineParent.prototype.scrollstop = 0;
	defineParent.prototype.scrollCheck = function(obj) {
		var i;
		if(bowser.mac) return;
		if(bowser.msie)	var c = obj;
		else var pump = this;
		var o;
		if(bowser.netscape4 || bowser.netscape6 || bowser.opera5) pump.scrollY = window.pageYOffset;	
		else pump.scrollY = document.body.scrollTop;
		if(pump.scrollY != pump.leftScroll) {
			pump.hidesub();
			if(pump.scrollY > pump.fromTopPlacement && pump.scrollstop) {
				for(i = 0; i < pump.l[0].m.length; i++) {
					o = pump.m[pump.l[0].m[i]].b;
					o.newCoords(o.x,pump.scrollY)
				}
			} else {
				if(pump.scrollstop) {
					for(i = 0; i < pump.l[0].m.length; i++) {
						o = pump.m[pump.l[0].m[i]].b;
						o.newCoords(o.x, pump.fromTopPlacement);
					}
				} else {
					for(i = 0; i < pump.l[0].m.length; i++) {
						o = pump.m[pump.l[0].m[i]].b;
						o.newCoords(o.x, o.oy + pump.scrollY);
					}
				}
			}
			pump.leftScroll = pump.scrollY;
			workSpaceObject.y = pump.scrollY;
			workSpaceObject.y2 = workSpaceObject.orgy + pump.scrollY;
			
			if(bowser.msie) {
				clearTimeout(pump.tim);
				pump.isover = 0;
				pump.hidesub();
			}
			
			if(pump.hideSelect) {
				
				var x = pump.m[pump.l[0].m[0]].b.x;
				var y = pump.m[pump.l[0].m[0]].b.y;
				
				if(pump.itemLayout)
					var maxWidth = pump.totw;
				else
					var maxWidth = pump.maxWidth;
	
				if(!pump.itemLayout)
					var maxHeight = pump.toth;
				else
					var maxHeight = pump.maxHeight;
					
				pump.hideSelect(0, x, y, maxWidth, maxHeight, 0);
			}
		}
		if(!bowser.msie) setTimeout(pump.name + ".scrollCheck()", 200);
	}
}


defineParent.prototype.onMakeVisible += ";this.pagecheck(b, parentMenu, parentMenu.subx, parentMenu.suby, maxWidth, maxHeight)";

defineParent.prototype.pagecheck = function(b, parentMenu, x, y, w, h, n) {  

	var l = parentMenu.lev + 1;
	
	var a = b.subPosition;
	
	if(!n) n = 1;
	
	var ok = 1;
	
	if(x < workSpaceObject.x) {
		parentMenu.subPosition = 1;
		ok = 0;
	} else if(x + w > workSpaceObject.x2) {
		parentMenu.subPosition = 1;
		ok = 0;
	} else if(y < workSpaceObject.y) {
		parentMenu.subPosition = 1;
		ok = 0;
	} else if(h + y > workSpaceObject.y2) {
		parentMenu.subPosition = 1;
		ok = 0;
	}
	
	
	if(!ok) {
		this.getcoords(parentMenu, this.l[l - 1].itemBorderX, this.l[l - 1].itemBorderY, parentMenu.b.x, parentMenu.b.y, w, h, this.l[l - 1].subMenuOffSetX, this.l[l - 1].subMenuOffSetY);
	}
	
	x = parentMenu.subx;
	y = parentMenu.suby;
	
	b.newCoords(x,y)
}

bowser.filter = (bowser.msie55 || bowser.msie6) && !bowser.mac;
defineParent.prototype.onMakeVisible += ";if(pump.l[parentMenu.lev].filter) b.filterIt(pump.l[parentMenu.lev].filter)";
tierObject.prototype.filter = null;
buildMenuObject.prototype.filterIt = function(f) {
	if(bowser.filter) {
		if(this.occurrence.filters[0]) this.occurrence.filters[0].Stop();
			else this.css.filter = f;
		this.occurrence.filters[0].Apply(); 
		this.makeVisible(); 
		this.occurrence.filters[0].Play();
	}
}

var keys = new Array();
function addHotKey(key, url, ctrlKey, altKey, shiftKey) {
	keys[keys.length] = new goHotKey(key, url, ctrlKey, altKey, shiftKey);
	return;
}

function checkKey(e) {
	var ctrl = 0;
	var alt = 0;
	var shift = 0;
	var code = (bowser.netscape4) ? e.which : event.keyCode;
	if(bowser.netscape4) {
		if(e.modifiers) {
			if(e.modifiers == 2) ctrl = 1;
			if(e.modifiers == 4) shift = 1;
		}
	} else {
		if(window.event) {
			if(window.event.ctrlKey) ctrl = 1;
			if(window.event.shiftKey) shift = 1;
			if(window.event.altKey) alt = 1;
		}
	}
	var key = String.fromCharCode(code);
	if(keys){
		for (var i = 0; i < keys.length; i++) {
			if (key == keys[i].key) {
				if(shift == keys[i].shiftKey) {
					if(ctrl == keys[i].ctrlKey) {
						if(alt == keys[i].ctrlKey) {
							location.href = keys[i].url;
							break;
						}
					}
				}
			}
		}
	}
}

function goHotKey(key, url, ctrlKey, altKey, shiftKey) {
  this.key = key;
  this.url = url;
  this.ctrlKey = ctrlKey;
  this.altKey = altKey;
  this.shiftKey = shiftKey;
}

if(bowser.netscape4) document.captureEvents(Event.KEYPRESS);

document.onkeypress = checkKey;


bpsM = new defineParent("bpsM");
bpsM.frames = 0;
bpsM.scrolling = 0;
bpsM.openOnClick = 0;
bpsM.closeOnClick =  0;
bpsM.closeDelay = 500;
bpsM.topItemSpace = 0;
bpsM.fromLeftPlacement = 8;
// La July 22 2008
// Increase top placement to allow for coupon banner
//bpsM.fromTopPlacement = 270;
bpsM.fromTopPlacement = 330;

bpsM.itemLayout = 0;
bpsM.topTierPlacement = "left";
bpsM.offlineRoot = "";
bpsM.onlineRoot = "";
bpsM.spacerImg = "";
bpsM.dividerImg = "";
bpsM.dividerHeight = 4;
bpsM.leftIconWidth = 10;

bpsM.tier[0] = new tierObject();
bpsM.tier[0].width = 165; // changed from 100 - TN, 1/9/06
bpsM.tier[0].height = 18;
bpsM.tier[0].normalClass = "bpsTop";
bpsM.tier[0].overClass = "bpsTopOver";
bpsM.tier[0].itemBorderX = 0;
bpsM.tier[0].itemBorderY = 0;
bpsM.tier[0].subMenuBorder = 1;
bpsM.tier[0].borderClass = "bpsBorder";
bpsM.tier[0].subMenuOffSetX = -2;
bpsM.tier[0].subMenuOffSetY = 0;
bpsM.tier[0].itemLayout = 0;
bpsM.tier[0].subPosition = "right";
bpsM.tier[0].arrowImage = 0;
bpsM.tier[0].arrowWidth = 7;
bpsM.tier[0].arrowHeight = 4;

bpsM.tier[1] = new tierObject();
bpsM.tier[1].width = 250;
bpsM.tier[1].height = 18;
bpsM.tier[1].normalClass = "bpsSub";
bpsM.tier[1].overClass = "bpsSubOver";
bpsM.tier[1].itemBorderX = 0;
bpsM.tier[1].itemBorderY = 0;
bpsM.tier[1].borderClass = "bpsBorder";
bpsM.tier[1].subMenuOffSetX = 0;
bpsM.tier[1].subMenuOffSetY = 0;
bpsM.tier[1].itemLayout = 0;
bpsM.tier[1].subPosition = 1;
bpsM.tier[1].arrowImage = 0;
bpsM.tier[1].arrowWidth = 4;
bpsM.tier[1].arrowHeight = 7;
