/**************************************************************
*   Copyright: TWIinteractive                                 *
*	Author: Laurent Muchacho                                  *
***************************************************************/
var mPixFld = '/pix/menu/'+c_c+'/';
var mItmH=19;

var numId=0;function unik(){var id=numId++;return id;}
function m_show(mId){createObjStyle(mId).visibility='visible';}
function m_hide(mId){createObjStyle(mId).visibility='hidden';}
function mItm(name,path,target,left,top){this.name=name;this.path=path;this.target=target;this.left=left;this.top=top;this.unikid='div_'+ unik();this.over=m_over;this.out=m_out;this.mSub=new Array();}
function mSub(name,path,target){this.name=name;this.path=path;this.target=target;this.unikid='div_'+menu.length+'_'+ unik();this.over=m_over;this.out=m_out;this.bgover=m_bg_over;this.bgout=m_bg_out;this.mSub=new Array();}
function img(name,iWidth,iHeight,sAlt){var str="";str='<img src="'+mPixFld+name+'.gif" width="'+iWidth+'" height="'+iHeight+'" border="0" alt="'+sAlt+'">';return str;}
function m_over(){m_show('s'+this.unikid);menuActive=true;}
function m_out(){m_hide('s'+this.unikid);menuActive=false;}
function m_bg_over(bg,txt,obj){if (bw.ns){m_show(this.unikid);}if(bw.ns6){createObjStyle('txt_'+this.unikid).color=txt;obj.bgColor=bg;}if (bw.ie){createObjStyle(this.unikid).backgroundColor=bg;createObjStyle('txt_'+this.unikid).color=txt;}}
function m_bg_out(bg,txt,obj){if (bw.ns){m_hide(this.unikid);}if (bw.ns6||bw.ie){createObjStyle('txt_'+this.unikid).color=txt;obj.bgColor=bg;}if (bw.ie){createObjStyle(this.unikid).backgroundColor=bg;createObjStyle('txt_'+this.unikid).color=txt;}}


function openSubLayer(name,left,top,wi,visi,sAction){var str=(bw.ns)?'<layer id='+name+' left='+left+' top='+top+' width='+wi+' visibility='+visi+' z-index=2000 '+sAction+'>':'<div id="'+name+'" '+sAction+' style="position:absolute;left:'+left+'px;top:'+top+'px;width:'+wi+'px;visibility:'+visi+';z-index:2000;">\n';return str;}
function openSLayer(name,left,top,width,height,visi,sAction,color){var str='<layer id='+name+' left='+left+' top='+top+' width='+width+' height='+height+' bgcolor="'+color+'" visibility='+visi+' z-index=2000 '+sAction+'>';return str;}
function closeLayer(){var str=(bw.ns)?'</layer>':'</div>\n';return str;}

var spacer='<img src="/1.gif" width="1" height="1">';
function fSpacer(wi,he){var str='<img src="/1.gif" width="'+wi+'" height="'+he+'">';return str;}
function arrow(state,name){var str='<img name="'+name+'" src="'+mPixFld+'arrow'+state+'.gif" width="7" height="11" hspace="5" vspace="2">';return str}
function openFont(txtColor){var str=(bw.ns)?'<font face="arial" size="1" color="'+txtColor+'"><nobr>':'<span style="color:'+txtColor+';font-family:arial;font-size:11px;"><nobr>';return str;}
function closeFont(){var str=(bw.ns)?'<nobr></font>':'<nobr></span>';return str;} 

function mItmTable(width,height,sTxt,sPath,mSubImg,color,txtC,action,divId){
var color_on=(color.indexOf('Sub')>-1)?mSubBg_on:mBg_on;var str="";
if(bw.ns){str='<table cellpadding="0" cellspacing="0" border="0" width="'+width+'" bgcolor="'+color+'"><tr>'; if (sTxt.indexOf("<img")==-1){str +='<td>'+fSpacer(10,height-1)+'</td>'} str +='<td width="100%"><a href="'+sPath+'" class="textDecoNo" '+action+'>'+openFont(txtC)+ sTxt +closeFont()+'</a></td><td>'+mSubImg+'</td></tr><tr><td colspan="3" bgcolor="'+lineC+'">'+spacer+'</td></tr></table>\n';}
if(bw.ns6){str='<table id="'+divId+'" cellpadding="0" cellspacing="0" border="0" width="'+width+'" height="19" style="cursor:hand" bgcolor="'+color+'" '+action+'><tr><td width="100%"><p class="indent10"><a href="'+sPath+'" id="txt_'+divId+'" style="color:'+txtC+';font-size:11px;font-family:arial;text-decoration:none;">'+ sTxt +'</a></p></td><td>'+mSubImg+'</td></tr><tr><td colspan="2" bgcolor="'+lineC+'">'+spacer+'</td></tr></table>';}
if(bw.ie){str='<table id="'+divId+'" cellpadding="0" cellspacing="0" border="0" width="'+width+'" bgcolor="'+color+'" style="background-color:'+color+';cursor:hand;" '+action+'><tr>'; if (sTxt.indexOf("<img")==-1){str +='<td>'+fSpacer(10,height-1)+'</td>'} str +='<td width="100%"><a href="'+sPath+'" style="color:'+txtC+';font-size:11px;font-family:arial;text-decoration:none;width:100%;" id="txt_'+divId+'">'+ sTxt +'</a></td><td>'+mSubImg+'</td></tr><tr><td colspan="3" bgcolor="'+lineC+'">'+spacer+'</td></tr></table>\n';}return str;}

function get_mItmW(oIndex,oArray){
var txtMaxL=0;var oW=0;
for (var i=0;i<oArray;i++){
	if(oIndex.mSub[i].name.indexOf("<img")==-1){
		if (oIndex.mSub[i].name.length>txtMaxL){
			txtMaxL=oIndex.mSub[i].name.length;
		}
	}
	else{
		if(oIndex.mSub[i].name.indexOf("supported")>-1){
			return 157;
		}
		if(oIndex.mSub[i].name.indexOf("sponsored")>-1){
			return 166;
		}
		
	}
}
return 16+(txtMaxL*6);
}

function displayMenu(){var str="";var action;
	for (var i=0;i<menu.length;i++){
	action=(menu[i].mSub.length>0)?'onmouseover="menu['+i+'].over()" onmouseout="menu['+i+'].out();"':'';
		d.write (openSubLayer(menu[i].unikid,menu[i].left,menu[i].top,'visible',''));
		d.write ('<a href="'+menu[i].path+'" '+action+'>'+menu[i].name+'</a>');
		d.write (closeLayer());
	}
	
	for (var i=0;i<menu.length;i++){
		if(menu[i].mSub.length>0){
		
			var mItmW=(get_mItmW(menu[i],menu[i].mSub.length)<120)? 110 : get_mItmW(menu[i],menu[i].mSub.length);
			if(i>1){mItmW=mItmW-20}
			if(i==menu.length-1){mItmW=70}
			
			var itmW=mItmW+11;
			var mItemH=(i>6)?12:15;
			action='onmouseover="menu['+i+'].over()" onmouseout="menu['+i+'].out()"';
		//write 2nd level
			d.write (openSubLayer('s'+menu[i].unikid,menu[i].left,menu[i].top,itmW+11+2,'hidden',action));
			d.write ( fSpacer(1,mItemH)+'<br>\n<table cellpadding="0" cellspacing="0" border="0" width="'+(itmW+11)+'"><tr><td bgcolor="'+indC+'">'+spacer+'</td><td width="'+itmW+'">\n');
			var haveSub;var subOverAction;var subOutAction;

			for (var j=0;j<menu[i].mSub.length;j++){
				haveSub=(menu[i].mSub[j].mSub.length>0)?true:false;
				var mSubImg=(haveSub)? arrow('','img_'+menu[i].mSub[j].unikid):spacer;
				var mSubImg_on=(haveSub)?arrow('_on','img_'+menu[i].mSub[j].unikid):spacer;
				
				subOverAction=(haveSub)? 'menu['+i+'].mSub['+j+'].bgover(mBg_on,mTxt_on,this); menu['+i+'].mSub['+j+'].over();if(!bw.ns){flipImg(\'img_'+menu[i].mSub[j].unikid+'\')};':'menu['+i+'].mSub['+j+'].bgover(mBg_on,mTxt_on,this);';
				subOutAction=(haveSub)?'menu['+i+'].mSub['+j+'].bgout(mBg,mTxt,this);menu['+i+'].mSub['+j+'].out();if(!bw.ns){flipImg(\'img_'+menu[i].mSub[j].unikid+'\');}':'menu['+i+'].mSub['+j+'].bgout(mBg,mTxt,this);';
				if (bw.ns){
					d.write (fSpacer(1,19)+'<br>')
					d.write (openSLayer('fl'+menu[i].mSub[j].unikid,11,((mItemH+(mItmH*j))),mItmW+11,mItmH,'inherit','onmouseover="'+subOverAction+'" onmouseout="'+subOutAction+'"',mBg));
					subOverAction="";subOutAction="";
				}
				d.write (mItmTable(itmW,mItmH,menu[i].mSub[j].name,menu[i].mSub[j].path,mSubImg,mBg,mTxt,'onmouseover="'+subOverAction+'" onmouseout="'+subOutAction+'"',menu[i].mSub[j].unikid));
				if(bw.ns){
					d.write (closeLayer());
				}
			}

			d.write ('</td><tr><td><img src="'+mPixFld+'corner.gif" width="11" height="10"></td><td bgcolor="'+mBg+'">'+fSpacer(itmW,1)+'</td></tr></table>\n'+closeLayer());

			if (bw.ns){
				for (var j=0;j<menu[i].mSub.length;j++){
					haveSub=(menu[i].mSub[j].mSub.length>0)?true:false;
					mSubImg=(haveSub)? arrow(''):spacer;var mSubImg_on=(haveSub)?arrow('_on'):spacer;
					subOverAction=(haveSub)?'menu['+i+'].mSub['+j+'].bgover(mBg_on,mTxt_on);menu['+i+'].over();menu['+i+'].mSub['+j+'].over();':'menu['+i+'].mSub['+j+'].bgover(mBg_on,mTxt_on);menu['+i+'].over();';
					subOutAction=(haveSub)?'menu['+i+'].mSub['+j+'].bgout(mBg,mTxt);menu['+i+'].mSub['+j+'].out();':'menu['+i+'].mSub['+j+'].bgout(mBg,mTxt);';

					d.write (openSLayer(menu[i].mSub[j].unikid,menu[i].left+11,menu[i].top+(mItemH+(mItmH*j)),mItmW+11,mItmH,'hidden','onmouseover="'+subOverAction+'" onmouseout="'+subOutAction+'"',mBg_on));
					d.write (mItmTable(itmW,mItmH,menu[i].mSub[j].name,menu[i].mSub[j].path,mSubImg_on,mBg_on,mTxt_on,''));
					d.write (closeLayer());
				}
			}
			
		// write 3rd level
		var parentWidth=mItmW 			
			for (var j=0;j<menu[i].mSub.length;j++){
			var objId=menu[i].mSub[j].unikid
				var mSubItmW=(get_mItmW(menu[i].mSub[j],menu[i].mSub[j].mSub.length)<120)?110:get_mItmW(menu[i].mSub[j],menu[i].mSub[j].mSub.length);
				if(menu[i].mSub[j].mSub.length==0){continue;}

	
				if(i>0){mSubItmW=mSubItmW-15;}
				subOverAction=(bw.ns)?'m_show(\'s'+objId+'\');m_show(\''+objId+'\');m_show(\'s'+menu[i].unikid+'\')':'menu['+i+'].mSub['+j+'].bgover(mBg_on,mTxt_on,document.getElementById(\''+objId+'\'));flipImg(\'img_'+objId+'\');menu['+i+'].mSub['+j+'].over();menu['+i+'].over()';
				subOutAction=(bw.ns)?'m_hide(\'s'+objId+'\');m_hide(\''+objId+'\');m_hide(\'s'+menu[i].unikid+'\')':'menu['+i+'].mSub['+j+'].bgout(mBg,mTxt,document.getElementById(\''+objId+'\'));flipImg(\'img_'+objId+'\');menu['+i+'].mSub['+j+'].out();menu['+i+'].out()';
				action=' onmouseover="'+subOverAction+'" onmouseout="'+subOutAction+'"'
				d.write (openSubLayer('s'+objId,(menu[i].left+itmW+11),(menu[i].top+mItemH-1)+((mItmH)*(j)),itmW,'hidden',action));
				d.write ('<table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'+indC+'">'+spacer+'</td><td>');

				for (var k=0;k<menu[i].mSub[j].mSub.length;k++){
					if(bw.ns){
					var sub_mItmH=(k==0)?0:mItmH*k;
					//	d.write (fSpacer(1,19)+'<br>');
					//	alert(openSLayer(menu[i].mSub[j].mSub[k].unikid,11,sub_mItmH,mSubItmW,mItmH,'inherit','onmouseover="m_show(\''+menu[i].mSub[j].mSub[k].unikid+'\');m_show(\'s'+menu[i].unikid+'\');m_show(\'s'+objId+'\');m_show(\''+objId+'\')" onmouseout="m_hide(\''+menu[i].mSub[j].mSub[k].unikid+'\')"',mSubBg))
					//	d.write (openSLayer(menu[i].mSub[j].mSub[k].unikid,11,sub_mItmH,mSubItmW,mItmH,'inherit','onmouseover="m_show(\''+menu[i].mSub[j].mSub[k].unikid+'\');m_show(\'s'+menu[i].unikid+'\');m_show(\'s'+objId+'\');m_show(\''+objId+'\')" onmouseout="m_hide(\''+menu[i].mSub[j].mSub[k].unikid+'\')"',mSubBg));
					}
					d.write (mItmTable(mSubItmW,mItmH,menu[i].mSub[j].mSub[k].name,menu[i].mSub[j].mSub[k].path,spacer,mSubBg,mSubTxt,'onmouseover="menu['+i+'].mSub['+j+'].mSub['+k+'].bgover(mSubBg_on,mSubTxt_on,this);menu['+i+'].mSub['+j+'].bgover(mSubBg_on,mSubTxt_on,this);" onmouseout="menu['+i+'].mSub['+j+'].mSub['+k+'].bgout(mSubBg,mSubTxt,this);"',menu[i].mSub[j].mSub[k].unikid));
					if(bw.ns){
					//d.write (closeLayer());
					}
				}

				d.write ('</td></tr><tr><td><img src="'+mPixFld+'corner.gif" width="11" height="10"></td><td bgcolor="'+mSubBg+'">'+fSpacer(mSubItmW,1)+'</td></tr></table>\n'+closeLayer());

				if(bw.ns){
					for (var k=0;k<menu[i].mSub[j].mSub.length;k++){
					var submItmH=(k==0)?menu[i].top+mItemH+0+(mItmH*j):menu[i].top+mItemH+(mItmH*j)+(mItmH*k);
							d.write (openSLayer(menu[i].mSub[j].mSub[k].unikid,(menu[i].left+33+parentWidth),submItmH-1,mSubItmW,mItmH,'hidden','onmouseover="m_show(\'s'+menu[i].unikid+'\');m_show(\'s'+objId+'\');m_show(\''+objId+'\');m_show(\''+menu[i].mSub[j].mSub[k].unikid+'\')" onmouseout="m_hide(\''+menu[i].mSub[j].mSub[k].unikid+'\')"',mSubBg_on));
							d.write (mItmTable(mSubItmW,mItmH,menu[i].mSub[j].mSub[k].name,menu[i].mSub[j].mSub[k].path,spacer,mSubBg_on,mSubTxt_on,''));
							d.write (closeLayer());
					}
				}
			}
		}
	}
}
