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;

var g_bAutoRotating;

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){
		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' and contains(Target/@value , 'javascript:"+media+"To')]";
				else
					strXPath = "LinkObject[Location/@value='"+page+"' and Target/@autostart='yes' and contains(Target/@value , 'javascript:"+media+"To')]";
			}else{
				if(bDouble)
					strXPath = "LinkObject[(Location/@value='"+page+"' or Location/@value='"+(page*1+1)+"') and contains(Target/@value , 'javascript:"+media+"To')]";
				else
					strXPath = "LinkObject[Location/@value='"+page+"' and contains(Target/@value , 'javascript:"+media+"To')]";				
			}

			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(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 = oHTML + "<table border=0 cellspacing=0 cellpadding=0 width=100% height=100%>";
			oHTML = oHTML + "	<tr>";
			oHTML = oHTML + "		<td width=33 height=11><img src="+strBaseURL+"images/tv_visul_job_01.gif width=33 height=11></td>";
			oHTML = oHTML + "		<td height=11 background="+strBaseURL+"images/tv_visul_job_02.gif></td>";
			oHTML = oHTML + "		<td><img src="+strBaseURL+"images/tv_visul_job_04.gif width=34 height=11></td>";
			oHTML = oHTML + "	</tr>";
			oHTML = oHTML + "	<tr>";
			oHTML = oHTML + "		<td width=33 background="+strBaseURL+"images/tv_visul_job_05.gif>&nbsp;</td>";
			oHTML = oHTML + "		<td width=100% height=100% align=center valign=middle>";
			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/tv_visul_job_03.gif width=100% height=100%></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 +	"		</td>";
			oHTML = oHTML + "		<td width=33 background="+strBaseURL+"images/tv_visul_job_09.gif>&nbsp;</td>";
			oHTML = oHTML + "	</tr>";
			oHTML = oHTML + "	<tr>";
			oHTML = oHTML + "		<td width=33 height=49><img src="+strBaseURL+"images/tv_visul_job_10.gif width=33 height=49></td>";
			oHTML = oHTML + "		<td valign=bottom background="+strBaseURL+"images/tv_visul_job_11.gif><table border=0 align=right cellpadding=5 cellspacing=0>";
			oHTML = oHTML + "			<tr align=right valign=middle>";
			oHTML = oHTML + "			<td height=33><img src="+strBaseURL+"images/tv_visul_job_14.gif name=Image7 width=25 height=27 border=0 onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('Image7','','"+strBaseURL+"images/tv_visul_job_on_14.gif',1) style=cursor:hand onclick=MoviePlayer.Play()></td>";
			oHTML = oHTML + "			<td><img src="+strBaseURL+"images/tv_visul_job_16.gif name=Image8 width=25 height=27 border=0 onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('Image8','','"+strBaseURL+"images/tv_visul_job_on_16.gif',1) style=cursor:hand onclick=MoviePlayer.Pause()></td>";
			oHTML = oHTML + "			<td><img src="+strBaseURL+"images/tv_visul_job_18.gif name=Image9 width=26 height=27 border=0 onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('Image9','','"+strBaseURL+"images/tv_visul_job_on_18.gif',1) style=cursor:hand onclick=MoviePlayer.Stop()></td>";
			oHTML = oHTML + "			</tr>";
			oHTML = oHTML + "		</table></td>";
			oHTML = oHTML + "		<td><img src="+strBaseURL+"images/tv_visul_job_12.gif width=34 height=49></td>";
			oHTML = oHTML + "	</tr>";
			oHTML = oHTML + "</table>";
			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>";
			oHTML = oHTML + "<script language=JavaScript type=text/JavaScript DEFER=true>";
			oHTML = oHTML + "function MM_swapImgRestore() {";
			oHTML = oHTML + "  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;";
			oHTML = oHTML + "}";
			oHTML = oHTML + "function MM_preloadImages() {";
			oHTML = oHTML + "  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();";
			oHTML = oHTML + "    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)";
			oHTML = oHTML + "    if (a[i].indexOf(\"#\")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}";
			oHTML = oHTML + "}";
			oHTML = oHTML + "function MM_findObj(n, d) {";
			oHTML = oHTML + "  var p,i,x;  if(!d) d=document; if((p=n.indexOf(\"?\"))>0&&parent.frames.length) {";
			oHTML = oHTML + "    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}";
			oHTML = oHTML + "  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];";
			oHTML = oHTML + "  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);";
			oHTML = oHTML + "  if(!x && d.getElementById) x=d.getElementById(n); return x;";
			oHTML = oHTML + "}";
			oHTML = oHTML + "function MM_swapImage() {";
			oHTML = oHTML + "  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)";
			oHTML = oHTML + "   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}";
			oHTML = oHTML + "}";
			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++;
	}
}
var g_isVertical=false;
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.visibility="hidden";
			document.all.mediaTableOn.style.position="absolute";			
			document.all.mediaTableOff.style.visibility="visible";
			document.all.mediaTableOff.style.position="relative";	
		}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.visibility="hidden";
			document.all.mediaTableOff.style.position="absolute";			
			document.all.mediaTableOn.style.visibility="visible";
			document.all.mediaTableOn.style.position="relative";	
		}catch(e){}
	}
}

function your_StartZoom() {
	if(g_isFullScreen != 2 && g_bDbookExtend=="y"){
		resizeWindowOrDbook(Math.pow(2,1));
	}
}

function your_EndZoom(){
	if(g_isFullScreen != 2 && g_bDbookExtend=="y"){
		resizeWindowOrDbook(Math.pow(2,0));
	}
}

function resizeWindowOrDbook(nRatio){
	var nMinWinWidth = 0, nMinWinHeight=0;
	var nWidthGap = g_nWidthGap, nHeightGap=g_nHeightGap;
	var nAvailWidth = screen.availWidth;
	var nAvailHeight = screen.availHeight;
	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;
	var nWinWidth =0, nWinHeight=0 ;
	var isOverFlowX = true, isOverFlowY = true;
	if(nViewerWidth>(nAvailWidth-nWidthGap)){
		nDBookWidth = nViewerWidth;
		nWinWidth = nAvailWidth;
	}else if(nDBookWidth>(nAvailWidth-nWidthGap)){
		nDBookWidth = nAvailWidth-nWidthGap;
		nWinWidth = (nDBookWidth+nWidthGap);
	}else{
		nWinWidth = (nDBookWidth+nWidthGap);
		isOverFlowX = false;
	}
	if(nViewerHeight>(nAvailHeight-nHeightGap)){
		nDBookHeight = nViewerHeight;
		nWinHeight = nAvailHeight;
	}else if(nDBookHeight>(nAvailHeight-nHeightGap)){
		nDBookHeight = nAvailHeight-nHeightGap;
		nWinHeight = (nDBookHeight+nHeightGap);
	}else{
		nWinHeight = (nDBookHeight+nHeightGap);
		isOverFlowY = false;
	}
	
	if(nRatio==1){
		nDBookWidth=nViewerWidth;
		nDBookHeight= nViewerHeight;
	}
	
	if(isOverFlowX && !isOverFlowY){
		nWinHeight = nWinHeight+20;
	}
	if(isOverFlowY && !isOverFlowX){
		nWinWidth = nWinWidth+20;
	}	
	document.all["viewerDiv"].style.width = nDBookWidth;
	document.all["viewerDiv"].style.height = nDBookHeight;
	document.all["dBook"].width = nDBookWidth;
	document.all["dBook"].height = nDBookHeight;
	document.dBook.handle_resize(nDBookWidth,nDBookHeight);
	
	if(nWinWidth<g_nMinWinWidth) nWinWidth=g_nMinWinWidth;
	if(nWinHeight<g_nMinWinHeight) nWinHeight=g_nMinWinHeight;
	var nWinX = parseInt((nAvailWidth-nWinWidth)/2);
	var nWinY = parseInt((nAvailHeight-nWinHeight)/2);

	if(g_isFullScreen==0){
		try{
			window.resizeTo(nWinWidth,nWinHeight);
			window.moveTo(nWinX,nWinY);
		}catch(e){}
	}
}

var g_isDPage=1;
function your_treatSlidePage(){
	
	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","search","print");
	for(var i=0; i<arrFrame.length; i++){
		oFrame = document.all[arrFrame[i]];
		if(arrFrame[i] != frameID){
			oFrame.style.left = 0;
			oFrame.style.top = 0;
			oFrame.style.width = 10;
			oFrame.style.height = 10;		
			oFrame.style.visibility="hidden";						
		}
	}
}

function moveAndResizeFrame(frameID, w, h){
	var oFrame = document.all[frameID];	
	var cTable = document.all["viewTable"];
	var oRcts = cTable.getBoundingClientRect();	
	oFrame.style.left = oRcts.left+104;
	if(frameID=="print"){
		oFrame.style.top = oRcts.top+210;
	}else if(frameID=="search"){
		oFrame.style.top = oRcts.top+150;	
	}else{
		oFrame.style.top = oRcts.top+85;
	}

	oFrame.style.pixelWidth = w;
	if (h>500){
		h = 500;
	}
	oFrame.style.pixelHeight = h;
}

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_mainHost) >=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("ÀÎÈ­ ½ÅÃ»Àº " + g_mainHost + " ¿¡¼­¸¸ °¡´ÉÇÕ´Ï´Ù");
		}	
	}catch(e){
		alert("ÀÎÈ­ ½ÅÃ»Àº " + g_mainHost + "¿¡¼­¸¸ °¡´ÉÇÕ´Ï´Ù");		
	}
}

function showFrame(frameID,viewOrHide){
	hideOtherFrame(frameID);
	var oFrame = document.all[frameID];
	if(viewOrHide=="view"){
		if(oFrame.src==""){
			oFrame.src = frameID+".htm";
		}
		oFrame.style.visibility="visible";
		try{
			document.frames(frameID).moveAndResizeFrame();
		}catch(e){}
	}else{
		oFrame.style.left = 0;
		oFrame.style.top = 0;
		oFrame.style.width = 10;
		oFrame.style.height = 10;		
		oFrame.style.visibility="hidden";	
	}
}

// On load defaunt1.html ***********************************************************************
function onLoadProcsss()
{
	// call by html document when the html document load finishing.
	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()
{
	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){
	var isRotate = document.dBook.handle_getRotateEnable();
	if(isRotate==0) {
		try{
			var num = parseInt(document.all.delay_num.value);
			if(num<1) num=1;
			if(num>50) num=50;
			document.dBook.handle_pressForwardRotate();
			document.dBook.handle_setDelayTime(num*1000);

			document.all.autoFlipTableOn.style.visibility="hidden";
			document.all.autoFlipTableOn.style.position="absolute";			
			document.all.autoFlipTableOff.style.visibility="visible";
			document.all.autoFlipTableOff.style.position="relative";
		}catch(e){
			document.dBook.handle_setDelayTime(1000);
			document.dBook.handle_pressPause();
			alert("¼ýÀÚ¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä!!");
			document.all.delay_num.focus();
			document.all.delay_num.select();
			return;			
		}
		
	}	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.visibility="hidden";
		document.all.autoFlipTableOff.style.position="absolute";			
		document.all.autoFlipTableOn.style.visibility="visible";
		document.all.autoFlipTableOn.style.position="relative";
} 

// event of cannot moving previous page 
function your_notFlipPrev() 
{ 
	alert( "Ã¹ ÆäÀÌÁö ÀÔ´Ï´Ù." ); 
    
    // Related to APPLET Parameter 'eventFunctions'.
    // TODO : Add your implementation code here.
} 

// event of cannot moving previous page 
function your_notFlipNext() 
{ 
	alert("¸¶Áö¸· ÆäÀÌÁö ÀÔ´Ï´Ù."); 
    
    // Related to APPLET Parameter 'eventFunctions'.
    // TODO : Add your implementation code here.
} 

function your_notZoom(iPage) {
	 //var msg = iPage + "Page´Â ÁÜ¹æÁö µÇ¾úÀ¾´Ï´Ù.";
	 //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;
	}


//***********************************************************************************************
// auto flip functions


function your_pressToggleAuto()
{
  if (g_bAutoRotating)
  {
    your_pressEndRotate();
  }
  else
  {
    your_pressPlayRotate();
  }
}

function your_pressEndRotate()
{
    //AUTOBUTTONTD.innerHTML = "<img src=\"images/skin_21.jpg\" alt=\"Auto Flip Start\" name=\"ImageToggleAutoPlay\" width=\"37\" height=\"33\" border=\"0\" onClick=\"javascript:your_pressToggleAuto()\" style=\"curosr:potinter;cursor:hand\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('ImageToggleAutoPlay','','images/skin_on_21.jpg',1)\">";
    your_pressReload();
    g_bAutoRotating = false;
}

function your_pressPlayRotate()
{
    //AUTOBUTTONTD.innerHTML = "<img src=\"images/skin_on_21.jpg\" alt=\"Auto Flip Stop\" name=\"ImageToggleAutoStop\" width=\"37\" height=\"33\" border=\"0\" onClick=\"javascript:your_pressToggleAuto()\" style=\"curosr:potinter;cursor:hand\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('ImageToggleAutoStop','','images/skin_21.jpg',1)\">";
    your_pressForwardRotate();
    g_bAutoRotating = true;
}


function your_pressForwardRotate()
{
  your_setDelayTime();
  HD_pressForwardRotate();
}

function your_pressBackwardRotate()
{
  your_setDelayTime();
  HD_pressBackwardRotate();
}

function your_setDelayTimeNum(nDelay)
{
  try {
    document.dBook.handle_setDelayTime(nDelay);
  } catch(eDelay1) {
    
  }
}

function your_setDelayTime()
{  
  try{
    if (delay_time.value == "")
      return;

    var nDelay = delay_time.value;
    nDelay = 1000*nDelay;             // transform from milisec to sec 
    your_setDelayTimeNum(nDelay);
  }
  catch (eDelay2) {}
}

function doKeyDelay(e)
{
	whichASC = event.keyCode;

	if (whichASC == 13){
		your_pressForwardRotate();
	}
}

//***********************************************************************************************