var smenu_o={
arrTab:null,
curTab:"",
curWidth:0,
startX:0,
startMPt:{x:0,y:0},
isResize:false,
gabObj:new Object(),
pen:{
	idx:-1,
	arrIdx:new Array(),
	isOn:false,
	curTab:"",
	state:new Object(),
	set:function(tab, bCache){
		if(e_o.dBook().handle_isLinkEditMode()){
			var frameObj=document.getElementById("frm_work");
			if(frameObj){
				try{
					var frameAcc;
					if(document.frames) frameAcc=document.frames["frm_work"];
					else if(window.frames) frameAcc=window.frames["frm_work"];
					else frameAcc=eval("frm_work");
					
					frameAcc.index_o.unload();
				}catch(e){
					e_o.dBook().handle_editLink(false);
				}
				
				frameObj.style.display="none";
				frameObj.style.visible="hidden";
			}else e_o.dBook().handle_editLink(false);
		}
		
		if(e_o.dBook().handle_getTextCaptureState()) menu_setTextCapture();
		if(e_o.dBook().handle_getImgCaptureState()) menu_setImgCapture();
		
		smenu_o.pen.isOn=true;
		
		if(tab==smenu_o.pen.curTab) return;
		e_o.addEventListener("startFlip","smenu_o.pen.flipHandler");
		e_o.addEventListener("mouseUp","smenu_o.pen.upHandler");
		e_o.dBook().handle_addPen("");
		
		smenu_o.pen.state=new Object();
		smenu_o.pen.state.bCache=bCache;
		switch(tab){
		case "postit":
			smenu_o.pen.state.shape="postit";
			setTimeout("smenu_o.pen.add();",84);
			break
		case "underline":
			smenu_o.pen.state.shape="pen";
			smenu_o.pen.state.orgThick=2;
			smenu_o.pen.state.thick=2;
			smenu_o.pen.state.orgColor="#FF0000";
			smenu_o.pen.state.color="#FF0000";
			smenu_o.pen.state.orgBGcolor="#FF0000";
			smenu_o.pen.state.bgcolor="#FF0000";
			smenu_o.pen.state.alpha="0.8";
			smenu_o.pen.state.data="";
			smenu_o.pen.state.style="";
			smenu_o.pen.state.UserID="";
			setTimeout("smenu_o.pen.add();",84);
			break;
		case "marker":
			smenu_o.pen.state.shape="pen";
			smenu_o.pen.state.orgThick=10;
			smenu_o.pen.state.thick=10;
			smenu_o.pen.state.orgColor="#FFFF33";
			smenu_o.pen.state.color="#aeFF06";
			smenu_o.pen.state.orgBGcolor="#99FF33";
			smenu_o.pen.state.bgcolor="#99FF33";
			smenu_o.pen.state.alpha="0.4";
			smenu_o.pen.state.data="";
			smenu_o.pen.state.style="";
			smenu_o.pen.state.UserID="";
			setTimeout("smenu_o.pen.add();",1);
			break;
		case "eraser":
			e_o.dBook().handle_addPen("");
			smenu_o.pen.idx=-1;
			setTimeout("e_o.dBook().handle_setPenMode(true);",84);
			break;
		}
		smenu_o.pen.curTab=tab;
	},
	add:function(){
		if(smenu_o.pen.isOn){
			e_o.dBook().handle_setPenMode(false);
			var idx=e_o.dBook().handle_addPen(smenu_o.pen.state.shape, smenu_o.pen.state);
			smenu_o.pen.arrIdx.push(idx);
			smenu_o.pen.idx=idx;
			try{link_hide();}catch(ae){}
			document.getElementById("dBook").focus();
		}
	},
	end:function(){
		e_o.dBook().handle_addPen("");
		smenu_o.pen.isOn=false;
		smenu_o.pen.idx=-1;
		smenu_o.pen.curTab="";
		e_o.removeEventListener("startFlip","smenu_o.pen.flipHandler");
		e_o.removeEventListener("mouseUp","smenu_o.pen.upHandler");
		setTimeout("e_o.dBook().handle_setPenMode(false);",84);
		try{link_display();}catch(e){}
	},
	removeAll:function(){
		if(smenu_o.pen.isOn) smenu_o.pen.end();
		
		while(smenu_o.pen.arrIdx.length>0){
			var idx=smenu_o.pen.arrIdx.pop();
			e_o.dBook().handle_removeEmbed("pen",idx,true,false);
		}
	},
	flipHandler:function(){
		if(smenu_o.pen.isOn) smenu_o.pen.end();
	},
	upHandler:function(mx, my, button){
		if(smenu_o.pen.isOn){
			if(button==2) smenu_o.pen.end();
			else if(button==1 && smenu_o.pen.curTab=="postit"){
				setTimeout(" smenu_o.pen.end();",84);
			}
		}
	}
},
init:function(){	
	if(skin_sideMenu!="left" && skin_sideMenu!="right") return;
	smenu_o.curTab="";
	smenu_o.arrTab=new Array();
	
	if(typeof(skin_sideMenuBgColor)=="undefined") skin_sideMenuBgColor="#262e42";
	if(typeof(skin_sideMenuBrdColor)=="undefined") skin_sideMenuBrdColor="#666666";
	if(typeof(skin_sideMenuTextColor)=="undefined") skin_sideMenuTextColor="#cccccc";
	
	if(typeof(MSG_SMENU_PAGE)=="undefined") MSG_SMENU_PAGE="Pages";
	if(typeof(MSG_SMENU_INDEX)=="undefined") MSG_SMENU_INDEX="Index";
	if(typeof(MSG_SMENU_SEARCH)=="undefined") MSG_SMENU_SEARCH="Search";
	if(typeof(MSG_SMENU_ADDITIONAL)=="undefined") MSG_SMENU_ADDITIONAL="Additional Function";
	if(typeof(MSG_SMENU_OPTION)=="undefined") MSG_SMENU_OPTION="Options";
	
	var html='<table id="smenu_Table" border="0" cellpadding="0" cellspacing="0" height="100%" style="opacity:0.9;filter:Alpha(Opacity=90);">';
	if(skin_sideMenu=="right"){
		html+=smenu_o.getResizeBarHTML();
		html+=smenu_o.getContentsBndHTML();
		html+=smenu_o.getTabHTML();
		html+='<td width="3" style="background-color:'+skin_sideMenuBgColor+'"><img src="images/blank.gif" width="3"></td>';
	}else{
		html+='<td width="3" style="background-color:'+skin_sideMenuBgColor+'"><img src="images/blank.gif" width="3"></td>';
		html+=smenu_o.getTabHTML();
		html+=smenu_o.getContentsBndHTML();
		html+=smenu_o.getResizeBarHTML();
	}
	html+='</table>';
	if(smenu_o.arrTab.length==0) return;

	var smenu_bnd=document.body.appendChild(document.createElement("div"));
	smenu_bnd.style.visibility="hidden";
	smenu_bnd.style.display="";
	smenu_bnd.id="smenu_bnd";
	smenu_bnd.style.position="absolute";
	smenu_bnd.style.left="0px";
	smenu_bnd.style.top="0px";
	smenu_bnd.innerHTML=html;
	e_o.addEventListener("stageResize", "smenu_o.reiszeHandler");
	var smenuRect=e_o.getElementRect(smenu_bnd);
	smenu_o.gabObj.x=smenuRect.x;
	smenu_o.gabObj.y=smenuRect.y;
	var baseObj=(skin_sideMenu=="right")?e_o.getObj("td_viewerRight"):e_o.getObj("td_viewerLeft");
	baseObj.style.display="";
	var oTmp=baseObj.appendChild(document.createElement("div"));
	oTmp.style.width=smenuRect.w;
	smenu_o.rePosition();
	smenu_bnd.style.visibility="visible";
},
reiszeHandler:function(){
	smenu_o.rePosition();
	setTimeout("smenu_o.rePosition();",12);
},
rePosition:function(){
	var smenu_bnd=e_o.getObj("smenu_bnd");
	if(smenu_bnd.style.display=="none") return;
	var smenuRect=e_o.getElementRect(smenu_bnd);
	var baseObj=(skin_sideMenu=="right")?e_o.getObj("td_viewerRight"):e_o.getObj("td_viewerLeft");
	var baseRect=e_o.getElementRect(baseObj);
	if(skin_sideMenu=="right") smenu_bnd.style.left=(baseRect.x+baseRect.w-smenuRect.w) -smenu_o.gabObj.x;
	else smenu_bnd.style.left=baseRect.x-smenu_o.gabObj.x;
	
	smenu_bnd.style.top=baseRect.y-smenu_o.gabObj.y;
	smenu_bnd.style.height=baseRect.h;
},
appendTab:function(tab){
	var oElement =e_o.getObj("frame_"+tab);
	if(oElement==null){
		var oElement = document.createElement("iframe");
		oElement.id="frame_"+tab;
		oElement.name="frame_"+tab;
		oElement.frameBorder=0;
		oElement.scrolling="no";
		oElement.style.width="100%";
		oElement.style.height="100%";
		oElement.allowTransparency=true;
		e_o.getObj("smenu_contents").appendChild(oElement);
		oElement.src="appendix/"+tab+".htm?float=n";
	}
},
tabClick:function(tab){
	var smenu_bnd=e_o.getObj("smenu_bnd");
	var orgRect=e_o.getElementRect(smenu_bnd);
	
	if(smenu_o.curTab.length>0){
		var frameID="frame_"+smenu_o.curTab;
		var oFrame=e_o.getObj(frameID);
		if(oFrame!=null){
			var frameAcc;
			if(document.frames) frameAcc=document.frames[frameID];
			else if(window.frames) frameAcc=window.frames[frameID];
			else frameAcc=eval(frameID);
			try{
				frameAcc._toggle(false);
			}catch(e){}
			oFrame.style.display="none";
		}
	}
	var smenu_bnd=e_o.getObj("smenu_bnd");
	if(smenu_o.curTab==tab){
		smenu_o.curTab="";
		e_o.getObj("smenu_contentsBnd").style.display="none";
		smenu_o.setResizeEvt(false);
		smenu_o.setBorder(false);
		
		if(skin_sideMenu=="right"){
			var curW=e_o.getElementRect(smenu_bnd).w;
			smenu_bnd.style.left=orgRect.x-(curW-orgRect.w);
		}
		smenu_o.rePosition();
		return;
	}
	var tabObj=smenu_o.getTabObj(tab);
	
	var contentW=(smenu_o.curWidth>tabObj.width)?smenu_o.curWidth:tabObj.width;
	
	smenu_o.curTab=tab;
	smenu_o.appendTab(tab);
	var smenu_contentsBnd=e_o.getObj("smenu_contentsBnd");
	smenu_contentsBnd.style.display="";
	e_o.getObj("smenu_contentsDiv").style.width=contentW;
	
	smenu_o.setResizeEvt(true);
	smenu_o.setBorder(true, tab);
	var frameID="frame_"+tab;
	var oFrame=e_o.getObj(frameID);
	oFrame.style.display="";
	
	e_o.getObj("smenu_title").innerHTML=tabObj.title;
	var frameAcc;
	if(document.frames) frameAcc=document.frames[frameID];
	else if(window.frames) frameAcc=window.frames[frameID];
	else frameAcc=eval(frameID);
	try{
		frameAcc._toggle(true);
	}catch(e){}
	
	if(skin_sideMenu=="right"){
		var curW=e_o.getElementRect(smenu_bnd).w;
		smenu_bnd.style.left=orgRect.x-(curW-orgRect.w);
		setTimeout("smenu_o.rePosition();",12);
	}

},
setResizeEvt:function(bSet){
	var smenu_resize_bar=e_o.getObj("smenu_resize_bar");
	if(bSet){
		smenu_resize_bar.style.display="";
	}else{
		smenu_resize_bar.style.display="none";
	}
},
resizeStart:function(evt){
	if(smenu_o.curTab.length==0){
		smenu_o.isResize=false;
		return false;
	}
	evt=evt || window.event;
	try{
		var frameID="frame_"+smenu_o.curTab;
		var barRect=e_o.getElementRect(e_o.getObj("smenu_resize_bar"));
		var tmpBar=document.body.appendChild(document.createElement("div"));
		tmpBar.id="smenu_tmp_bar";
		tmpBar.style.position="absolute";
		tmpBar.style.width=barRect.w;
		tmpBar.style.height=barRect.h;
		tmpBar.style.left=barRect.x;
		tmpBar.style.top=barRect.y;
		tmpBar.style.border="1px solid #cccccc";
		tmpBar.style.cursor="e-resize";
		tmpBar.style.backgroundColor="#cccccc";

		var frameAcc;
		if(document.frames) frameAcc=document.frames[frameID];
		else if(window.frames) frameAcc=window.frames[frameID];
		else frameAcc=eval(frameID);	
		
		if(document.addEventListener){
			document.addEventListener("mousemove", smenu_o.resizeMove, false);
			document.addEventListener("mouseup", smenu_o.resizeEnd, false);
			
			frameAcc.document.addEventListener("mousemove", smenu_o.resizeMove, false);
			frameAcc.document.addEventListener("mouseup", smenu_o.resizeEnd, false);
		}else{
			document.attachEvent("onmousemove", smenu_o.resizeMove);
			document.attachEvent("onmouseup", smenu_o.resizeEnd);
			
			frameAcc.document.attachEvent("onmousemove", smenu_o.resizeMove);
			frameAcc.document.attachEvent("onmouseup", smenu_o.resizeEnd);
		}
		smenu_o.startX=barRect.x;
		smenu_o.startMPt.x=evt.screenX;
		smenu_o.startMPt.y=evt.screenY;
		smenu_o.isResize=true;
	}catch(e){}
	return smenu_o.stopEvt(evt);
},
resizeMove:function(evt){
	if(!smenu_o.isResize) return false;
	else if(smenu_o.curTab.length==0){
		smenu_o.isResize=false;
		return false;
	}	
	evt=evt || window.event;
	
	var smenu_contentsDiv=e_o.getObj("smenu_contentsDiv");
	var contentW=parseInt(smenu_contentsDiv.style.width);
	var maxW=parseInt((window.innerWidth)?window.innerWidth:document.body.clientWidth);
	var gapX=evt.screenX-smenu_o.startMPt.x;
	smenu_o.curWidth=(skin_sideMenu=="right")?contentW-gapX:contentW+gapX ;
	
	if(smenu_o.curWidth<136) smenu_o.curWidth=136;
	else if(smenu_o.curWidth>(maxW/2)) smenu_o.curWidth=Math.round(maxW/2);
		
	gapX=(skin_sideMenu=="right")?contentW-smenu_o.curWidth:smenu_o.curWidth-contentW;
	e_o.getObj("smenu_tmp_bar").style.left=smenu_o.startX+gapX;
	return smenu_o.stopEvt(evt);
},
resizeEnd:function(evt){
	try{document.body.removeChild(e_o.getObj("smenu_tmp_bar"));}catch(e){}
	if(smenu_o.curTab.length==0){
		smenu_o.isResize=false;
		return false;
	}
	evt=evt || window.event;
	var frameID="frame_"+smenu_o.curTab;
	var oFrame=e_o.getObj(frameID);
	var frameAcc;
	if(document.frames) frameAcc=document.frames[frameID];
	else if(window.frames) frameAcc=window.frames[frameID];
	else frameAcc=eval(frameID);	
	if(document.removeEventListener){
		document.removeEventListener("mousemove", smenu_o.resizeMove, false);
		document.removeEventListener("mouseup", smenu_o.resizeEnd, false);
		frameAcc.document.removeEventListener("mousemove", smenu_o.resizeMove, false);
		frameAcc.document.removeEventListener("mouseup", smenu_o.resizeEnd, false);
	}else{
		document.detachEvent("onmousemove", smenu_o.resizeMove);
		document.detachEvent("onmouseup", smenu_o.resizeEnd);
		frameAcc.document.detachEvent("onmousemove", smenu_o.resizeMove);
		frameAcc.document.detachEvent("onmouseup", smenu_o.resizeEnd);
	}
	var smenu_contentsDiv=e_o.getObj("smenu_contentsDiv");
	
	if(skin_sideMenu=="right"){
		var smenu_bnd=e_o.getObj("smenu_bnd");
		smenu_bnd.style.left=parseInt(smenu_bnd.style.left)-(smenu_o.curWidth-parseInt(smenu_contentsDiv.style.width));

	}
	smenu_contentsDiv.style.width=smenu_o.curWidth;
	if(skin_sideMenu=="right"){
		setTimeout("smenu_o.rePosition();",12);
	}
	try{frameAcc._resize();}catch(e){}
	smenu_o.isResize=false;
	return smenu_o.stopEvt(evt);
},
stopEvt:function(evt){
	evt=evt || window.event;
	if(evt){
		if (evt.stopPropagation) evt.stopPropagation();
		if (evt.preventDefault) evt.preventDefault();
		if (evt.preventCapture) evt.preventCapture();
		if (evt.preventBubble) evt.preventBubble();	
		evt.cancelBubble=true;
		evt.returnValue=false;
	}
	
	return false;
},
tabMouseOver:function(evt, img, tab){
	if(smenu_o.curTab==tab) return;
	img.src=e_iconDirectory+"/smenu_tab_"+tab+"_on.png";
},
tabMouseOut:function(evt, img, tab){
	if(smenu_o.curTab==tab) return;
	img.src=e_iconDirectory+"/smenu_tab_"+tab+"_off.png";
},
getResizeBarHTML:function(){
	var html='<td width="3" valign="center" id="smenu_resize_bar" style="display:none;cursor:e-resize;background-color:'+skin_sideMenuBgColor+';" onmousedown="smenu_o.resizeStart(event);" ondrag="return false;" ondragstart="return false;"><img src="images/blank.gif" width="3" height="100%"></td>';
	return html;
},
getContentsBndHTML:function(){
	var brdStyle="1px solid " + skin_sideMenuBrdColor;
	var html='<td id="smenu_contentsBnd" style="background-color:'+skin_sideMenuBgColor+';display:none;">';
	html+='<div id="smenu_contentsDiv" style="width:100%;height:100%;overflow:hidden;">';
	html+='<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">';
	html+='<tr><td height="3"></tr></td>';
	html+='<tr><td style="padding:3px;border-top:'+brdStyle+';border-bottom:'+brdStyle+';';
	if(skin_sideMenu=="right") html+='border-left:'+brdStyle+';">';
	else html+='border-right:'+brdStyle+';">';
	
	html+='<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">';
	html+='<tr height="32">';
	html+='<td align="left" valign="middle" id="smenu_title" style="font-size:9pt;padding-left:3px;color:'+skin_sideMenuTextColor+'"></td>';
	html+='<td align="right" style="padding-right:5px;"><img src="images/smenu_close.png" style="cursor:pointer;" onclick="smenu_o.tabClick(smenu_o.curTab)" onmouseover="this.src=\'images/smenu_close_on.png\';" onmouseout="this.src=\'images/smenu_close.png\';"></td>';	
	html+='</tr>';
	html+='<tr><td colspan="2" id="smenu_contents">';
	html+='</td></tr>';	
	html+='</table>';
	html+='</td></tr>';
	html+='<tr><td height="3"></tr></td>';
	html+='</table>';
	html+='</div>';
	html+='</td>';
	return html;
},
isAdditionalFunctionBtn:function(){
	if(skin_bAdditionalFunction_Button && skin_additionalFunctionView=="side"){
		if(skin_bEditLink_Button) return true;
		else if(skin_bEditPen_Button) return true;
		else if(skin_bEditMemo_Button) return true;
		else if(skin_bMyFavorite_Button && e_isIEBrowser) return true;
	}
	return false;
},
getTabHTML:function(){
	var html='<td valign="top" style="background-color:'+skin_sideMenuBgColor+';">'
	html+='<table border="0" cellpadding="0" cellspacing="0" width="30" height="100%">';
	html+='<tr><td height="3"><img src="images/blank.gif" height="3"></td></tr>';
	if(skin_bThumbnailNav_View){
		smenu_o.arrTab.push({tab:"thumbnail",width:136,title:MSG_SMENU_PAGE});
		html+=smenu_o.getTabBtnHTML("thumbnail");
	}
	if(skin_bIndex_Button && skin_indexView=="side"){
		smenu_o.arrTab.push({tab:"index",width:250,title:MSG_SMENU_INDEX});
		html+=smenu_o.getTabBtnHTML("index");
	}
	if(skin_bTextSearch && skin_indexView=="side"){
		smenu_o.arrTab.push({tab:"search",width:250,title:MSG_SMENU_SEARCH});
		html+=smenu_o.getTabBtnHTML("search");
	}
	if(smenu_o.isAdditionalFunctionBtn()){
		smenu_o.arrTab.push({tab:"additional",width:200,title:MSG_SMENU_ADDITIONAL});
		html+=smenu_o.getTabBtnHTML("additional");		
	}
	if(skin_bOption_Button){
		smenu_o.arrTab.push({tab:"option",width:200,title:MSG_SMENU_OPTION});
		html+=smenu_o.getTabBtnHTML("option");
	}
	
	html+='<tr><td id="smenu_Border_hor" style=""  height="100%"><img src="images/blank.gif"></td></tr>';
	html+='<tr><td height="3"><img src="images/blank.gif" height="3"></td></tr>';
	html+='</table>';
	html+='</td>';
	return html;
},
getTabBtnHTML:function(tab){
	var tabObj=smenu_o.getTabObj(tab);
	var title=(tabObj==null)?"":tabObj.title;
	var html='<tr><td id="smenu_tab_bnd_'+tab+'" width="30" height="36" align="center" valign="middle" style="border:1px solid transparent;cursor:pointer;" onclick="smenu_o.tabClick(\''+tab+'\')" >';
	html+='<img src="'+e_iconDirectory+'/smenu_tab_'+tab+'_off.png" id="smenu_tab_'+tab+'" title="'+title+'" onmouseover="smenu_o.tabMouseOver(event,this,\''+tab+'\');" onmouseout="smenu_o.tabMouseOut(event,this,\''+tab+'\');">';
	html+='</td></tr>';
	return html;
},
getTabObj:function(tab){
	for(var i=0;i<smenu_o.arrTab.length;i++){
		var obj=smenu_o.arrTab[i];
		if(obj.tab==tab) return obj;
	}
	return null;
},
setBorder:function(bView, tab){
	var brd_on="1px solid "+skin_sideMenuBrdColor;
	var brd_off="1px solid transparent";
	for(var i=0;i<smenu_o.arrTab.length;i++){
		var curTab=smenu_o.arrTab[i].tab;
		var obj=e_o.getObj("smenu_tab_bnd_"+curTab);
		var img=e_o.getObj("smenu_tab_"+curTab);
		if(bView){
			if(curTab==tab){
				obj.style.borderTop=brd_on;
				obj.style.borderBottom=brd_on;
				if(skin_sideMenu=="right"){
					obj.style.borderLeft=brd_off;
					obj.style.borderRight=brd_on;					
				}else{
					obj.style.borderLeft=brd_on;
					obj.style.borderRight=brd_off;	
				}
				img.src=e_iconDirectory+"/smenu_tab_"+curTab+".png";
			}else{
				obj.style.borderTop=brd_off;
				obj.style.borderBottom=brd_off;
				
				if(skin_sideMenu=="right"){
					obj.style.borderLeft=brd_on;
					obj.style.borderRight=brd_off;					
				}else{
					obj.style.borderLeft=brd_off;
					obj.style.borderRight=brd_on;
				}
				img.src=e_iconDirectory+"/smenu_tab_"+curTab+"_off.png";
			}
		}else{
			obj.style.border=brd_off;
			img.src=e_iconDirectory+"/smenu_tab_"+curTab+"_off.png";
		}
	}
	if(skin_sideMenu=="right") e_o.getObj("smenu_Border_hor").style.borderLeft=(bView)?brd_on:brd_off;
	else e_o.getObj("smenu_Border_hor").style.borderRight=(bView)?brd_on:brd_off;
}
}

