var GMENUS = new Array()
var GMENUIMAGES = new Array()
var INSET = 0

function ImageMenu (menuname) {
	this.name = menuname
	this.itemindex = 0
	this.Items = new Array()
	
	this.cellspacing = 0
	this.cellpadding = 0
	this.bgcolor = ''
	this.width = ''
	this.border = 0
	this.bordercolor = ''
	this.isvertical = true
	
	this.addMenuImage = addMenuImage
	this.addMenuText = addMenuText
	this.addMenuDivider = addMenuDivider
	this.getMenuString = getMenuString

	GMENUS[menuname] = this
}

function addMenuImage (url, alttext, coldimagefile, hotimagefile, isdefault, submenu) {
	var menuimage = new MenuImage(this, url, alttext, coldimagefile, hotimagefile, isdefault, submenu)

	this.Items[this.itemindex] = menuimage
	++this.itemindex

	this.Items[menuimage.name] = menuimage
	GMENUIMAGES[menuimage.name] = menuimage
	return menuimage
}

function addMenuText (url, text, coldcolor, hotcolor, isdefault, submenu) {
	var menutext = new MenuText(this, url, text, coldcolor, hotcolor, isdefault, submenu)

	this.Items[this.itemindex] = menutext
	++this.itemindex

	this.Items[menutext.name] = menutext
	return menutext
}

function addMenuDivider (type, info) {
	var menudiv = new MenuDivider(this, type, info)

	this.Items[this.itemindex] = menudiv
	++this.itemindex

	this.Items[menudiv.name] = menudiv
	return menudiv
}

function getMenuString () {
	if (this.Items.length) {
		var result = ""

		result = result.concat("<TABLE BORDER="+this.border+" CELLSPACING="+this.cellspacing+" CELLPADDING="+this.cellpadding+((this.width) ? " WIDTH="+this.width : "")+">\n")
		if (! this.isvertical) result = result.concat("<TR>\n");
		for (var i = 0; i < this.Items.length; i++) {
			++INSET
			var itemstring = this.Items[i].getItemString()
			if (itemstring) {
				if (this.isvertical) result = result.concat("<TR>\n");
				result = result.concat(itemstring);
				if (this.isvertical) result = result.concat("</TR>\n");
			}
			--INSET

		}
		if (! this.isvertical) result = result.concat("</TR>\n");
		result = result.concat("</TABLE>");
		
		return result;
	}
	return ""
}

function MenuImage(menu, url, alttext, coldimagefile, hotimagefile, isdefault, submenu) {
	this.url = url
	this.alttext = alttext
	this.isdefault = isdefault
	this.ishot = isdefault || false
	this.isvisible = true
	this.submenu = submenu

	this.align = "center"
	this.valign = "top"
	this.width = "";
	
	this.cold = new Image()
	this.cold.src = coldimagefile
	this.hot = new Image()
	this.hot.src = hotimagefile

	this.index = menu.itemindex


	this.name = "MI_"+menu.name+"_"+this.index

	this.getItemString = getImgString
}

function getImgString () {
	if (this.isvisible) {
		var imgtag = "<IMG SRC='"+(this.isdefault ? this.hot.src : this.cold.src)+"' BORDER=0 ALT='"+this.alttext+"' NAME='"+this.name+"'>"
		var result = "<TD nowrap valign='"+this.valign+"' align='"+this.align+"' "+((this.width != "") ? "width='"+this.width+"'" : "")+">"

		result = result.concat("<A HREF='"+this.url+"' NAME='link_"+this.name+"' onMouseOver=\"imageSwap(document.images."+this.name+")\" onMouseOut=\"imageSwap(document.images."+this.name+")\">"+imgtag+"</A><BR>\n")

		if (this.submenu) {
			result = result.concat(this.submenu.getMenuString())
		}

		result = result.concat("</TD>");

		return result
	}
	return ""
}

function MenuText(menu, url, text, coldcolor, hotcolor, isdefault, submenu) {
	this.url = url
	this.text = text
	this.isdefault = isdefault
	this.ishot = isdefault || false
	this.isvisible = true
	this.submenu = submenu

	this.align = "center"
	this.valign = "top"
	this.width = "";

	this.cold = coldcolor
	this.hot = hotcolor

	this.index = menu.itemindex

	this.name = "MT_"+menu.name+"_"+this.index

	this.getItemString = getTextString
}


function getTextString () {
	if (this.isvisible) {
		var result = "<TD nowrap valign='"+this.valign+"' align='"+this.align+"' "+((this.width != "") ? "width='"+this.width+"'" : "")+">"
		result = result.concat("<A HREF='"+this.url+"' NAME='"+this.name+"' STYLE=\"text-decoration: none; color: "+((this.isdefault) ? this.hot : this.cold)+"\">"+this.text+"</A><BR>\n")

		if (this.submenu) {
			result = result.concat(this.submenu.getMenuString())
		}
		result = result.concat("</TD>");
		return result
	}
	return ""
}

function MenuDivider(menu, type, info) {
	this.type = type
	this.info = info
	
	this.align = "center"
	this.valign = "middle"
	this.width = "";
	this.nowrap = true;
	this.isvisible = true;

	this.index = menu.itemindex

	this.name = "MD_"+menu.name+"_"+this.index

	this.getItemString = getDividerString
}


function getDividerString () {
	if (this.isvisible) {
		var result = "<TD"+(this.nowrap ? " nowrap" : "")+" valign='"+this.valign+"' align='"+this.align+"' "+((this.width != "") ? "width='"+this.width+"'" : "")+">"

		if (this.type == "image")
			result = result.concat("<IMG SRC='"+this.info+"' BORDER=0 ALT=''>");
		else 
			result = result.concat(this.info);

		result = result.concat("</TD>\n");
		return result
	}
	return ""
}

function imageSwap (imageObj) {
	var menuimage = GMENUIMAGES[imageObj.name]
	if (! menuimage.isdefault) {
		document.images[imageObj.name].src = menuimage.ishot ? menuimage.cold.src : menuimage.hot.src
		menuimage.ishot = ! menuimage.ishot
	}
	return true
}


function escape(text) {
	text = text.replace(/&/g, "&amp")
	text = text.replace(/</g, "&lt")
	text = text.replace(/>/g, "&gt")
	text = text.replace(/\n/g, "<BR>\n")
	return text
}


function openNewWindow(URLtoOpen, windowName, windowFeatures) {
	newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}


if(!window.saveInnerWidth) {
  window.onresize = resize;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
}

function resize() {
    if (saveInnerWidth < window.innerWidth || 
        saveInnerWidth > window.innerWidth || 
        saveInnerHeight > window.innerHeight || 
        saveInnerHeight < window.innerHeight ) 
    {
        window.history.go(0);
    }
}
