var g_bViewMedia = true;
var g_TimerID,g_TimerRunning=false;

var g_ZoomLevelPrev=0;
var g_ZoomAreaLeftPrev=0;
var g_ZoomAreaTopPrev=0;

var g_maxMediaNum=21;
var g_mediaNum=0;
var g_arrMediaType = new Array("flash","movie","music","vrmall","image","html","url");
var g_arrMedia = new Array(g_maxMediaNum);
var g_mediaType = new Array(g_maxMediaNum);
var g_mediaURL = new Array(g_maxMediaNum);   //Movie,Flash,Music, Vrmall,autocad
var g_mediaPage = new Array(g_maxMediaNum);
var g_mediaLeft = new Array(g_maxMediaNum);
var g_mediaTop = new Array(g_maxMediaNum);
var g_mediaWidth = new Array(g_maxMediaNum);
var g_mediaHeight = new Array(g_maxMediaNum);

var g_nAltFrameLeft, g_nAltFrameTop;

for(var i=0;i<g_maxMediaNum;i++){
	g_arrMedia[i]="mediaFrame"+i;
	g_mediaURL[i]="";
	g_mediaPage[i]="";
	g_mediaLeft[i]=0;
	g_mediaTop[i]=0;
	g_mediaWidth[i]=0;
	g_mediaHeight[i]=0;
}


function MediaTimeService()
{
	MediaRefleshView();
    
	if(g_TimerRunning) {
		g_TimerID = setTimeout("MediaTimeService()",300);
	}
	
	if(!g_bViewMedia)	{
		g_TimerRunning=false;
		clearTimeout(g_TimerID);
	}
}

function MediaRefleshView() 
{
	var ZoomLevel=dBook.handle_getCurrZoomStep();
	var ZoomAreaLeft=dBook.handle_getZoomAreaLeft();
	var ZoomAreaTop=dBook.handle_getZoomAreaTop();
	if(ZoomLevel != g_ZoomLevelPrev || ZoomAreaLeft != g_ZoomAreaLeftPrev || ZoomAreaTop!=g_ZoomAreaTopPrev){
/*
		if(ZoomLevel !=g_ZoomLevelPrev && g_isFullScreen != 2 && g_bDbookExtend=="y"){
			maximizeDbook(Math.pow(2,ZoomLevel), true);
			if(ZoomLevel>0){
//				document.dBook.handle_pressPause();	
				for(var i=0;i<ZoomLevel; i++){
					setTimeout("document.dBook.handle_pressZoom();",i*500);
				}
			}
		}
*/
		g_ZoomLevelPrev = ZoomLevel;
		g_ZoomAreaLeftPrev = ZoomAreaLeft;
		g_ZoomAreaTopPrev = ZoomAreaTop;
		
		for(var i=0;i<g_mediaNum;i++)
			viewMediaFrame(g_arrMedia[i]);			
	}
}
//******************************************************************************************

var g_mediaPageNum=0;
function playPageMedia(bDouble,page,autostart){
	if(g_mediaPageNum!=page){
		if(g_bViewMedia){
			for(var i=0;i<g_arrMediaType.length;i++)
				playPageMediaFunction(bDouble,page,autostart,g_arrMediaType[i]);
		}
	}
	g_mediaPageNum=page;
}

function playPageMediaFunction(bDouble,page,autostart,media){
		try{
			var strXPath, oMediaLink, strScript, nPageValue;
			if(autostart){
				if(bDouble)
					strXPath = "LinkObject[(Location/@value='"+page+"' or Location/@value='"+(page*1+1)+"') and Target/@autostart='yes']";
				else
					strXPath = "LinkObject[Location/@value='"+page+"' and Target/@autostart='yes']";
			}else{
				if(bDouble)
					strXPath = "LinkObject[(Location/@value='"+page+"' or Location/@value='"+(page*1+1)+"')]";
				else
					strXPath = "LinkObject[Location/@value='"+page+"']";				
			}
			oMediaLink = g_objLinkList.selectNodes(strXPath);
	
			var nTmp1;
			var theURL,thePage, x1,y1,x2,y2, theArea, arrTheArea,theLink="";
			
			for(var i=0;i<oMediaLink.length;i++){
				strScript = oMediaLink.item(i).selectSingleNode("Target").attributes.getNamedItem("value").value;
if(strScript.indexOf("javascript:"+media+"To") < 0)
    continue;
				
				if(media=="music"){
					eval(strScript);
				}else{
					thePage = oMediaLink.item(i).selectSingleNode("Location").attributes.getNamedItem("value").value;
					nTmp1 = strScript.indexOf("'");
					theURL = strScript.substring(nTmp1+1,strScript.indexOf("'", nTmp1+1));					
					theArea = 	oMediaLink.item(i).selectSingleNode("Source").attributes.getNamedItem("value").value;	
					arrTheArea = theArea.split(";");
					x1 = arrTheArea[0];
					y1 = arrTheArea[1];
					x2 = arrTheArea[2];
					y2 = arrTheArea[3];
					
					if(media=="html"){
						var re = /:t_divide:/g;
						theURL = theURL.replace(re,";");
						
						re =new RegExp("&lt;","g");
						theURL = theURL.replace(re,"<");
						
						re =new RegExp("&gt;","g");
						theURL = theURL.replace(re,">");
					
						re =new RegExp("&gt;","g");
						theURL = theURL.replace(re,">");
						
						re = /:rest:/g;
						theURL = theURL.replace(re,",");
						re = /:s_quotation:/g;
						theURL = theURL.replace(re,"'");
						re = /:d_quotation:/g;
						theURL = theURL.replace(re,"\"");
					}else if(media=="image"){
						arrTheArea = strScript.split(",");
						theLink = arrTheArea[6];
						nTmp1 = theLink.indexOf("'");
						theLink = theLink.substring(nTmp1+1,theLink.indexOf("'", nTmp1+1));
					}
					

					mediaTo(theURL,thePage, x1,y1,x2,y2,media,theLink);
				}
			}
		}catch(e){
			
		}	
}

function stopAllMediaFrame(){
	try{
		for(var i=0;i<g_arrMedia.length;i++){
			hideMediaFrame(g_arrMedia[i]);			
		}
	}catch(e){}
	g_mediaNum=0;
	g_mediaPageNum=0;
}

var g_objLinkParam, g_objLinkList;

function getLinkParamXml(reload){
	if(reload){
		var str3DmallPath = get3DmallPath();
		var strXmlName = getLinkParamsXmlName();
		g_objLinkParam = LoadDOM(str3DmallPath + strXmlName);
		g_objLinkList = g_objLinkParam.documentElement.selectSingleNode("LinkList[@type='link']");	
	}else{
		try{
			var strXml = g_objLinkList.xml;
		}catch(e){
			var str3DmallPath = get3DmallPath();
			var strXmlName = getLinkParamsXmlName();
			g_objLinkParam = LoadDOM(str3DmallPath + strXmlName);
			g_objLinkList = g_objLinkParam.documentElement.selectSingleNode("LinkList[@type='link']");	
		}		
	}
}

function getFrameGap(curZoomStep,pos){
	if(pos=="left"){
		if(curZoomStep==0) return 3;
		else if(curZoomStep==1) return 5;
		else if(curZoomStep==2) return 5;
		else if(curZoomStep==3) return 5;
	}else if(pos=="top"){
		if(curZoomStep==0) return 3;
		else if(curZoomStep==1) return 3;
		else if(curZoomStep==2) return 4;
		else if(curZoomStep==3) return 4;		
	}else if(pos=="width"){
		if(curZoomStep==0) return 6;
		else if(curZoomStep==1) return 4;
		else if(curZoomStep==2) return 3;
		else if(curZoomStep==3) return 3;			
	}	else if(pos=="height"){
		if(curZoomStep==0) return 6;
		else if(curZoomStep==1) return 6;
		else if(curZoomStep==2) return 5;
		else if(curZoomStep==3) return 5;			
	}
}

function getMediaArrayNum(media){
	var m=0;
	for(var i=0;i<g_arrMedia.length;i++){
		if(g_arrMedia[i]==media){
			m=i;
			break;
		}
	}
	return m;
}

function musicTo(theURL){
	var m=g_mediaNum;
	for(var i=0;i<g_mediaNum;i++){
		if(g_mediaURL[i]==theURL){
			m=i;
			break;
		}else{
			m=g_mediaNum;			
		}
	}
	if(document.frames("mediaFrame"+m).document.body.innerHTML==""){
		var oMusic="<embed type=\"application/x-mplayer2\" src=\""+ theURL + "\" autostart=\"1\"></embed>";
		document.frames("mediaFrame"+m).document.body.innerHTML = oMusic;
		g_mediaType[m]="music";
		g_mediaURL[m]=theURL;
		g_mediaNum++;
	}else{
		document.frames("mediaFrame"+m).document.body.innerHTML = "";
	}
}

function mediaTo(theURL,thePage, x1,y1,x2,y2, media,theLink){

	if(g_bViewMedia){
		if(media=="music"){
			musicTo(theURL);
		}
		var m=g_mediaNum;
		g_mediaType[m]= media;
		g_mediaLeft[m] = x1;
		g_mediaTop[m] = y1;
		g_mediaWidth[m] = x2-x1;
		g_mediaHeight[m] = y2-y1;
		g_mediaPage[m] = thePage;
		g_mediaURL[m] = theURL;
		var oHTML="";
		if(media=="flash"){
			oHTML="<OBJECT id=\"FlashPlayer\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" WIDTH=\"100%\" HEIGHT=\"100%\">";
			oHTML = oHTML + "<PARAM NAME=\"Movie\" VALUE=\""+theURL+"\">";
			oHTML = oHTML + "<param NAME=\"Play\" VALUE=\"True\">";
			oHTML = oHTML + "<param NAME=\"Loop\" VALUE=\"False\">";
			oHTML = oHTML + "<param NAME=\"Quality\" VALUE=\"High\">";
			oHTML = oHTML + "<param NAME=\"Scale\" VALUE=\"ExactFit\">";
			oHTML = oHTML + "</OBJECT>"				
		}else if(media=="movie"){
			var baseCol, strBaseURL;
			baseCol = document.all.tags('BASE');
			if(baseCol.length>0)	strBaseURL=baseCol[0].href;
			else strBaseURL="";
			
			var strLocationPath = document.location.href;
			if(theURL.indexOf("://")<0){
				if(strLocationPath.indexOf("file")==0 || strBaseURL==""){
					strLocationPath = strLocationPath.substring(0, strLocationPath.lastIndexOf("/"));
					var re = new RegExp("%20","g")
					strLocationPath = strLocationPath.replace(re," ");
					while (theURL.indexOf("../")==0){
						strLocationPath = strLocationPath.substring(0, strLocationPath.lastIndexOf("/"));
						theURL = theURL.substring("../".length, theURL.length);
					}
					
					theURL = strLocationPath +"/" + theURL
				}else if(strBaseURL!=""){
					theURL = strBaseURL+theURL
				}
			}
			
			oHTML="";
			oHTML="<table id=\"LoadingTable\" width=\"100%\" height=\"100%\" border=0 cellpadding=0 cellspacing=0 bgcolor=#000000>";
			oHTML = oHTML + "<tr><td align=center valign=middle><img id=\"LoadingImage\" src=\""+strBaseURL+"images/up_menu_01.gif\" width=205 height=64></td></tr></table>"
			oHTML = oHTML + "<embed id=\"MoviePlayer\" type=\"application/x-mplayer2\" src=\""+ theURL + "\" WIDTH=\"100%\" HEIGHT=\"100%\"  autostart=\"1\" autoSize=\"1\" EnableTracker=\"0\" ShowControls=\"0\"></embed>";
			oHTML = oHTML + "<SCRIPT FOR=\"MoviePlayer\" EVENT=\"Buffering(bStart)\" LANGUAGE=\"JScript\">";
			oHTML = oHTML + "if(!bStart){";
			oHTML = oHTML + "LoadingImage.style.width=0;";
			oHTML = oHTML + "LoadingImage.style.height=0;";	
			oHTML = oHTML + "LoadingTable.style.width=0;";
			oHTML = oHTML + "LoadingTable.style.height=0;";
			oHTML = oHTML + "LoadingTable.style.position=\"absolute\";";
			oHTML = oHTML + "}";
			oHTML = oHTML + "</SCRIPT>";
			oHTML = oHTML + "<SCRIPT FOR=\"MoviePlayer\" EVENT=\"ReadyStateChange(lReadyState)\" LANGUAGE=\"JScript\">";
			oHTML = oHTML + "if(lReadyState==4){";
			oHTML = oHTML + "LoadingImage.style.width=0;";
			oHTML = oHTML + "LoadingImage.style.height=0;";	
			oHTML = oHTML + "LoadingTable.style.width=0;";
			oHTML = oHTML + "LoadingTable.style.height=0;";
			oHTML = oHTML + "LoadingTable.style.position=\"absolute\";";
			oHTML = oHTML + "}";		
			oHTML = oHTML + "</SCRIPT>";
			oHTML = oHTML + "<SCRIPT FOR=\"MoviePlayer\" EVENT=\"Error(bStart)\" LANGUAGE=\"JScript\">";
			oHTML = oHTML + "LoadingImage.src=\""+strBaseURL+"images/up_menu_06.gif\";";
			oHTML = oHTML + "LoadingImage.style.width=205;";
			oHTML = oHTML + "LoadingImage.style.height=64;";	
			oHTML = oHTML + "LoadingTable.style.width=\"100%\";";
			oHTML = oHTML + "LoadingTable.style.height=\"100%\";";
			oHTML = oHTML + "LoadingTable.style.position=\"relative\";";
			oHTML = oHTML + "</SCRIPT>";
		}else if(media=="vrmall"){
			oHTML = "<OBJECT ID=\"VRmallViewer\" WIDTH=\"100%\" HEIGHT=\"100%\" CLASSID=\"CLSID:D7959311-BFA5-11D4-AC33-0050DA92CB80\" CODEBASE=\"http://www.humandream.com/VRmall/Release/VRmall.cab#version=2,9,0,0\">";
			oHTML = oHTML + "<PARAM NAME=\"SOURCE\" VALUE=\""+theURL+"\">";
			oHTML = oHTML + "<PARAM NAME=\"WIDTH\"  VALUE=\"100%\">";
			oHTML = oHTML + "<PARAM NAME=\"HEIGHT\" VALUE=\"100%\">";
			oHTML = oHTML + "</OBJECT>";
		}else if(media=="image"){
			oHTML="<table width=\"100%\" height=\"100%\" border=0 cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>";
			oHTML = oHTML + "<tr><td align=center valign=middle>";
			oHTML = oHTML + "<img src=\"" + theURL + "\" width=\"100%\" height=\"100%\" ";
			if( theLink!="http://" )
				oHTML = oHTML + "style=\"cursor:hand;\" onClick=\"javascript:window.open('" + theLink + "','','scrollbars=no,scrolling=no,menubar=no,resizable=yes')\">";
			else
				oHTML = oHTML + ">"
			oHTML = oHTML + "</td></tr></table>";				
		}else if(media=="html"){
			oHTML=oHTML +"<table width=\"100%\" height=\"100%\" border=0 cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>";
			oHTML = oHTML + "<tr><td align=center valign=middle style=\"font-size:12px; font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;  color: #666666;\">";
			oHTML= oHTML + theURL;
			oHTML = oHTML + "</td></tr></table>";	
		}
		document.frames("mediaFrame"+g_mediaNum).document.body.leftMargin=0;
		document.frames("mediaFrame"+g_mediaNum).document.body.topMargin=0;
		document.frames("mediaFrame"+g_mediaNum).document.body.rightMargin=0;
		document.frames("mediaFrame"+g_mediaNum).document.body.bottomMargin=0;
		document.frames("mediaFrame"+g_mediaNum).document.body.innerHTML = oHTML;
		viewMediaFrame("mediaFrame"+g_mediaNum);
		
		
		g_mediaNum++;
	}
}

function viewMediaFrame(mediaFrame){
	try{
		var m=getMediaArrayNum(mediaFrame);		
		if(g_mediaWidth[m]!=0){
			var maxZoomStep = document.dBook.handle_getTotalZoomStep();
			var curZoomStep = document.dBook.handle_getCurrZoomStep();
			var ratio1 = Math.pow(2,curZoomStep);
			var ratio2 = Math.pow(2,maxZoomStep);
			var pageWidth = 0, pageHeight=0;
			var nViewerHeight=0;
			var ZoomAreaLeft=document.dBook.handle_getZoomAreaLeft();
			var ZoomAreaTop=document.dBook.handle_getZoomAreaTop();	
			
			if( g_isDPage == 1){
				if(document.dBook.handle_getLeftSlidePage()%2==0){
					if(g_mediaPage[m]%2 == 1){
						pageWidth = document.dBook.handle_getPageWidth()*1;
						pageHeight = document.dBook.handle_getPageHeight()*1;
					}
				}else{
					if(g_mediaPage[m]%2 == 0){
						pageWidth = document.dBook.handle_getPageWidth()*1;
						pageHeight = document.dBook.handle_getPageHeight()*1;
					}					
				}
				if(g_isVertical == 1){
					pageWidth = 0;
				}else{
					pageHeight =0;
				}			
			}
			var left = parseInt( g_mediaLeft[m]*ratio1 / ratio2) + pageWidth*ratio1-ZoomAreaLeft;
			var top = parseInt( g_mediaTop[m]*ratio1 / ratio2) + pageHeight*ratio1-ZoomAreaTop;
			var width = parseInt( g_mediaWidth[m]*ratio1 / ratio2);
			var height = parseInt( g_mediaHeight[m]*ratio1 / ratio2);
			
			document.all[mediaFrame].style.pixelLeft=left - getFrameGap(curZoomStep,"left");
			document.all[mediaFrame].style.pixelTop=top - getFrameGap(curZoomStep,"top");
			document.all[mediaFrame].style.pixelWidth=width + getFrameGap(curZoomStep,"width");
			document.all[mediaFrame].style.pixelHeight=height + getFrameGap(curZoomStep,"height");		

			setTimeout("document.all['"+mediaFrame+"'].style.visibility='visible';",150);
				
			if(!g_TimerRunning){
				g_TimerRunning = true;
				MediaTimeService();
			}
		}
	}catch(e){}
}

function hideMediaFrame(mediaFrame){
	document.all[mediaFrame].style.pixelLeft=0;
	document.all[mediaFrame].style.pixelTop=0;
	document.all[mediaFrame].style.pixelWidth=0;
	document.all[mediaFrame].style.pixelHeight=0;
	document.all[mediaFrame].style.visibility="hidden";
	initMediaVar(mediaFrame);
	document.frames(mediaFrame).document.body.innerHTML="";
}

function initMediaVar(mediaFrame){
		var m=getMediaArrayNum(mediaFrame);
		g_mediaType[m]="";
		g_mediaURL[m]="";
		g_mediaPage[m]="";
		g_mediaLeft[m]=0;
		g_mediaTop[m]=0;
		g_mediaWidth[m]=0;
		g_mediaHeight[m]=0;
}

function your_linkPressed(index_param, args)
{
    
    var index;
    index = parseInt( index_param );

	try	{
 		var strMSG;
 		linkData=document.dBook.handle_getLinkParam(index);
 		linkDataPosX=document.dBook.handle_getLinkValue(index, "posX");
 		linkDataPosY=document.dBook.handle_getLinkValue(index, "posY");
 		linkDataPos2X=document.dBook.handle_getLinkValue(index, "pos2X");
 		linkDataPos2Y=document.dBook.handle_getLinkValue(index, "pos2Y");
 		linkDataTarget=document.dBook.handle_getLinkValue(index, "target");
 		linkDataURL=document.dBook.handle_getLinkValue(index,"url");
 		linkDataPageNum=document.dBook.handle_getLinkValue(index, "pageNum");
 		linkDataTestParamA=document.dBook.handle_getLinkValue(index, "ValA");
		
		var media,nTmp1, theURL,thePage, x1,x2,x3,x4,theLink="", arrTheArea;
		for(var i=0;i<g_arrMediaType.length;i++){
			media = g_arrMediaType[i];
			if(linkDataURL.indexOf("javascript:"+media+"To")>=0){
				if(media != "music"){
					nTmp1 = linkDataURL.indexOf("'");
					theURL = linkDataURL.substring(nTmp1+1,linkDataURL.indexOf("'", nTmp1+1));
					thePage = linkDataPageNum;
					x1 = linkDataPosX;
					y1 = linkDataPosY;
					x2 = linkDataPos2X;
					y2 = linkDataPos2Y;
					
					if(media=="html"){
						var re = /:t_divide:/g;
						theURL = theURL.replace(re,";");
						
						re =new RegExp("&lt;","g");
						theURL = theURL.replace(re,"<");
						
						re =new RegExp("&gt;","g");
						theURL = theURL.replace(re,">");
					
						re =new RegExp("&gt;","g");
						theURL = theURL.replace(re,">");
						
						re = /:rest:/g;
						theURL = theURL.replace(re,",");
						re = /:s_quotation:/g;
						theURL = theURL.replace(re,"'");
						re = /:d_quotation:/g;
						theURL = theURL.replace(re,"\"");
					}else if(media=="image"){
						arrTheArea = linkDataURL.split(",");
						theLink = arrTheArea[6];
						nTmp1 = theLink.indexOf("'");
						theLink = theLink.substring(nTmp1+1,theLink.indexOf("'", nTmp1+1));
					}
					mediaTo(theURL,thePage, x1,y1,x2,y2,media,theLink);
				}	
				break;
			}
		}
		
		
	} catch(e) { }
}

function your_pressBGM(){
	try{
		var bgm = document.all.albumSound;
		var nState = bgm.PlayState;
		if(nState==2){
			bgm.stop();
		}else if(nState==0){
			bgm.play();
		}
	}catch(e){}
	if(g_bViewMedia){
		stopAllMediaFrame();
		g_bViewMedia=false;
		try{
			document.all.mediaTableOn.style.display="none";
			document.all.mediaTableOff.style.display="block";
		}catch(e){}
	}else{
		g_bViewMedia=true;
		var page;
		if( g_isDPage == 1){
			page=document.dBook.handle_getLeftSlidePage();
			if((page%2)==0){
				page=page-1;
			}
			playPageMedia(true,page,false);
		}else{
			page = document.dBook.handle_getCurSlidePage();
			playPageMedia(false,page,false);
		}	
		try{
			document.all.mediaTableOff.style.display="none";
			document.all.mediaTableOn.style.display="block";
		}catch(e){}
	}
}

function your_StartZoom() {
	if(g_isFullScreen != 2 && g_bDbookExtend=="y"){
		maximizeDbook(Math.pow(2,1), true);
	}
}

function your_EndZoom(){
	if(g_isFullScreen != 2 && g_bDbookExtend=="y"){
		maximizeDbook(Math.pow(2,0), true);
	}
}

function your_treatSlidePage(){
	try{document.frames("editLink").onPageTurn();}catch(e){}
	getLinkParamXml(false);
	stopAllMediaFrame();

	var page;
	if( g_isDPage == 1){
		page=document.dBook.handle_getLeftSlidePage();
		if((page%2)==0){
			page=page-1;
		}
		playPageMedia(true,page,true);
	}else{
		page = document.dBook.handle_getCurSlidePage();
		playPageMedia(false,page,true);
	}	
}


function hideOtherFrame(frameID){
	var oFrame;
	var arrFrame = new Array("indexList","editLink","search");
	for(var i=0; i<arrFrame.length; i++){
		oFrame = document.all[arrFrame[i]];
		if(arrFrame[i] != frameID &&  oFrame.style.visibility=="visible"){
			oFrame.style.left = 0;
			oFrame.style.top = 0;
			oFrame.style.width = 10;
			oFrame.style.height = 10;		
			oFrame.style.visibility="hidden";						
		}
	}
}

function moveAndResizeFrame(frameID, pos, w, h){
	var oFrame = document.all[frameID];	
	var oBndRct = document.body.getBoundingClientRect();
	var limitHeight = oBndRct.bottom-oBndRct.top-(g_nSkinTop+g_nSkinBottom);
	var fw, fh;
	var iPosX, iPosY;
	if(limitHeight<100)	limitHeight=100;
	
	if(pos=="init")
		pos = g_CurPos;
	else
		g_CurPos = pos;	
		
	if( limitHeight <= h){
		fw = w+18;
		fh = limitHeight;
	}else{
		fw = w;
		fh = h;
	}

	if(pos=="left_top"){
		iPosX = g_nSkinLeft;
		iPosY = g_nSkinTop;
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;
	}else if(pos=="right_top"){
		iPosX = oBndRct.right - oBndRct.left - fw - g_nSkinRight;
		iPosY = g_nSkinTop;			
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;			
	}else if(pos=="left_bottom"){
		iPosX = g_nSkinLeft;
		iPosY = oBndRct.bottom - oBndRct.top - fh- g_nSkinBottom;
		if(iPosY<g_nSkinTop){
			iPosY = g_nSkinTop;
			fh = g_nSkinTop - oBndRct.bottom+oBndRct.top+g_nSkinBottom;
		}
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;		
	}else if(pos=="right_bottom"){
		iPosX = oBndRct.right - oBndRct.left - fw - g_nSkinRight;
		iPosY = oBndRct.bottom - oBndRct.top - fh - g_nSkinBottom;
		if(iPosY<g_nSkinTop){
			iPosY = g_nSkinTop;
			fh = g_nSkinTop - oBndRct.bottom+oBndRct.top+g_nSkinBottom;
		}
		oFrame.style.left = iPosX;
		oFrame.style.top = iPosY;			
	}
	
		oFrame.style.pixelWidth = fw;
		oFrame.style.pixelHeight = fh;
}

function HD_eidtLink(mode, linkID, left, top, right, bottom,page){
	try{
		document.frames("editLink").eidtLink(mode, linkID, left, top, right, bottom,page);
	}catch(e){
//			alert("error editLink");
	}
}


function your_printPhoto(){
	try{
		var url = document.location.host;
		url = url.toLowerCase();
		if(url.indexOf(g_domain) >=0){
			var page = document.dBook.handle_getLeftSlidePage();
			var photoURL = "/addservice/photo/album.asp?seq="+nAlbumSeq+"&page=" + page
			var win = window.open(photoURL,"print",'width=290,height=220, scrollbars=no,scrolling=no,menubar=no,resizable=no');
			win.focus();		
		}else{
			alert(MSG_DBOOK_001);
		}	
	}catch(e){
		alert(MSG_DBOOK_001);		
	}
}

function showFrame(frameID){
	hideOtherFrame(frameID);
	var oFrame = document.all[frameID];
	if(oFrame.style.visibility=="hidden"){
		if(frameID=="editLink"){
			var url = document.location.host;
			url = url.toLowerCase();			
			if(url.indexOf(g_domain) >=0){
				var baseCol = document.all.tags('BASE');
				if(baseCol.length > 0)
					oFrame.src = "/gallery/dBook/"+strWork+".asp?baseURL=" + baseCol[0].href ;
				else{
					url = url.substring(0, url.lastIndexOf("/") + 1);
					try{
						oFrame.src = "/gallery/dBook/"+strWork+".asp?baseURL=" + url ;
					}catch(e){}
				}
			}else{
				alert(MSG_DBOOK_002);
			}
		}else{
			if(oFrame.src==""){
				oFrame.src = frameID+".htm";
			}
		}
		oFrame.style.visibility="visible";
		try{
			document.frames(frameID).moveAndResizeFrame("init");
		}catch(e){}
	}else{
		oFrame.style.left = 0;
		oFrame.style.top = 0;
		oFrame.style.width = 10;
		oFrame.style.height = 10;		
		oFrame.style.visibility="hidden";	
		if(frameID=="editLink"){
			oFrame.src="";
			document.dBook.handle_removeLink();
			document.dBook.handle_editLink(false);
		}
	}
}

// On load defaunt1.html ***********************************************************************
function onLoadProcsss()
{
	// call by html document when the html document load finishing.
	initDBookViewer();
	if(g_strFullScreen=="init" ) 	fullScreen();
	else if(g_strFullScreen=="y" )  g_strFullScreen="init"; 
	
	bOnLoaded = true;		
	HD_getSlidePage();

//	page_num.onkeypress = doKey;

	if ( getCookie( "ebook_help_show" ) != "no" )
	{
		your_showHelp( -1 );            // help window will NOT be opened.
		//  your_showHelp( 0 );         // help window will be opened immediately.
		//  your_showHelp( 5000 );      // help window will be opened after 5 secs.
	}

	setStartPage( getStartPage() );
}

// On Unload defaunt1.html ***********************************************************************
function onUnLoadProcsss()
{
	clearTimeout(g_TimerID);
	DigitalBookUnload();
}

//
//***********************************************************************************************
// move page Functions  

// go to nPage 
function your_gotoPage( nPage ) 
{		
	HD_gotoPage( nPage );
	// TODO : Add your implementation code here.
}

// move next Page  
function your_pressNextPage() 
{		
	HD_pressNextPage();
	// TODO : Add your implementation code here.    
}

// move previous Page
function your_pressPreviousPage() 
{	
	HD_pressPreviousPage();
	// TODO : Add your implementation code here.    
}

// move first Page
function your_gotoFirstPage() 
{		
	HD_gotoFirstPage();
	// TODO : Add your implementation code here.    
}

// move last Page
function your_gotoEndPage() 
{			
	HD_gotoEndPage();
	// TODO : Add your implementation code here.    
}

//***********************************************************************************************
// zoom off or auto flip pause 
function your_pressReload() 
{		
	HD_pressPause();
	// TODO : Add your implementation code here.    
}

//***********************************************************************************************
// zoom functions 

// left page zoom in 
function your_pressLeftZoom() 
{		
	HD_pressLeftZoom();
	// TODO : Add your implementation code here.    
}

// right page zoom in 
function your_pressRightZoom() 
{			
	HD_pressRightZoom();
	// TODO : Add your implementation code here.    
}

// activate/deactivate zoom lens
function your_pressCloseUp() 
{		
	HD_pressCloseUp();
	// TODO : Add your implementation code here.    
}

//***********************************************************************************************
// page print 
function your_printPage( val )
{
    printPage( val );
    
    // If you do not want to load the printing module for the speed, update appendix/Package/DBookInstallList.xml file.
    
    // 0 = Left Page, 1 = Right Page, 2 = Double Page
    // TODO : Add your implementation code here.
}

function your_pressAutoFlip(onOrOff,delay_num){
	var isRotate = document.dBook.handle_getRotateEnable();
	if(isRotate==0) {
			var num = delay_num;
			if(num>50) num=50;
			document.dBook.handle_pressForwardRotate();
			document.dBook.handle_setDelayTime(num*1000);
	}	else {
		document.dBook.handle_pressPause();
	}
}
//***********************************************************************************************
// Event Functions
//<PARAM NAME=eventFunctions VALUE="
//changePage=your_changePage;
//endRotate=your_endRotate;
//notFlipPrev=your_notFlipPrev;
//notFlipNext=your_notFlipNext;
//linkPressed=your_linkPressed">

// event of moving page 
function your_changePage() 
{ 
    HD_setPageNum(); 
    // alert("Page Changes..");
    
    // Related to APPLET Event 'changePage'.
    // TODO : Add your implementation code here.
} 

// event of stopping auto flip 
function your_endRotate() 
{ 
    // alert( "Rotating And" ); 
    
    // Related to APPLET Event 'endRotate'.
    // TODO : Add your implementation code here.
//		document.all.autoFlipTableOff.style.display="none";
//		document.all.autoFlipTableOn.style.display="block";
} 

// event of cannot moving previous page 
function your_notFlipPrev() 
{ 
	alert( MSG_DBOOK_004 ); 
    
    // Related to APPLET Parameter 'eventFunctions'.
    // TODO : Add your implementation code here.
} 

// event of cannot moving previous page 
function your_notFlipNext() 
{ 
	alert(MSG_DBOOK_005); 
    
    // Related to APPLET Parameter 'eventFunctions'.
    // TODO : Add your implementation code here.
} 

function your_notZoom(iPage) {
	 var msg = iPage + MSG_DBOOK_006;
	 alert(msg);
}

//***********************************************************************************************
// PopUp Help Window
function your_showHelp( delayMilliSec )
{
    /***
    Notice : if delayMilliSec < 0, help window will NOT be opened.
                delayMilliSec = 0, help window will be opened immediately.
                delayMilliSec > 0, help window will be opened after the delayMilliSec.
    ***/
                
    if ( delayMilliSec < 0 )          ;
    else if ( delayMilliSec == 0 )  	showHelp();
    else setTimeout( 'showHelp();', delayMilliSec );
    
    // Related to "setTimeout(...)" of this page.
	  // TODO : Add your implementation code here.
}

//***********************************************************************************************
// minimize current window 
function your_minimizeWindow()
{
	minimizeBrowser();
}

//***********************************************************************************************
// move to url web page 
function your_openReplace( url ) 
{ 
    openReplace( url );
    // Related to the failure of APPLET loading.
    // TODO : Add your implementation code here.    
}

	function your_mouseLinkOver(linkID){
			g_currentMouseOverlinkID = linkID;
			var strXPath = "LinkObject[position()="+linkID+"]";
			try{
				var oMediaLink = g_objLinkList.selectSingleNode(strXPath);
				var strDescMode = oMediaLink.selectSingleNode("Description").attributes.getNamedItem("type").value;
				if(strDescMode!="html"){
					return;
				}
				var nPage = oMediaLink.selectSingleNode("Location").attributes.getNamedItem("value").value;
				var strArea = oMediaLink.selectSingleNode("Source").attributes.getNamedItem("value").value;
				var strDescription = oMediaLink.selectSingleNode("Description").attributes.getNamedItem("value").value;
				var strDescFront = "&lt;html&gt;&lt;body leftMargin=0 topMargin=0 rightMargin=0 bottomMargin=0&gt;&lt;table id=fMainTable border=0 cellpadding=0 cellspacing=0 width=0 height=0&gt;&lt;tr&gt;&lt;td width=0 height=0&gt;"
				var strDescRear = "&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;&lt;script lanugage=javascript DEFER=true&gt;var oTimerID=0;function setFrameSize(){clearTimeout(oTimerID);var oRect=document.all['fMainTable'].getBoundingClientRect();var fWidth=oRect.right-oRect.left;var fHeight=oRect.bottom-oRect.top;parent.setAltFrameSize(fWidth,fHeight);oTimerID=setTimeout('setFrameSize()','1000');}setFrameSize();function hideFrame(){clearTimeout(oTimerID);}&lt;/script&gt;"
				var re = /&lt;/g;
				strDescFront = strDescFront.replace(re,"<")
				strDescRear = strDescRear.replace(re,"<")
				re = /&gt;/g;
				strDescFront = strDescFront.replace(re,">")
				strDescRear = strDescRear.replace(re,">")
				
				strDescription =  strDescFront + strDescription + strDescRear;
//				alert(strDescription)
				var arrTheArea = strArea.split(";");
				var x1 = arrTheArea[0];
				var y1 = arrTheArea[1];
				var x2 = arrTheArea[2];
				var y2 = arrTheArea[3];

				var maxZoomStep = document.dBook.handle_getTotalZoomStep();
				var curZoomStep = document.dBook.handle_getCurrZoomStep();
				var ratio1 = Math.pow(2,curZoomStep);
				var ratio2 = Math.pow(2,maxZoomStep);
				var pageWidth = 0, pageHeight=0;
				var nViewerHeight=0;
				var ZoomAreaLeft=document.dBook.handle_getZoomAreaLeft();
				var ZoomAreaTop=document.dBook.handle_getZoomAreaTop();	
				
				
				if( g_isDPage == 1){
					if(document.dBook.handle_getLeftSlidePage()%2==0){
						if(nPage%2 == 1){
							pageWidth = document.dBook.handle_getPageWidth()*1;
							pageHeight = document.dBook.handle_getPageHeight()*1;
						}
					}else{
						if(nPage%2 == 0){
							pageWidth = document.dBook.handle_getPageWidth()*1;
							pageHeight = document.dBook.handle_getPageHeight()*1;
						}					
					}
					if(g_isVertical == 1){
						pageWidth = 0;
					}else{
						pageHeight =0;
					}			
				}			
				var left = parseInt( (0.5*x2+0.5*x1)*ratio1 / ratio2) + pageWidth*ratio1-ZoomAreaLeft;
				var top = parseInt( (0.5*y2+0.5*y1)*ratio1 / ratio2) + pageHeight*ratio1-ZoomAreaTop;
				
				var oRect = document.all["dBook"].getBoundingClientRect();
				var nDbookLeft = oRect.left;
				var nDbookTop = oRect.top;
				document.frames("altFrame").document.body.leftMargin=0;
				document.frames("altFrame").document.body.topMargin=0;
				document.frames("altFrame").document.body.rightMargin=0;
				document.frames("altFrame").document.body.bottomMargin=0;
				g_nAltFrameLeft =  left+nDbookLeft+document.body.scrollLeft; 
				g_nAltFrameTop = top+nDbookTop+document.body.scrollTop;
				document.all["altFrame"].style.pixelLeft = g_nAltFrameLeft;
				document.all["altFrame"].style.pixelTop = g_nAltFrameTop;
				document.frames("altFrame").document.body.innerHTML = strDescription;
				setTimeout("document.all['altFrame'].style.visibility='visible';",100);
			}catch(e){}
	}
	
	function your_mouseLinkOut(linkID){
		try{
			g_currentMouseOverlinkID = 0;
			document.all["altFrame"].style.pixelLeft = 0;
			document.all["altFrame"].style.pixelTop = 0;
			document.all["altFrame"].style.pixelWidth = 0;
			document.all["altFrame"].style.pixelHeight = 0;
			
			document.frames("altFrame").hideFrame();
			document.frames("altFrame").document.body.innerHTML = "";
		}catch(e){}			
	}
	
	function setAltFrameSize(w,h){
		var nScrollLeft = document.body.scrollLeft;
		var nScrollTop = document.body.scrollTop;
		var rect = document.body.getBoundingClientRect();		
		var nWinWidth = rect.right - rect.left;
		var nWinHeight = rect.bottom - rect.top;

		if( ((g_nAltFrameLeft+w) > (nWinWidth+nScrollLeft)) && (g_nAltFrameLeft > (nScrollLeft+nWinWidth/2))){
			document.all["altFrame"].style.pixelLeft = g_nAltFrameLeft-w;
		}
		
		if( ((g_nAltFrameTop+h) > (nWinHeight+nScrollTop)) && (g_nAltFrameTop > (nScrollTop+nWinHeight/2))){
			document.all["altFrame"].style.pixelTop = g_nAltFrameTop-h;
		}		
		document.all["altFrame"].style.pixelWidth = w;
		document.all["altFrame"].style.pixelHeight = h;
	}

/*
getWindowSizeInfo()
window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);

And Calculate
g_nWidthGap, g_nHeightGap
*/
	function getWindowSizeInfo(){
		if (g_isFullScreen==0){
			try{
				window.moveTo(0,0);
				window.resizeTo(screen.availWidth,screen.availHeight);
				
				
				g_nWidthGap = (screen.availWidth-document.body.clientWidth) + g_nWidthGap;
				g_nHeightGap = (screen.availHeight-document.body.clientHeight) + g_nHeightGap;

			}catch(e){}			
		}
	}
	
	function initBoard(){
		if(g_haveBoard=="y"){
			document.dboardForm.bArticleViewMode.value = "FALSE";
			document.dboardForm.strBoardListMode.value = g_strBoardType;
			if(g_strBoardType=="AllPages"){
				frames.dboard.document.location.href = "http://"+ g_mainHost + "/boardx/list.asp?brd_id=" + g_nDbookSeq + "&brd_type=" + g_strBoardType + "&db_page=1&dbt_page=" + document.dBook.handle_getSlideTotal();
			}else if (g_strBoardType=="PageDependent"){
					frames.dboard.document.location.href = "http://" + g_mainHost + "/boardx/list.asp?brd_id=" + g_nDbookSeq + "&brd_type="+g_strBoardType+"&db_page=1";
			}
			
			document.all["dboard"].style.height="300px";
		}
	}
	
	function initDBookViewer(){
		try{
			var hostName = document.location.host;
			hostName = hostName.toLowerCase();
			
			if(hostName.indexOf(g_domain)>=0){
				g_mainHost = hostName;
			}else if(hostName.indexOf("albummania")){
				g_domain = hostName.substring(hostName.indexOf("albummania"));
				g_mainHost = "www." + g_domain;
			}else{
				g_mainHost = "www." + g_domain;
			}

			document.all["viewerDiv"].style.width=document.all["dBook"].width;
			document.all["viewerDiv"].style.height=document.all["dBook"].height;
			g_isDPage = parseInt(document.dBook.handle_isDoublePage());	
			var page;
			if( g_isDPage == 1){
				var pageHeight = document.dBook.handle_getPageHeight()*1;
				var nViewerHeight = document.dBook.handle_getBookAreaBottom() -  document.dBook.handle_getBookAreaTop();
				if(nViewerHeight == 2*pageHeight){
					g_isVertical=1;
				}else{
					g_isVertical=0;
				}
				page=document.dBook.handle_getLeftSlidePage();
				if((page%2)==0){
					page=page-1;
				}
				playPageMedia(true,page,true);
			}	else{
				page = document.dBook.handle_getCurSlidePage();
				playPageMedia(false,page,true);		
			}
			g_isFullScreen = getIsFullScreen();
			initBoard();
		}catch(e){
			setTimeout("initDBookViewer()",300);
		}
	}
	
	var g_viewTableWidth, g_viewTableHeight, g_viewTableLeft, g_viewTableTop;
	function fullScreen(){
		var vTable = document.all["viewTable"];
		var mTable = document.all["menuTable"];
		var returnFrame = document.all("returnToOrgin");

		if(g_strFullScreen=="init"){
			mTable.style.position="absolute";
			mTable.style.visibility = "hidden";
			try{
				getViewTableSizeOrLocation();
				window.moveBy(-1*window.screenLeft-g_viewTableLeft,-1*window.screenTop-g_viewTableTop);
				getViewTableSizeOrLocation();
				if( (window.screenTop+g_viewTableTop)<5 ){
					window.resizeBy(screen.width-g_viewTableWidth,screen.height-g_viewTableHeight );
				}else{
					window.resizeTo(screen.availWidth,screen.availHeight);
				}
			}catch(we){
				window.moveTo(0,0);
				window.resizeTo(screen.availWidth,screen.availHeight);					
			}
			
			
	
			returnFrame.style.pixelLeft = g_viewTableWidth-90;
			returnFrame.style.pixelTop = 0;
			returnFrame.style.pixelWidth = 86;
			returnFrame.style.pixelHeight = 32;
			g_strFullScreen="y";
			
			maximizeDbook( Math.pow(2, document.dBook.handle_getCurrZoomStep()), true );
		}else{
			if(document.dBook.handle_getCurrZoomStep() > 0){
				document.all["viewerDiv"].style.pixelWidth = 150;
				document.all["viewerDiv"].style.pixelHeight = 150;
			}
			getWindowSizeInfo();
			mTable.style.position="static";
			mTable.style.visibility = "inherit";
			g_strFullScreen="init";
			returnFrame.style.pixelLeft = 0;
			returnFrame.style.pixelTop = 0;
			returnFrame.style.pixelWidth = 0;
			returnFrame.style.pixelHeight = 0;
			
			maximizeDbook( Math.pow(2, document.dBook.handle_getCurrZoomStep()), true );
			
		}

		

	}
	
	function maximizeDbook(nRatio, bResizeDBook){
		getViewTableSizeOrLocation();
		var nAvailWidth =g_viewTableWidth;
		var nAvailHeight = g_viewTableHeight;
		var nViewerWidth, nViewerHeight;
		var nPageWidth = document.dBook.handle_getPageWidth();
		var nPageHeight = document.dBook.handle_getPageHeight();
	
		if( g_isDPage == 1){		
			if(g_isVertical == 1){
				nViewerWidth = nPageWidth;
				nViewerHeight = 2*nPageHeight;
			}else{
				nViewerWidth = 2*nPageWidth;
				nViewerHeight = nPageHeight;
			}
		}else{
				nViewerWidth = nPageWidth;
				nViewerHeight = nPageHeight;			
		}

		var nDBookWidth= nViewerWidth * nRatio;
		var nDBookHeight= nViewerHeight * nRatio;
		
		if(nRatio>1 && (nDBookWidth>nAvailWidth || nDBookHeight>nAvailHeight) ){
			if(nDBookWidth>nAvailWidth) nDBookWidth = nAvailWidth;
			if(nDBookHeight>nAvailHeight) nDBookHeight = nAvailHeight;
			
			document.all["viewerDiv"].style.pixelTop=g_viewTableTop + (nAvailHeight-nDBookHeight)/2 + document.body.scrollTop -2;
			document.all["viewerDiv"].style.pixelLeft=g_viewTableLeft + (nAvailWidth-nDBookWidth)/2 + document.body.scrollLeft -2;
			document.all["viewerDiv"].style.pixelWidth = nDBookWidth;
			document.all["viewerDiv"].style.pixelHeight = nDBookHeight;
			document.all["dBook"].width = nDBookWidth;
			document.all["dBook"].height = nDBookHeight;
			document.all["viewerDiv"].style.position="absolute";
			
			if(bResizeDBook) document.dBook.handle_changeViewSize(nDBookWidth,nDBookHeight);
		}else{
			document.all["viewerDiv"].style.position="static";
			document.all["viewerDiv"].style.pixelTop=0;
			document.all["viewerDiv"].style.pixelLeft=0;
			document.all["viewerDiv"].style.pixelWidth = nDBookWidth;
			document.all["viewerDiv"].style.pixelHeight = nDBookHeight;
			document.all["dBook"].width = nDBookWidth;
			document.all["dBook"].height = nDBookHeight;
		
			if(bResizeDBook) document.dBook.handle_changeViewSize(nDBookWidth,nDBookHeight);					
		}
	}
	
	function getViewTableSizeOrLocation(){
		var oBndRct = document.all["viewTable"].getBoundingClientRect();
		g_viewTableLeft = oBndRct.left;
		g_viewTableTop = oBndRct.top;
		g_viewTableWidth = oBndRct.right - oBndRct.left;
		g_viewTableHeight = oBndRct.bottom - oBndRct.top;
	}
