browser=getVersion();
os=getUserAgent();
ajm_state=new AJM_STATE();
MENU_PREF=new MenuPreferense();

function MenuPreferense(){
   this.htmlBefore='&nbsp;&nbsp;';
   this.htmlAfter='&nbsp;&nbsp;';
   this.sp_item='';
   this.pad_1=0;    //отступ меню слева
   this.pad_2=0;  //отступ меню справа
   this.cellpadding=0;  //отступ внутри меню между элементами
   this.cellspacing=1;  //отступ внутри меню между элементами
   this.layerpadding=2;  //отступ внутри меню от границы до элемента
   this.target='';
   this.valign='middle';
   this.menuborder='';
   this.menuborder1='';
   this.itemborder='';
   this.divider='&nbsp;';
   this.fontFamily='Verdana';
   this.fontStyle='none';
   this.fontSize='11px';
   this.fontWeight='bold';
   this.textDecoration='none';
   this.style='text-decoration: none;';
   this.astyle='text-decoration: none;';
   this.astyle1='text-decoration: none;';
   this.spacing=0;
   this.tbgcolor='#DDDDDD';
   this.nbgcolor='#FFFFFF';//'#FFFFFF'
   this.hbgcolor='#F0F0F0';
   this.nftcolor='#000000';
   this.hftcolor='#FF5A00';
   this.tbgcolor1='';
   this.nbgcolor1='';//'#FFFFFF'
   this.hbgcolor1='#F0F0F0';
   this.nftcolor1='#000000';
   this.hftcolor1='#FF5A00';
   this.arrow_image='/img/arr.gif';  
   this.text_arrow_image='';//<img src="'+this.arrow_image+'" border=0 alt="" align=middle width=11 height=10>';
   this.bgimage=null;  //path +  this.nbgcolor='transparent';
   this.layout='vertical';  // 'horizontal' , 'vertical'
   this.menu_dirn='right'; //'right' 'left'
}


function AJM_STATE(){
  this.menuActive=false;
  this.submenuArray=new Array(50);
  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.imgOutArray=new Array(50);
  this.imgOverArray=new Array(50);
  this.imac=0;
  if(os=="Mac"&&browser=="IE"){
	  this.mtopoffset=15;
	  this.mleftoffset=10;
	}
	else{
		this.mtopoffset=3;
		this.mleftoffset=0;
	}
	this.menuoffset=1;
	this.menuReady=false;
	this.menuStatus=1;
}

function SetFontPref(element){
  document.ids[element].fontFamily=this.fontFamily;
  document.ids[element].fontSize=this.fontSize;
  document.ids[element].fontStyle=this.fontStyle;
  document.ids[element].fontWeight=this.fontWeight;
  document.ids[element].textDecoration=this.textDecoration;
}

function mainMenu(){
  this.itemArray=new Array(30);
  this.iac=0;
  ajm_state.mainmenuArray[ajm_state.mmac++]=this;
  this.count=1;
  this.name='aj'+ajm_state.mmac;
  this.over_img=new Array(30);
  this.out_img=new Array(30);
  this.item='';

  this.htmlBefore=MENU_PREF.htmlBefore;
  this.htmlAfter=MENU_PREF.htmlAfter; 
  this.sp_item=MENU_PREF.sp_item;               
  this.pad_1=MENU_PREF.pad_1;                  
  this.pad_2=MENU_PREF.pad_2;                  
  this.cellpadding=MENU_PREF.cellpadding;            
  this.cellspacing=MENU_PREF.cellspacing;            
  this.layerpadding=MENU_PREF.layerpadding;           
  this.target=MENU_PREF.target;           
  this.valign=MENU_PREF.valign;          
  this.menuborder=MENU_PREF.menuborder1;            
  this.itemborder=MENU_PREF.itemborder;            
  this.divider=MENU_PREF.divider;         
  this.fontFamily=MENU_PREF.fontFamily;       
  this.fontStyle=MENU_PREF.fontStyle;         
  this.fontSize=MENU_PREF.fontSize;          
  this.fontWeight=MENU_PREF.fontWeight;        
  this.textDecoration=MENU_PREF.textDecoration;    
  this.style=MENU_PREF.style;                 
  this.astyle=MENU_PREF.astyle1;                 
  this.spacing=MENU_PREF.spacing;                
  this.tbgcolor=MENU_PREF.tbgcolor1;       
  this.nbgcolor=MENU_PREF.nbgcolor1;       
  this.hbgcolor=MENU_PREF.hbgcolor1;       
  this.nftcolor=MENU_PREF.nftcolor1;       
  this.hftcolor=MENU_PREF.hftcolor1;       
  if(MENU_PREF.layout=='vertical'){
   this.layout='vertical';
   ajm_state.mainmenu_layout[ajm_state.mmac]='vertical';
  }
  else{
   this.layout='horizontal';
   ajm_state.mainmenu_layout[ajm_state.mmac]='horizontal';
  }
  if(MENU_PREF.menu_dirn=='left'){
  	ajm_state.mainmenu_dirn[ajm_state.mmac]='left';
  }
  else{
  	ajm_state.mainmenu_dirn[ajm_state.mmac]='right';
  }
  if(MENU_PREF.bgimage!=null){
    this.bgimage=MENU_PREF.bgimage;
    this.nbgcolor='transparent';
  }
  else{
    this.bgimage=null;
  }
  
  this.SetFontPref=SetFontPref;
  this.writeMenu=MainWriteMenu;
  this.addItem=addItem;
  this.addItems=addItems;
  this.addImages=addImages;
  this.addWithoutLink=MenuAddWithoutLink;
  this.MenuAddWithoutLink=addItemSansLink;
  this.addItemsWithTarget=addItemsWithTarget;
  this.addImagesWithTarget=addImagesWithTarget;
  this.displayMMenu=AJMSetStatus;
}

function AJMSetStatus(){
	ajm_state.menuStatus=0;
  ajm_state.menuReady=true;
}

function MainWriteMenu(){
  this.displayMMenu();
  if(browser=="NS4"){
	  document.writeln('<table bgcolor="'+this.tbgcolor+'"');
		document.writeln('border="0" cellpadding="'+this.cellpadding+'" cellspacing="'+this.cellspacing+'">');
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
	  document.writeln('<table id="'+this.name+'table" ');
    document.writeln('bgcolor="'+this.tbgcolor+'" ');
	  document.writeln('border="0" cellpadding="'+this.cellpadding+'" cellspacing="'+this.cellspacing+'" onmouseout="ajm_state.menuActive=false;" onmouseover="ajm_state.menuActive=true;" style="border:'+this.menuborder+'">');
  }
  if(this.layout=='vertical'&&this.pad_1!=0){
	  document.writeln('<tr ');
  	if(this.nbgcolor!='transparent'){
		  document.writeln('bgcolor="'+this.nbgcolor+'" ');
	  }
  	if(this.bgimage!=null){
		  document.writeln('background="'+this.bgimage+'" ');
	  }
	  else{
		  document.writeln('background="" ');
	  }
	  document.writeln('><td height="'+this.pad_1+'">&nbsp;</td></tr>');
  }
  if(this.layout=='horizontal'){
	  document.writeln('<tr ');
  	if(this.nbgcolor!='transparent'){
		  document.writeln('bgcolor="'+this.nbgcolor+'" ');
	  }
  	if(this.bgimage!=null){
		  document.writeln('background="'+this.bgimage+'" ');
	  }
	  else{
		  document.writeln('background="" ');
	  }
	  document.writeln('>');
  	if(this.pad_1!=0){
		  document.writeln('<td width="'+this.pad_1+'">&nbsp;</td>');
  	}
  }
  if(ajm_state.menuStatus==0){
	  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');
  	if(this.nbgcolor!='transparent'){
		  document.writeln('bgcolor="'+this.nbgcolor+'" ');
	  }
  	if(this.bgimage!=null){
		  document.writeln('background="'+this.bgimage+'" ');
	  }
	  else{
		  document.writeln('background="" ');
	  }
	  document.writeln('><td height="'+this.pad_2+'">&nbsp;</td></tr>');
  }
  document.writeln('</table>');
}

function addItem(desc,URL,target,submenu,out_img,over_img){
	var mname=this.name+'mi'+this.count;
	this.style='font-family:'+this.fontFamily+';font-style:'+this.fontStyle+';font-size:'+this.fontSize+';font-weight:'+this.fontWeight+';text-decoration:'+this.textDecoration;
  if(arguments.length<3||arguments[2]==null){
	  target=this.target;
  }
  if(browser=="NS4"){
  	desc='<font color="'+this.nftcolor+'">'+this.htmlBefore+desc+this.htmlAfter+'</font>';
  }
  else{
	  desc=this.htmlBefore+desc+this.htmlAfter;
  }
  if(this.layout=='vertical' && submenu=="1"){
   desc+=MENU_PREF.text_arrow_image;
  }
  this.item+=this.sp_item;
  if(this.layout=='vertical'){
	  this.item+='<tr ';
  	if(this.nbgcolor!='transparent'){
		  this.item+='bgcolor="'+this.nbgcolor+'" ';
	  }
  	if(this.bgimage!=null){
		  this.item+='background="'+this.bgimage+'" ';
	  }
	  else{
		  this.item+='background="" ';
	  }
    this.item+='>';
  }

  
  if(browser=="NS4"){
    this.item+='<td nowrap valign="'+this.valign+'"><ilayer id="'+mname+'clip" z-index="28" visibility="hide">';
    this.item+='<a href="'+URL+'" id="'+this.name+'ai'+this.count+'">';
    if(arguments.length==5){
      this.item+='<img id="'+this.name+'mi_img'+this.count+'clip" src="'+out_img+'" border="0"></font></a>';
      }
    else{
      this.item+=desc+'</a>';
      }
    this.item+='</ilayer>';
    this.item+='<layer id="'+mname+'" z-index="29" width="300" visibility="hide" ';
    if(this.nbgcolor!='transparent'){
      this.item+='bgColor="'+this.nbgcolor+'" ';
      }
    this.item+='onmouseover="mainMenuMouseOver(\''+this.name+'\',\''+this.count+'\',\''+ajm_state.mmac+'\',\''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+ajm_state.imac+'\')" onmouseout="mainMenuMouseOut(\''+this.name+'\',\''+this.count+'\',\''+this.nbgcolor+'\',\''+this.nftcolor+'\',\''+ajm_state.imac+'\')">';
      
    if(arguments.length==6){
      ajm_state.imgOverArray[ajm_state.imac]=new Image();
      ajm_state.imgOverArray[ajm_state.imac].src=over_img;
      ajm_state.imgOutArray[ajm_state.imac]=new Image();
      ajm_state.imgOutArray[ajm_state.imac++].src=out_img;
      }
    this.item+='<a href="'+URL+'" id="'+this.name+'a'+this.count+'"';
    if(target!=''){
       this.item+=' target="'+target+'"';
       }
    if(URL==''){
      this.item+=' onclick="return false;"';
      }

    if(arguments.length==6){
      this.item+='><img id="'+this.name+'mi_img'+this.count+'" src="'+out_img+'" border="0"></a>';
      }
    else{
      this.item+='><img id="'+this.name+'mi_img'+this.count+'" src="'+out_img+'" border="0">'+desc+'</a>';
      }
    this.item+='</layer></td>';
    this.SetFontPref(this.name+'ai'+this.count);
    this.SetFontPref(this.name+'a'+this.count);
    this.SetFontPref(this.name+'d'+this.count);
    }

  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
    var tStr;
    tStr=URL.toLowerCase();
    if(tStr.indexOf("javascript:")==0){
      tStr=URL.substring(11,URL.length);
      }
    else {
      if(tStr.indexOf("'")==-1&&tStr.indexOf('"')==-1) {
        if(target!=''){
          tStr='window.open(\''+URL+'\'';
          tStr+=',\''+target+'\'';
          tStr+=')';
          }
        else tStr='document.location=\''+URL+'\'';
        }
      else { tStr=''; }
    }
    this.item+='<td style="font-size:1px" onclick="'+tStr+'" onmouseover="mainMenuMouseOver(\''+this.name+'\',\''+this.count+'\',\''+ajm_state.mmac+'\', \''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+ajm_state.imac+'\')" onmouseout="mainMenuMouseOut(\''+this.name+'\',\''+this.count+'\', \''+this.nbgcolor+'\',\''+this.nftcolor+'\',\''+ajm_state.imac+'\');" nowrap valign="'+this.valign+'" style="border:'+this.itemborder+'"><div id="'+mname+'clip" style="position:absolute;width:1;height:1"></div>';
    this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px">';
    this.item+='<a href="'+URL+'" style="text-decoration:none"';
    if(browser!="Opera") {this.item+=' onclick="return false;"'; }
    if(URL==''){
      this.item+=' onmouseover="self.status=\'\';return true;"';
      }
    if(target!=''){
      this.item+=' target="'+target+'"';
      }
  
    if(arguments.length==6){
      this.item+='><img id="'+this.name+'mi_img'+this.count+'" src="'+out_img+'" border="0"><font id="'+this.name+'a'+this.count+'" style="'+this.style+';color:'+this.nftcolor+';">'+desc+'</font></a>';
      ajm_state.imgOverArray[ajm_state.imac]=new Image();
      ajm_state.imgOverArray[ajm_state.imac].src=over_img;
      ajm_state.imgOutArray[ajm_state.imac]=new Image();
      ajm_state.imgOutArray[ajm_state.imac++].src=out_img;
      }
    else {
      this.item+='><font id="'+this.name+'a'+this.count+'" style="'+this.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.item+='<tr ';
    	if(this.nbgcolor!='transparent'){
  		  this.item+='bgcolor="'+this.nbgcolor+'" ';
  	  }
    	if(this.bgimage!=null){
  		  this.item+='background="'+this.bgimage+'" ';
  	  }
  	  else{
  		  this.item+='background="" ';
  	  }
		  this.item+='><td height="'+this.spacing+'"><font size="1pt">&nbsp;</font></td></tr>';
	  }
  	if(this.layout=='horizontal'){
		  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
			  this.sp_item='<td width="'+this.spacing+'" align="center"><font color="'+this.nftcolor+'" style="'+this.style+'">'+this.divider+'</font></td>';
		  }
		  if(browser=="NS4"){
			  this.sp_item='<td width="'+this.spacing+'" align="center"><font color="'+this.nftcolor+'" id="'+this.name+'d'+this.count+'">'+this.divider+'</font></td>';
		  }
	  }
  }
  if(this.layout=='vertical'){
	  this.item+='</tr>';
  }
  this.count++;
}

function addItemSansLink(desc){
  var mname=this.name+'mi'+this.count;
  this.style='font-family:'+this.fontFamily+';font-style:'+this.fontStyle+';font-size:'+this.fontSize+';font-weight:'+this.fontWeight+';text-decoration:'+this.textDecoration;
  if(browser=="NS4"){
	  desc=this.htmlBefore+'<font color="'+this.nftcolor+'">'+desc+'</font>'+this.htmlAfter;
  }
  else{
	  desc=this.htmlBefore+desc+this.htmlAfter;
  }
  this.item+=this.sp_item;
  if(this.layout=='vertical'){
	  this.item+='<tr ';
   	if(this.nbgcolor!='transparent'){
 		  this.item+='bgcolor="'+this.nbgcolor+'" ';
 	  }
   	if(this.bgimage!=null){
 		  this.item+='background="'+this.bgimage+'" ';
 	  }
 	  else{
 		  this.item+='background="" ';
 	  }
  }
  if(browser=="NS4"){
	  this.item+='<td valign="'+this.valign+'"><ilayer id="'+mname+'clip" z-index="28" visibility="hide">';
  	this.item+=desc;
	  this.item+='</ilayer>';
  	this.item+='<layer id="'+mname+'" z-index="29" width="300" visibility="hide" ';
  	if(this.nbgcolor!='transparent'){
  		this.item+='bgColor="'+this.nbgcolor+'" ';
	  }
  	this.item+='>';
  	this.SetFontPref(mname+'clip');
  	this.SetFontPref(mname);
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
	  this.item+='<td valign="'+this.valign+'" style="'+this.style+';border:'+this.itemborder+'"><div id="'+mname+'clip" style="position:absolute;width:1;height:1"></div>';
	  this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px;color:'+this.nftcolor+'">';
  }
  this.item+=desc;
  if(browser=="NS4"){
	  this.item+='</layer></td>';
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
  	this.item+='</div></td>';
  }
  this.itemArray[this.iac++]=mname;
  if(this.spacing!=0){
	  if(this.layout=='vertical'){
  		this.sp_item='<tr ';
    	if(this.nbgcolor!='transparent'){
  		  this.sp_item+='bgcolor="'+this.nbgcolor+'" ';
  	  }
    	if(this.bgimage!=null){
  		  this.sp_item+='background="'+this.bgimage+'" ';
  	  }
  	  else{
  		  this.sp_item+='background="" ';
  	  }
  		this.sp_item+='><td height="'+this.spacing+'"><font style="font-size:1pt">&nbsp;</font></td></tr>';
	  }
  	if(this.layout=='horizontal'){
		  this.sp_item='<td width="'+this.spacing+'" align="center"><font color="'+this.nftcolor+'" style="'+this.style+'">'+this.divider+'</font></td>';
	  }
  }
  if(this.layout=='vertical'){
  	this.item+='</tr>';
  }
  this.count++;
}


function mainMenuMouseOver(name,count,mmac,bgcolor,ftcolor,img){
  var left;
  var top;
  var nm1=name+'sm'+count;
  var nm2=name+'mi'+count;
  if(browser!="Opera"){
	  SetBgColor(nm2,bgcolor);
  	SetFgColor(name+'a'+count,ftcolor);
  }
  ShowElements();
  if(browser=="NS4"){
	  if(GetLayer(nm1)){
  		ajm_state.activemenuArray[ajm_state.amac++]=nm1;
  	  if(ajm_state.mainmenu_layout[mmac]=="horizontal"){
    		left=GetPageX(nm2);
  		  top=GetPageY(nm2)+GetHeight(nm2);
  		  SetLeftPos(nm1,left);
  		  SetPosTop(nm1,top);
  	  }
      if(ajm_state.mainmenu_layout[mmac]=="vertical"){
      	if(ajm_state.mainmenu_dirn[mmac]=='right'){
    		  left=GetPageX(nm2)+GetWidth(nm2);
    	  	SetLeftPos(nm1,left);
    	  }
      	else{
    		  left=GetPageX(nm2)-GetWidth(nm1);
    		  SetLeftPos(nm1,left);
    	  }
    	  top=GetPageY(nm2);
      	SetPosTop(nm1,top);
    	}
  	}
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
  	if(GetLayer(nm1)){
		  ajm_state.activemenuArray[ajm_state.amac++]=nm1;
		  if(ajm_state.mainmenu_layout[mmac]=="horizontal"){
			  top=GetPageY(nm2+'clip')+GetHeight(nm2)+ajm_state.mtopoffset;
			  left=GetPageX(nm2+'clip')+ajm_state.mleftoffset;
			  if(browser=="Opera"){
				  top+=2;
			  }
			  SetPosTop(nm1,top);
			  SetLeftPos(nm1,left);
		  }
			if(ajm_state.mainmenu_layout[mmac]=="vertical"){
			  left=GetPageX(nm2+'clip')+ajm_state.mleftoffset;
			  if(ajm_state.mainmenu_dirn[mmac]=='right'){
  			  left+=GetWidth(nm2);
  		  }
  		  else{
  			  left-=GetWidth(nm1);
  		  }
  		  top=GetPageY(nm2+'clip')+ajm_state.mtopoffset;
  		  SetPosTop(nm1,top);
  		  SetLeftPos(nm1,left);
  	  }
	  }
  }
  if(browser=="NS4"&&img!="undefined"&&document.layers[nm2].document.images.length!=0){
	  document.layers[nm2].document.images[0].src=ajm_state.imgOverArray[img].src;
  }
  if((browser=="IE"||browser=="NS6"||browser=="Opera")&&document.images[name+'mi_img'+count]){
	  document.images[name+'mi_img'+count].src=ajm_state.imgOverArray[img].src;
  }
  ajm_state.menuActive=true;
  if(GetLayer(nm1)){
	  if(left<GetWindowLeft()){
  		SetLeftPos(nm1,GetWindowLeft());
		}
	  if(left+GetWidth(nm1)>GetWindowWidth()){
		  SetLeftPos(nm1,GetWindowWidth()-GetWidth(nm1));
	  }
  	if(top<GetWindowTop()){
		  SetPosTop(nm1,GetWindowTop());
	  }
	  if(top+GetHeight(nm1)>GetWindowHeight()){
		  SetPosTop(nm1,GetWindowHeight()-GetHeight(nm1));
	  }
  }
  ShowElement(nm1,true);
}

function mainMenuMouseOut(name,count,bgcolor,ftcolor,img){
  if(browser!="Opera"){
	  SetBgColor(name+'mi'+count,bgcolor);
  	SetFgColor(name+'a'+count,ftcolor);
  }
  ajm_state.menuActive=false;
  if(browser=="NS4"&&img!="undefined"&&document.layers[name+'mi'+count].document.images.length!=0){
	  document.layers[name+'mi'+count].document.images[0].src=ajm_state.imgOutArray[img].src;
  }
  if((browser=="IE"||browser=="NS6"||browser=="Opera")&&document.images[name+'mi_img'+count]){
  	document.images[name+'mi_img'+count].src=ajm_state.imgOutArray[img].src;
  }
  setTimeout("ShowElements()",300);
}

function subMenu(menuName){
  ajm_state.submenuArray[ajm_state.smac++]=this;
  this.itemArray=new Array(50);
  this.iac=0;
  this.name="aj"+ajm_state.mmac+"sm"+menuName;
  this.count=1;
  this.item='';

  this.htmlBefore=MENU_PREF.htmlBefore;
  this.htmlAfter=MENU_PREF.htmlAfter;
  this.sp_item=MENU_PREF.sp_item;
  this.pad_1=MENU_PREF.pad_1;
  this.pad_2=MENU_PREF.pad_2;
  this.cellpadding=MENU_PREF.cellpadding;
  this.cellspacing=MENU_PREF.cellspacing;
  this.layerpadding=MENU_PREF.layerpadding;
  this.target=MENU_PREF.target;
  this.valign=MENU_PREF.valign;
  this.menuborder=MENU_PREF.menuborder;
  this.itemborder=MENU_PREF.itemborder;
  this.divider=MENU_PREF.divider;
  this.fontFamily=MENU_PREF.fontFamily;
  this.fontStyle=MENU_PREF.fontStyle;
  this.fontSize=MENU_PREF.fontSize;
  this.fontWeight=MENU_PREF.fontWeight;
  this.textDecoration=MENU_PREF.textDecoration;
  this.style=MENU_PREF.style;
  this.astyle=MENU_PREF.astyle;
  this.spacing=MENU_PREF.spacing;
  this.tbgcolor=MENU_PREF.tbgcolor;       
  this.nbgcolor=MENU_PREF.nbgcolor;
  this.hbgcolor=MENU_PREF.hbgcolor;
  this.nftcolor=MENU_PREF.nftcolor;
  this.hftcolor=MENU_PREF.hftcolor;
  if(MENU_PREF.bgimage!=null){
    this.bgimage=MENU_PREF.bgimage;
    this.nbgcolor='transparent';
  }
  else{
    this.bgimage=null;
  }
  this.SetFontPref=SetFontPref;
  this.writeMenu=SubMenuWrite;
  this.addItem=SubMenuAddItem;
  this.addItems=addItems;
  this.addWithoutLink=MenuAddWithoutLink;
  this.MenuAddWithoutLink=SubMenuAddItemSansLink;
  this.addItemsWithTarget=addItemsWithTarget;
}

function SubMenuWrite(){
  if(browser=="NS4"){
	  document.writeln('<layer id="'+this.name+'" ');
  	if(this.nbgcolor!='transparent'){
		  document.writeln('bgColor="'+this.nbgcolor+'" ');
	  }
  	if(this.bgimage!=null){
		  document.writeln('background="'+this.bgimage+'" ');
	  }
  	document.writeln('visibility="hide" z-index="30" onmouseout="ajm_state.menuActive=false;" onmouseover="ajm_state.menuActive=true;"><layer visibility="hide"></layer><table bgcolor="'+this.tbgcolor+'" border="0" cellspacing="'+this.cellspacing+'" cellpadding="'+this.cellpadding+'" background="" ');
	  if(this.nbgcolor!='transparent'){
  		document.writeln('bgColor="'+this.nbgcolor+'" ');
	  }
  	document.writeln('>');
	  document.writeln(this.item);
  	document.writeln('</table></layer>');
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
	  document.writeln('<div align="left" id="'+this.name+'" style="position:absolute;background-color:'+this.nbgcolor+';z-index:30;border:'+this.menuborder+';visibility:hidden" onmouseout="ajm_state.menuActive=false;" onmouseover="ajm_state.menuActive=true;">');
	  document.writeln('<table bgcolor="'+this.tbgcolor+'" border="0" style="left:0;top:0" cellspacing="'+this.cellspacing+'" cellpadding="'+this.cellpadding+'" ');
  	document.writeln('id="'+this.name+'table">'+this.item+'</table></div>');
  }
  if(browser=="NS6"||(browser=="IE"&&version==4)){
  	SetWidth(this.name,GetWidth(this.name+'table'));
  }
}

function SubMenuAddItem(desc,URL,target,submenu){
  this.style='font-family:'+this.fontFamily+';font-style:'+this.fontStyle+';font-size:'+this.fontSize+';font-weight:'+this.fontWeight+';text-decoration:'+this.textDecoration;
  if(arguments.length<3){
	  target=this.target;
  }
  desc=this.htmlBefore+desc+this.htmlAfter;
  if(submenu=="1"){
   desc+=MENU_PREF.text_arrow_image;
  }
  var mname=this.name+'itm'+this.count;
  if(browser=="NS4"){
	  this.item+='<tr ';
  	if(this.nbgcolor!='transparent'){
		  this.item+='bgcolor="'+this.nbgcolor+'" ';
	  }
  	if(this.bgimage!=null){
		  this.item+='background="'+this.bgimage+'" ';
	  }
	  else{
		  this.item+='background="" ';
	  }
    this.item+='><td valign="middle">';
  	this.item+='<ilayer z-index="29" id="'+mname+'clip" visibility="hide">'+desc+'</ilayer>';
	  this.item+='<layer z-index="30" id="'+mname+'" ';
	  if(this.nbgcolor!='transparent'){
		  this.item+='bgColor="'+this.nbgcolor+'" ';
	  }
	  this.item+='width="350" onmouseover="subMenuMouseOver(\''+this.name+'\',\''+this.count+'\',\''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+ajm_state.mmac+'\')" onmouseout="subMenuMouseOut(\''+this.name+'\',\''+this.count+'\',\''+this.nbgcolor+'\',\''+this.nftcolor+'\')"><a style="'+this.astyle+'" id="'+mname+'a" href="'+URL+'"';
	  if(target!=''){
		  this.item+=' target="'+target+'"';
	  }
	  if(URL==''){
		  this.item+=' onclick="return false;"';
	  }
   this.item+='><font color="'+this.nftcolor+'">'+desc+'</font></a></layer>';
   this.item+='</td></tr>';
   this.itemArray[this.iac++]=mname;
   this.SetFontPref(mname);
   this.SetFontPref(mname+'clip');
   this.SetFontPref(mname+'a');
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
    var tStr;
    tStr=URL.toLowerCase();
    if(tStr.indexOf("javascript:")==0){
   	  tStr=URL.substring(11,URL.length);
 	  }
 	  else{
		  if(tStr.indexOf("'")==-1&&tStr.indexOf('"')==-1){
		    if(target!=''){
  		  	tStr='window.open(\''+URL+'\'';
   		  	tStr+=',\''+target+'\'';
  		  	tStr+=')';
		  	}
		  	else
         tStr='document.location=\''+URL+'\'';
	  	}
	  	else{
  			tStr='';
		  }
    }
	  this.item+='<tr ';
  	if(this.nbgcolor!='transparent'){
		  this.item+='bgcolor="'+this.nbgcolor+'" ';
	  }
  	if(this.bgimage!=null){
		  this.item+='background="'+this.bgimage+'" ';
	  }
	  else{
		  this.item+='background="" ';
	  }
	  this.item+='><td valign="middle" onclick="'+tStr+'" onmouseover="subMenuMouseOver(\''+this.name+'\', \''+this.count+'\',\''+this.hbgcolor+'\',\''+this.hftcolor+'\',\''+ajm_state.mmac+'\')" onmouseout="subMenuMouseOut(\''+this.name+'\', \''+this.count+'\',\''+this.nbgcolor+'\',\''+this.nftcolor+'\')" style="border:'+this.itemborder+'"><div id="'+mname+'clip" style="position:absolute;width:1;height:1"></div>';
	  this.item+='<div id="'+mname+'" style="padding:'+this.layerpadding+'px"><a style="'+this.astyle+'" href="'+URL+'" style="text-decoration:none"';
	  if(browser!="Opera"){
  		this.item+=' onclick="return false;"';
	  }
  	if(target!=''){
		  this.item+=' target="'+target+'"';
	  }
 		this.item+='><font id="'+this.name+'a'+this.count+'" style="'+this.style+';color:'+this.nftcolor+';">'+desc+'</font></a></div></td></tr>';
	}
  this.count++;
}

function SubMenuAddItemSansLink(desc){
  this.style='font-family:'+this.fontFamily+';font-style:'+this.fontStyle+';font-size:'+this.fontSize+';font-weight:'+this.fontWeight+';text-decoration:'+this.textDecoration;
  if(browser=="NS4"){
	  desc=this.htmlBefore+'<font color="'+this.nftcolor+'">'+desc+'</font>'+this.htmlAfter;
  }
  else{
	  desc=this.htmlBefore+desc+this.htmlAfter;
  }
  var mname=this.name+'itm'+this.count;
  if(browser=="NS4"){
    this.item+='<tr ';
  	if(this.nbgcolor!='transparent'){
		  this.item+='bgcolor="'+this.nbgcolor+'" ';
	  }
  	if(this.bgimage!=null){
		  this.item+='background="'+this.bgimage+'" ';
	  }
	  else{
		  this.item+='background="" ';
	  }
    this.item+='><td valign="middle">';
    this.item+='<ilayer z-index="29" id="'+mname+'clip" visibility="hide">'+desc+'</ilayer>';
    this.item+='<layer z-index="30" id="'+mname+'" ';
    if(this.nbgcolor!='transparent'){
  	  this.item+='bgColor="'+this.nbgcolor+'" ';
    }
    this.item+='width="350">'+desc+'</layer>';
    this.item+='</td></tr>';
    this.itemArray[this.iac++]=mname;
    this.SetFontPref(mname+'clip');
    this.SetFontPref(mname);
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
    this.item+='<tr ';
  	if(this.nbgcolor!='transparent'){
		  this.item+='bgcolor="'+this.nbgcolor+'" ';
	  }
  	if(this.bgimage!=null){
		  this.item+='background="'+this.bgimage+'" ';
	  }
	  else{
		  this.item+='background="" ';
	  }
	  this.item+='><td valign="middle" style="border:'+this.itemborder+'"><div id="'+mname+'clip" style="position:absolute;width:1;height:1"></div>';
  	this.item+='<div id="'+mname+'" style="'+this.style+';padding:'+this.layerpadding+'px;color:'+this.nftcolor+'">'+desc+'</div></td></tr>';
  }
  this.count++;
}

function subMenuMouseOver(name,count,bgcolor,fgcolor,mmac){
  var tmp_amac=ajm_state.amac;
  var left;
  var top;
  var nm1=name+'i'+count;
  var nm2=name+'itm'+count;
  for(var i=0;i<tmp_amac;i++){
	  if(ajm_state.activemenuArray[i]!=name){
    	if(nm1.indexOf(ajm_state.activemenuArray[i])==-1){
  
  		  ShowElement(ajm_state.activemenuArray[i],false);
  		  ajm_state.amac--;
  	  }
    }
  }
  if(browser!="Opera"){
	  SetBgColor(nm2,bgcolor,name);
  	SetFgColor(name+'a'+count,fgcolor,name);
	}
  if(browser=="NS4"){
  	if(GetLayer(nm1)){
		  ajm_state.activemenuArray[ajm_state.amac++]=nm1;
		  if(ajm_state.mainmenu_dirn[mmac]=='right'){
			  left=GetPageX(name)+GetWidth(name)-ajm_state.menuoffset;
			  SetLeftPos(nm1,left);
		  }
  		else{
  		  if(GetPageX(name)-GetWidth(nm1)+ajm_state.menuoffset>0){
  			  left=GetPageX(name)-GetWidth(nm1)+ajm_state.menuoffset;
  			  SetLeftPos(nm1,left);
  		  }
  		  else{
  			  left=0;
  			  SetLeftPos(nm1,0);
  		  }
  	  }
    	top=GetPageY(nm2,name);
  	  SetPosTop(nm1,top);
	  }
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
  	if(GetLayer(nm1)){
		  ajm_state.activemenuArray[ajm_state.amac++]=nm1;
		  if(ajm_state.mainmenu_dirn[mmac]=='right'){
			  left=GetLeftPos(name)+GetWidth(name)-ajm_state.menuoffset+ajm_state.mleftoffset;
			  SetLeftPos(nm1,left);
		  }
		  else{
			  left=GetLeftPos(name)-GetWidth(nm1)+ajm_state.menuoffset;
			  SetLeftPos(nm1,left);
		  }
		  if(browser=="IE"){
			  top=GetPageY(name)+GetPageY(nm2+'clip')+ajm_state.mtopoffset;
			  SetPosTop(nm1,top);
		  }
		  if(browser=="NS6"){
			  if(version==6.1){
				  top=GetPageY(name)+GetPageY(nm2+'clip');
				  SetPosTop(nm1,top);
			  }
			  else{
				  top=GetPageY(nm2+'clip');
				  SetPosTop(nm1,top);
			  }
		  }
		  if(browser=="Opera"){
			  top=GetPageY(name)+GetPageY(nm2+'clip');
			  SetPosTop(nm1,top);
		  }
	  }
  }
  if(GetLayer(nm1)){
  	if(left<GetWindowLeft()){
		  SetLeftPos(nm1,GetWindowLeft());
	  }
	  if(left+GetWidth(nm1)>GetWindowWidth()){
  		SetLeftPos(nm1,GetWindowWidth()-GetWidth(nm1));
	  }
	  if(top<GetWindowTop()){
  		SetPosTop(nm1,GetWindowTop());
	  }
  	if(top+GetHeight(nm1)>GetWindowHeight()){
		  SetPosTop(nm1,GetWindowHeight()-GetHeight(nm1));
	  }
  	ShowElement(nm1,true);
  }
  ajm_state.menuActive=true;
}

function subMenuMouseOut(name,count,bgcolor,fgcolor){
  if(browser!="Opera"){
	  SetBgColor(name+'itm'+count,bgcolor,name);
	  SetFgColor(name+'a'+count,fgcolor,name);
  }
  setTimeout("ShowElements()",300);
}

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

function MenuAddWithoutLink(){
	for(var i=0;i<arguments.length;i++){
		this.MenuAddWithoutLink(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 addItemsWithTarget(){
  for(var i=0;i<arguments.length;i+=4){
  	this.addItem(arguments[i],arguments[i+1],arguments[i+2],arguments[i+3]);
  }
}


function ShowElements(){
  if(!ajm_state.menuActive){
  for(var i=0;i<ajm_state.amac;i++){
	  ShowElement(ajm_state.activemenuArray[i],false);
  }
  ajm_state.amac=0;
  }
}

function displayMenu(){
  for(var i=ajm_state.mmcp;i<ajm_state.mmac;i++){
	  ajm_state.mainmenuArray[i].writeMenu();
  }
	ajm_state.mmcp=ajm_state.mmac;
}

function createMenu(){
  for(var i=ajm_state.smcp;i<ajm_state.smac;i++){
	  ajm_state.submenuArray[i].writeMenu();
  }
  ajm_state.smcp=ajm_state.smac;
}

function loadMenu(){
  if((browser=="NS6"&&version==6.1)||browser=="IE"){
    for(var i=0;i<ajm_state.smac;i++){
  	  var menu=ajm_state.submenuArray[i];
    	var name=menu.name;
  	  var count=name.substring(name.indexOf("aj")+2,name.indexOf("sm"));
    	ShowElement(name,false);
  	  if(name.indexOf("i")==-1){
  		  var t_name=name.replace("sm","mi");
  		  var main_menu=ajm_state.mainmenuArray[parseInt(count)-1];
  		  if(main_menu.layout=='vertical'){
  			  if(ajm_state.mainmenu_dirn[parseInt(count)]=='right'){
  				  SetLeftPos(name,GetPageX(t_name+'clip')+GetWidth(t_name));
  			  }
  			  else{
  				  SetLeftPos(name,GetPageX(t_name+'clip')-GetWidth(t_name));
  			  }
  			  SetPosTop(name,GetPageY(t_name+'clip'));
  		  }
  		  if(main_menu.layout=='horizontal'){
  			  SetLeftPos(name,GetPageX(t_name+'clip'));
  			  SetPosTop(name,GetPageY(t_name+'clip')+GetHeight(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(ajm_state.mainmenu_dirn[parseInt(count)]=='right'){
  			  SetLeftPos(name,GetPageX(t_name)+GetWidth(t_name)-ajm_state.menuoffset);
  		  }
  		  else{
  			  SetLeftPos(name,GetPageX(t_name)-GetWidth(name)+ajm_state.menuoffset);
  		  }
  		  SetPosTop(name,GetPageY(t_name)+GetPageY(u_name));
  		}
    }
  }
  if(browser=="NS4"){
	  for(var i=0;i<ajm_state.mmac;i++){
		  var menu=ajm_state.mainmenuArray[i];
		  var width=0;
		  var height=0;
		  if(menu.layout=='vertical'){
			  for(var j=0;j<menu.iac;j++){
  				if(GetWidth(menu.itemArray[j]+'clip')>width){
					  width=GetWidth(menu.itemArray[j]+'clip');
				  }
			  }
			}
		  for(var j=0;j<menu.iac;j++){
			  if(menu.layout=='horizontal'){
				  width=GetWidth(menu.itemArray[j]+'clip');
			  }
			  SetWidth(menu.itemArray[j],width);
			  SetLeftPos(menu.itemArray[j],GetPageX(menu.itemArray[j]+'clip'));
			  SetPosTop(menu.itemArray[j],GetPageY(menu.itemArray[j]+'clip'));
			  ShowElement(menu.itemArray[j],true);
		  }
	  }
  	for(var i=0;i<ajm_state.smac;i++){
		  var menu=ajm_state.submenuArray[i];
		  var width=0;
		  for(var j=0;j<menu.iac;j++){
			  if(GetWidth(menu.itemArray[j]+'clip',menu.name)>width){
				  width=GetWidth(menu.itemArray[j]+'clip',menu.name);
			  }
		  }
		  SetWidth(menu.name,width+2);
		  for(var j=0;j<menu.iac;j++){
			  SetWidth(menu.itemArray[j],width,menu.name);
			  SetLeftPos(menu.itemArray[j],1,menu.name);
			  SetPosTop(menu.itemArray[j],GetPageY(menu.itemArray[j]+'clip',menu.name)-GetPageY(menu.name),menu.name);
		  }
	  }
  }
}

function GetWindowWidth(){
 	if(browser=="NS4"||browser=="NS6"||browser=="Opera"){
		return(window.innerWidth+window.pageXOffset);
	}
	if(browser=="IE"){
		return(document.body.clientWidth+document.body.scrollLeft);
	}
}

function GetWindowLeft(){
	if(browser=="NS4"||browser=="NS6"||browser=="Opera"){
		return(window.pageXOffset);
	}
	if(browser=="IE"){
		return(document.body.scrollLeft);
	}
}

function GetWindowTop(){
  if(browser=="NS4"||browser=="NS6"||browser=="Opera"){
	  return(window.pageYOffset);
  }
  if(browser=="IE"){
  	return(document.body.scrollTop);
  }
}

function GetWindowHeight(){
  if(browser=="NS4"||browser=="NS6"||browser=="Opera"){
	  return(window.innerHeight+window.pageYOffset);
  }
  if(browser=="IE"){
  	return(document.body.clientHeight+document.body.scrollTop);
  }
}

window.onresize=MenuOnResize;
origWidth=window.innerWidth;
origHeight=window.innerHeight;

function MenuOnResize(){
	if(browser=='NS4'&&origWidth==window.innerWidth&&origHeight==window.innerHeight){
		return;
	}
}

