// MENU BUILDER

browser=identify_browser();
os=identify_os();
menu_ptr=new create_menu_struct();


function create_menu_struct() {
	this.menuActive=false;
	this.submenuArray=new Array(30);
	this.mainmenuArray=new Array(5);
	this.mainmenu_dirn=new Array(5);
	this.mainmenu_layout=new Array(5);
	this.activemenuArray=new Array(10);
	this.mmcp=0;
	this.smcp=0;
	this.mmac=0;
	this.smac=0;
	this.amac=0;
	this.menuoffset=10;
	this.ver="1.5";
	this.id="40190";
};


function mainMenu(layout,spacing,nbgcolor,hbgcolor,nftcolor,hftcolor,bgimage,menu_dirn) {
	this.itemArray=new Array(30);
	this.iac=0;
	menu_ptr.mainmenuArray[menu_ptr.mmac++]=this;
	this.count=1;
	this.name="aj"+menu_ptr.mmac;
	this.css="ajmainmenu";
	this.item='';
	this.htmlBefore='&nbsp;&nbsp;';
	this.htmlAfter='&nbsp;&nbsp;';
	this.macoffset=8;
	this.sp_item='';
	if(arguments.length >= 1&&arguments[0] == 'vertical') {
		this.layout='vertical';
		menu_ptr.mainmenu_layout[menu_ptr.mmac]='vertical';
	}
	else {
		this.layout='horizontal';
		menu_ptr.mainmenu_layout[menu_ptr.mmac]='horizontal';
	}
	if(arguments.length >= 2) {
		this.spacing=spacing;
	}
	else {
		this.spacing=0;
	}
	if(arguments.length >= 3) {
		this.nbgcolor=nbgcolor;
	}
	else {
		this.nbgcolor="black";
	}
	if(arguments.length >= 4) {
		this.hbgcolor=hbgcolor;
	}
	else {
		this.hbgcolor="black";
	}
	if(arguments.length >= 5) {
		this.nftcolor=nftcolor;
	}
	else {
		this.nftcolor="white";
	}
	if(arguments.length >= 6) {
		this.hftcolor=hftcolor;
	}
	else {
		this.hftcolor="white";
	}
	if(arguments.length >= 7&&arguments[6] != '') {
		this.bgimage=bgimage;
		this.nbgcolor='transparent';
	}
	else {
		this.bgimage=null;
	}
	if(arguments.length >= 8&&arguments[7] == 'left') {
		menu_ptr.mainmenu_dirn[menu_ptr.mmac]='left';
	}
	else {
		menu_ptr.mainmenu_dirn[menu_ptr.mmac]='right';
	}
	this.over_img=new Array(30);
	this.out_img=new Array(30);
	this.pad_1=0;
	this.pad_2=0;
	this.cellpadding=1;
	this.layerpadding=0;
	this.target='_self';
	this.valign='middle';
	this.menuborder='';
	this.itemborder='';
	this.divider='&nbsp;';
	this.writeMenu=write_main_menu;
	this.addItem=add_one_main_item;
	this.addItems=add_list_WithLink;
	this.addImages=addImages;
	this.addWithoutLink=add_list_WithoutLink;
	this.add_list_WithoutLink=gen_main_item_WithoutLink;
	this.addItemsWithTarget=add_list_WithTarget;
	this.addImagesWithTarget=addImagesWithTarget;
};


// OUTPUT HTML TO CREATE TABLE
function write_main_menu() {
	if(browser == "IE"||browser == "NS6") {
		document.writeln('<table ');
		if(this.nbgcolor != 'transparent') {
			document.writeln('bgcolor="'+this.nbgcolor+'" ');
		}
		if(this.bgimage != null) {
			document.writeln('background="'+this.bgimage+'" ');
		}
		document.writeln('border="0" cellpadding="'+this.cellpadding+'" cellspacing="0" onmouseout="menu_ptr.menuActive=false;" onmouseover="menu_ptr.menuActive=true;" style="border:'+this.menuborder+'">');
	}
	if(this.layout == 'vertical'&&this.pad_1 != 0) {
		document.writeln('<tr><td height="'+this.pad_1+'">&nbsp;</td></tr>');
	}
	if(this.layout == 'horizontal') {
		document.writeln('<tr>');
		if(this.pad_1 != 0) {
			document.writeln('<td width="'+this.pad_1+'">&nbsp;</td>');
		}
	}
	document.writeln(this.item);
	if(this.layout == 'horizontal') {
		if(this.pad_2 != 0) {
			document.writeln('<td width="'+this.pad_2+'">&nbsp;</td>');
		}
		document.writeln('</tr>');
	}
	if(this.layout == 'vertical'&&this.pad_2 != 0) {
		document.writeln('<tr><td height="'+this.pad_2+'">&nbsp;</td></tr>');
	}
	document.writeln('</table>');
};


function add_one_main_item(desc,URL,target,out_img,over_img) {
	var mname=this.name+'mi'+this.count;
	if(arguments.length<3||arguments[2] == null) {
		target=this.target;
	}
	desc=this.htmlBefore+desc+this.htmlAfter; 
	this.item+=this.sp_item;
	if(this.layout == 'vertical') {
		this.item+='<tr>';
	}
	if(browser == "IE"||browser == "NS6") {
		this.item+='<td onmouseover="mainMenuMouseOver(\''+this.name+'\',\''+this.count+'\',\''+menu_ptr.mmac+'\', \''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+over_img+'\',\''+this.macoffset+'\')" ';
		this.item+='onmouseout="mainMenuMouseOut(\''+this.name+'\',\''+this.count+'\', \''+this.nbgcolor+'\',\''+this.nftcolor+'\',\''+out_img+'\')" ';
		this.item+='nowrap valign="'+this.valign+'" style="border:'+this.itemborder+'">';
		this.item+='<div id="'+mname+'clip" style="position:absolute; width:0; height:0"></div>';
		this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px">';
		this.item+='<a href="'+URL+'" class="'+this.css+'" style="text-decoration:none"';
		if(target != '') { this.item+=' target="'+target+'"'; }
		if(URL == '') { this.item+=' onclick="return false;"'; }
		if(arguments.length == 5) {
			this.item+='><img id="'+this.name+'mi_img'+this.count+'" src="'+out_img+'" border="0"></a>';
		}
		else {
			this.item+='><font id="'+this.name+'a'+this.count+'" style="color:'+this.nftcolor+';">'+desc+'</font></a>';
		}
		this.item+='</div></td>';
	}
	this.itemArray[this.iac++]=mname;
	if(this.spacing != 0) {
		if(this.layout == 'vertical') {
			this.sp_item='<tr><td height="'+this.spacing+'"><font size="1pt">&nbsp;</font></td></tr>';
		}
		if(this.layout == 'horizontal') {
			this.sp_item='<td class="'+this.css+'" width="'+this.spacing+'" align="center"><font color="'+this.nftcolor+'">'+this.divider+'</font></td>';
		}
	}
	if(this.layout == 'vertical') {
		this.item+='</tr>';
	}
	this.count++;
};


function gen_main_item_WithoutLink(desc) {
	var mname=this.name+'mi'+this.count;
	desc=this.htmlBefore+desc+this.htmlAfter;
	this.item+=this.sp_item;
	if(this.layout == 'vertical') {
		this.item+='<tr>';
	}
	if(browser == "IE"||browser == "NS6") {
		this.item+='<td nowrap valign="'+this.valign+'" style="border:'+this.itemborder+'" class="'+this.css+'"><div id="'+mname+'clip" style="position:absolute; width:0; height:0"></div>';
		this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px;color:'+this.nftcolor+'">';
	}
	this.item+=desc;
	if(browser == "IE"||browser == "NS6") {
		this.item+='</div></td>';
	}
	this.itemArray[this.iac++]=mname;
	if(this.spacing != 0) {
		if(this.layout == 'vertical') {
			this.sp_item='<tr><td height="'+this.spacing+'"><font size="1pt">&nbsp;</font></td></tr>';
		}
		if(this.layout == 'horizontal') {
			this.sp_item='<td class="'+this.css+'" width="'+this.spacing+'" align="center"><font color="'+this.nftcolor+'">'+this.divider+'</font></td>';
		}
	}
	if(this.layout == 'vertical') {
		this.item+='</tr>';
	}
	this.count++;
};


function loadMenu() {
	if(browser == "NS6"&&version == 6.1) 
	{
		for(var i=0; i<menu_ptr.smac; i++) {
			var menu=menu_ptr.submenuArray[i];
			var name=menu.name;
			var count=name.substring(name.indexOf("aj")+2,name.indexOf("sm"));
			if(name.indexOf("i") == -1) {
				var t_name=name.replace("sm","mi");
				var main_menu=menu_ptr.mainmenuArray[parseInt(count)-1];
				if(main_menu.layout == 'vertical') {
					if(menu_ptr.mainmenu_dirn[parseInt(count)] == 'right') {
						set_position_to_left(name,get_X_coord(t_name)+get_width(t_name));
					}
					else {
						set_position_to_left(name,get_X_coord(t_name)-get_width(t_name));
					}
					set_top_position(name,get_Y_coord(t_name));
				}
				if(main_menu.layout == 'horizontal') {
					set_position_to_left(name,get_X_coord(t_name));
					set_top_position(name,get_Y_coord(t_name)+get_height(t_name));
				}
			}
			else {
				var t_name=name.substring(0,name.lastIndexOf("i"));
				var u_name=t_name+"itm"+name.substring(name.lastIndexOf("i")+1)+"clip";
				if(menu_ptr.mainmenu_dirn[parseInt(count)] == 'right') {
					set_position_to_left(name,get_left_offset(t_name)+get_width(t_name)-menu_ptr.menuoffset);
				}
				else {
					set_position_to_left(name,get_left_offset(t_name)-get_width(name)+menu_ptr.menuoffset);
				}
				set_top_position(name,get_Y_coord(t_name)+get_Y_coord(u_name));
			}
		}
	}
};


function mainMenuMouseOver(name,count,mmac,bgcolor,ftcolor,img,macoffset) {
	set_background_color(name+'mi'+count,bgcolor);
	set_foreground_color(name+'a'+count,ftcolor);
	cleanup_active_list();
	if(browser == "IE"||browser == "NS6") {
		if(element_exists(name+'sm'+count)) {
			menu_ptr.activemenuArray[menu_ptr.amac++]=name+'sm'+count;
			if(menu_ptr.mainmenu_layout[mmac] == "horizontal") {
				set_position_to_left(name+'sm'+count,get_X_coord(name+'mi'+count+'clip'));
				if(os == "MacX") {
					set_top_position(name+'sm'+count,get_Y_coord(name+'mi'+count+'clip')+get_height(name+'mi'+count)+macoffset);
				}
				else {
					set_top_position(name+'sm'+count,get_Y_coord(name+'mi'+count+'clip')+get_height(name+'mi'+count));
				}
			}
			if(menu_ptr.mainmenu_layout[mmac] == "vertical") {
				if(menu_ptr.mainmenu_dirn[mmac] == 'right') {
					set_position_to_left(name+'sm'+count,get_X_coord(name+'mi'+count+'clip')+get_width(name+'mi'+count));
				}
				else {
					set_position_to_left(name+'sm'+count,get_X_coord(name+'mi'+count+'clip')-get_width(name+'sm'+count));
				}
				if(os == "MacX") {
					set_top_position(name+'sm'+count,get_Y_coord(name+'mi'+count+'clip')+macoffset);
				}
				else {
					set_top_position(name+'sm'+count,get_Y_coord(name+'mi'+count+'clip'));
				}
			}
			change_visibility(name+'sm'+count,true);
		}
	}
	if((browser == "IE"||browser == "NS6")&&document.images[name+'mi_img'+count]) {
		document.images[name+'mi_img'+count].src=img;
	}
	menu_ptr.menuActive=true;
};


function mainMenuMouseOut(name,count,bgcolor,ftcolor,img) {
	set_background_color(name+'mi'+count,bgcolor);
	set_foreground_color(name+'a'+count,ftcolor);
	menu_ptr.menuActive=false;
	if((browser == "IE"||browser == "NS6")&&document.images[name+'mi_img'+count]) {
		document.images[name+'mi_img'+count].src=img;
	}
};


function subMenu(menuName,nbgcolor,hbgcolor,nftcolor,hftcolor,bgimage) {
	menu_ptr.submenuArray[menu_ptr.smac++]=this;
	this.itemArray=new Array(30);
	this.iac=0;
	if(arguments.length >= 2) {
		this.nbgcolor=nbgcolor;
	}
	else {
		this.nbgcolor="black";
	}
	if(arguments.length >= 3) {
		this.hbgcolor=hbgcolor;
	}
	else {
		this.hbgcolor="black";
	}
	if(arguments.length >= 4) {
		this.nftcolor=nftcolor;
	}
	else {
		this.nftcolor="white";
	}
	if(arguments.length >= 5) {
		this.hftcolor=hftcolor;
	}
	else {
		this.hftcolor="white";
	}
	if(arguments.length >= 6) {
		this.bgimage=bgimage;
		this.nbgcolor='transparent';
	}
	else {
		this.bgimage=null;
	}
	this.css="ajsubmenu";
	this.name="aj"+menu_ptr.mmac+"sm"+menuName;
	this.count=1;
	this.item='';
	this.htmlBefore='&nbsp;&nbsp;';
	this.htmlAfter='&nbsp;&nbsp;';
	this.cellpadding=1;
	this.layerpadding=0;
	this.menuborder='';
	this.itemborder='';
	this.target='_self';
	this.writeMenu=write_sub_menu;
	this.addItem=add_one_sub_item;
	this.addItems=add_list_WithLink;
	this.addWithoutLink=add_list_WithoutLink;
	this.add_list_WithoutLink=one_sub_item_WithoutLink;
	this.addItemsWithTarget=add_list_WithTarget;
};

function write_sub_menu() {
	if(browser == "IE"||browser == "NS6") {
	document.writeln('<div id="'+this.name+'" style="position:absolute; visibility:hidden; ');
	document.writeln('background-color:'+this.nbgcolor+'; z-index:30; border:'+this.menuborder+'"" ');
	document.writeln('onmouseout="menu_ptr.menuActive=false; " ');
	document.writeln('onmouseover="menu_ptr.menuActive=true; ">');
	document.writeln('<table border="0" cellspacing="0" cellpadding="'+this.cellpadding+'" ');
	if(this.bgimage != null) {
		document.writeln('background="'+this.bgimage+'" ');
	}
	document.writeln('id="'+this.name+'table">'+this.item+'</table></div>');
	}
	if(browser == "NS6"||(browser == "IE"&&version == 4)) {
		set_width(this.name,get_width(this.name+'table'));
	}
	set_position_to_left(this.name,8);
	set_top_position(this.name,8);
};

function add_one_sub_item(desc,URL,target) {
	if(arguments.length<3) {
		target=this.target;
	}
	desc=this.htmlBefore+desc+this.htmlAfter;
	var mname=this.name+'itm'+this.count;
	if(browser == "IE"||browser == "NS6") {
		this.item+='<tr><td class="'+this.css+'" valign="middle" nowrap ';
//fixDouble	this.item+='onclick="window.open(\''+URL+'\',\''+target+'\');" ';
		this.item+='onmouseover="subMenuMouseOver(\''+this.name+'\', \''+this.count+'\',\''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+menu_ptr.mmac+'\')" ';
		this.item+='onmouseout="subMenuMouseOut(\''+this.name+'\', \''+this.count+'\',\''+this.nbgcolor+'\',\''+this.nftcolor+'\')" ';
		this.item+='style="border:'+this.itemborder+'">';

		this.item+='<div id="'+mname+'clip" style="position:absolute; width:0; height:0"></div>';
		this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px">';

		this.item+='<a href="'+URL+'" class="'+this.css+'" style="text-decoration:none" ';
		if(target != '') { this.item+=' target="'+target+'"'; }
		if(URL == '') { this.item+=' onclick="return false; "'; }
		this.item+='>';
		this.item+='<font id="'+this.name+'a'+this.count+'" style="color:'+this.nftcolor+'; ">'+desc+'</font>';
		this.item+='</a>';
		this.item+='</div>';
		this.item+='</td></tr>\n';
	}
	this.count++;
};

function one_sub_item_WithoutLink(desc) {
	if(arguments.length<3) {
		target=this.target;
	}
	desc=this.htmlBefore+desc+this.htmlAfter;
	var mname=this.name+'itm'+this.count;
	if(browser == "IE"||browser == "NS6") {
	this.item+='<tr><td valign="middle" class="'+this.css+'" nowrap style="border:'+this.itemborder+'">';
	this.item+='<div id="'+mname+'clip" style="position:absolute; width:0; height:0"></div>';
	this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px;color:'+this.nftcolor+'">'+desc+'</div></td></tr>';
	}
	this.count++;
};

function subMenuMouseOver(name,count,bgcolor,fgcolor,mmac) {
	var tmp_amac=menu_ptr.amac;
	for(var i=0; i<tmp_amac; i++) {
		if(menu_ptr.activemenuArray[i] != name) {
			var tmp_name=name+'i'+count;
			if(tmp_name.indexOf(menu_ptr.activemenuArray[i]) == -1) {
				change_visibility(menu_ptr.activemenuArray[i],false);
				menu_ptr.amac--;
			}
		}
	}
	set_background_color(name+'itm'+count,bgcolor,name);
	set_foreground_color(name+'a'+count,fgcolor,name);
	if(browser == "IE"||browser == "NS6") {
		if(element_exists(name+'i'+count)) {
			menu_ptr.activemenuArray[menu_ptr.amac++]=name+'i'+count;
			if(menu_ptr.mainmenu_dirn[mmac] == 'right') {
				set_position_to_left(name+'i'+count,get_left_offset(name)+get_width(name)-menu_ptr.menuoffset);
			}
			else {
				set_position_to_left(name+'i'+count,get_left_offset(name)-get_width(name+'i'+count)+menu_ptr.menuoffset);
			}
			if(browser == "IE") {
				set_top_position(name+'i'+count,get_Y_coord(name)+get_Y_coord(name+'itm'+count+'clip'));
			}
			if(browser == "NS6") {
				if(version == 6.1) {
					set_top_position(name+'i'+count,get_Y_coord(name)+get_Y_coord(name+'itm'+count+'clip'));
				}
				else {
					set_top_position(name+'i'+count,get_Y_coord(name+'itm'+count+'clip'));
				}
			}
		}
	}
	change_visibility(name+'i'+count,true);
	menu_ptr.menuActive=true;
};


function subMenuMouseOut(name,count,bgcolor,fgcolor) {
	set_background_color(name+'itm'+count,bgcolor,name);
	set_foreground_color(name+'a'+count,fgcolor,name);
};


function add_list_WithLink() {
	for(var i=0; i<arguments.length; i+=2) {
		this.addItem(arguments[i],arguments[i+1]);
	}
};


function add_list_WithoutLink() {
	for(var i=0; i<arguments.length; i++) {
		this.add_list_WithoutLink(arguments[i]);
	}
};


function addImages() {
	for(var i=0; i<arguments.length; i+=3) {
		this.addItem(null,arguments[i],null,arguments[i+1],arguments[i+2]);
	}
};


function addImagesWithTarget() {
	for(var i=0; i<arguments.length; i+=4) {
		this.addItem(null,arguments[i],arguments[i+1],arguments[i+2],arguments[i+3]);
	}
};


function add_list_WithTarget() {
	for(var i=0; i<arguments.length; i+=3) {
		this.addItem(arguments[i],arguments[i+1],arguments[i+2]);
	}
};


function cleanup_active_list() {
	if(!menu_ptr.menuActive) {
		for(var i=0; i<menu_ptr.amac; i++) {
			change_visibility(menu_ptr.activemenuArray[i],false);
		}
		menu_ptr.amac=0;
	}
};

function displayMenu() {
	for(var i=menu_ptr.mmcp; i<menu_ptr.mmac; i++) {
		menu_ptr.mainmenuArray[i].writeMenu();
	}
	menu_ptr.mmcp=menu_ptr.mmac;
	for(var i=menu_ptr.smcp; i<menu_ptr.smac; i++) {
		menu_ptr.submenuArray[i].writeMenu();
	}
	menu_ptr.smcp=menu_ptr.smac;
	setInterval("cleanup_active_list()",300);
};

// window.onresize=window_resize;
// origWidth=window.innerWidth;
// origHeight=window.innerHeight;

// function window_resize() {
// 	return;
// };

