//------------------------------------------------------------------------------------------
//
//                audioVideo.js    ( version    v1.0.6 )
//
//                function
//
//
//
//                																  prg by pyc
//------------------------------------------------------------------------------------------

function playSound() {
      	document.all.gSound.src = g_sound;
}	

function gSoundPlay(){
	if(g_sound){
		annText2.innerHTML = '&nbsp; ¢Ü¢Ý';
		document.all.gSound.src = g_sound;
	}else{
		alert('¹è°æ À½¾ÇÀÌ µî·ÏµÇ¾î ÀÖÁö ¾Ê½À´Ï´Ù');
	}
}

function gSoundStop(){
	if(g_sound) {
		document.all.gSound.src = '';
		annText2.innerHTML = '';
	}	
}	




//--------------------------- web page ------------------------------------------

function  chkWebPageView()
{
	var sp = g_cpage- g_spage, j=0;
	
	if (g_bookPage[sp])
	{
		for( j=0; j<g_bookPage[sp].length; j++)
		{
			//webPageView(sp,j,(sp%2), true);
			webPageView(sp,j,0, true);			//2008.3.8
			j = g_epage;
		}
	}
	sp+=1;
	if (g_bookPage[sp]) 
	{
		for( j=0; j<g_bookPage[sp].length; j++)
		{
			//webPageView(sp,j,(sp%2), true);
			webPageView(sp,j,1, true);		//2008.3.8
			j = g_epage;
		}
	}
}



function  webPageView(sp,i,mode, chk)
{
	//var URL = g_bookPage[sp].url;
	//var skin = g_bookPage[sp].skin;
	//alert(sp+' '+mode);
	if(chk)
	{
		if (g_bookPage[sp][i].after) 	var ndZindex = g_showPage;
		else 	var ndZindex = g_hiddenPage;
		parent_bpLDiv = document.all['layerl'+g_showPage];
		parent_bpRDiv = document.all['layerr'+g_showPage];
		
		if (mode==0)	var curMDiv = parent_bpLDiv;
		else var curMDiv = parent_bpRDiv;

		createWebPage(curMDiv,g_bookPage[sp][i],ndZindex);
	}
}

function createWebPage(top_Div,bPage,ndZindex)
{
	var cNewDiv = document.createElement("iFrame");
	if(bPage.mode == "web2" || bPage.mode == "Video" )
	{
		cNewDiv.src = filedir+"video/"+bPage.url;
		cNewDiv.frameBorder=0;
		cNewDiv.scrolling="no";
	}
	else {
		cNewDiv.src = bPage.url;
	}
	with ( cNewDiv.style )
	{
		position = "absolute";
		align="center";
		left =  bPage.left;
		top =  bPage.top;
		width = bPage.right;
		height = bPage.bottom;
		if ( bPage.skin == '1' ){      scrolling = "auto";   }
		else if (bPage.skin == '2'){	scrolling = "no";   }
		frameborder=0;
		border = 0;
		framespacing = 0;
		//bordercolor="red";
		zIndex = ndZindex ;
	}
	top_Div.appendChild(cNewDiv);
	g_bookPageFlag = true;
}



function DestoryWepPageLink( top_Div,ndZindex) {
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			if (oChild.style.zIndex == ndZindex ){
				 top_Div.removeChild(oChild) ;
			}
		}
	}

}





//----------------- large -----------------------------------------
function  webLargePageView(sp){
	var URL = "";
	var ndZindex = 65;
	var curMDiv = parent_bpLarDiv;
	
	//for( var i=0; i<g_bookPage[sp- g_spage].length; i++) {			
	sp = sp - g_spage;
	for( var i=0; i<g_bookPage[sp].length; i++) {			
		URL = g_bookPage[sp][i].url;
		if(URL) createWebLarPage(curMDiv,URL,ndZindex);
	}

}



function createWebLarPage(top_Div,URL,ndZindex){
		var cNewDiv = document.createElement("iFrame");
//              cNewDiv.outerHTML = "<iframe  id=WebPageFrame ></iframe>" ;
		with (cNewDiv ) {
			with ( style ) {
				position = "absolute";
//				align="center";
//				valign="middle";
				left =  0;
				top =  27;
				width =  g_width+3; //"95%";
				height = g_height-23; //"95%";
				zIndex = ndZindex ;
//				border = 0;
//				bordercolor="blue";
				frameborder="1";
				scrolling="auto";
			}
			src=URL;
		}
		//top_Div.appendChild(cNewDiv);			//µ¿¿µ»ó È®´ë ±ÝÁö 2008.3.8
		g_bookPageLFlag = true;
}

function DestoryWepLarPageLink( top_Div,ndZindex) {
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			if (oChild.style.zIndex == ndZindex ){
				 oChild.src='';
				 top_Div.removeChild(oChild) ;

			}
		}
	}
	g_bookPageLFlag = false;
}



//-------------- page audio link ------------------------------------------
function createAudioplay(URL,ndZindex){
	var cSoundObj = document.createElement("Embed");
	parent_AVDiv.appendChild(cSoundObj);
       cSoundObj.outerHTML = "<embed id=gSound2  src="+URL+">" ;
	with(cSoundObj) {
		with(style) {
			zIndex = ndZindex;
			hidden="false";
			border="0";
			width="290";
			height="44";
			autostart="true";
			loop="1";
			PLUGINSPAGE="HTTP://quicktime.apple.com/qt/sw/sw.html"
		}

      }
      g_AVPageFlag = true;
}




function createVideoplay(URL,ndZindex){
	var cSoundObj = document.createElement("Embed");
	parent_AVDiv.appendChild(cSoundObj);
       cSoundObj.outerHTML = "<embed id=gSound3  src="+URL+">" ;
	with(cSoundObj) {
		with(style) {
			zIndex = ndZindex;
			hidden="false";
			border="0";
			left = g_bx1;
			top = g_top;
			width="320";
			height="284";
			autostart="true";
			loop="1";
			PLUGINSPAGE="HTTP://quicktime.apple.com/qt/sw/sw.html"
		}

      }
      g_AVPageFlag = true;
}


function DestoryAVplay() {
	var top_Div = parent_AVDiv;
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			 top_Div.removeChild(oChild) ;
		}
	}
	g_AVPageFlag = false;
}


function AVplay(ndZindex) {
	var top_Div = parent_AVDiv;
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			if (oChild.style.zIndex == ndZindex ){
				 oChild.play();
			}
		}
	}
}


function AVstop(ndZindex) {
	var top_Div = parent_AVDiv;
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			if (oChild.style.zIndex == ndZindex ){
				 oChild.stop();

			}
		}
	}
}



//---------------------------------book  page add audio -----------------------------
function  audioGoLink(sp,i,mode){
	var URL = g_bookPage[sp][i].url;
	var ndZindex = 100;
	//createAddAplay(URL,ndZindex);
	var left= g_bxl1;
	if (b_direct =='0'){
		if(mode==1) 	left =  g_bxl2;
	}else{
		if(mode==0) 	left = g_bxl2;
	}
	//createAddAplay(URL,ndZindex,left);
	createAddAplay2(URL,ndZindex,left);
	//activeEmbedSound( pos, URL );
}




function createAddAplay(URL,ndZindex,left){
	var cSoundObj = document.createElement("Embed");
	parent_AVDiv.appendChild(cSoundObj);
       cSoundObj.outerHTML = "<embed id=gSound4  src="+URL+">" ;
	with(cSoundObj) {
		with(style) {
			zIndex = ndZindex;
			hidden= false;
			border="0";
			left = left;
			top = g_top;
			width="290";
			height="44";
			if (g_bookPageAddSFlag) autostart=false;
			else  autostart= true;
			loop="1";
			showControls = true;
		}

      }
      g_bookPageAddSFlag = true;
}


function DestorybpAddAudio(ndZindex) {
	var top_Div = parent_AVDiv;
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			top_Div.removeChild(oChild) ;
		}
	}
      g_bookPageAddSFlag = false;
}



function createAddAplay2(URL,ndZindex,sleft){
	var i ;
		var cSoundObj = document.createElement("Div");
		parent_AVDiv.appendChild(cSoundObj);
		with (cSoundObj ) {
			with ( style ) {
				position = "absolute";
				visibility = "visible" ;
				left = sleft;
				top = g_top;
				width = 290 ;
				height = 44 ;
				zIndex = ndZindex ;
			}
			innerHTML = "<embed src="+URL+"  hidden=\"false\" border=0 width=290 height=44 autostart=\"true\" loop=1>" ;
		}
      g_bookPageAddSFlag = true;
}


//============================================= Page Mess===========================================

function  pageMessGoLink(){
	var sp = g_cpage  - g_spage;
 	parent_bpLDiv = document.all['layerl'+g_showPage];
 	parent_bpRDiv = document.all['layerr'+g_showPage];
	if ( sp >= 0 ) {
		if (g_pageMess[sp])  pageMessLink(sp,0);
	}
	if (g_pageMess[sp+1])  	pageMessLink(sp+1,1);
}




function  pageMessLink(sp,mode){

	var npMess = g_pageMess[sp];
	var npPosit= g_pSkin[11];
	var ndZindex =  g_showPage;

 	if(b_direct == '0') {
		if (mode==0)	var curMDiv = parent_bpLDiv;
		else var curMDiv = parent_bpRDiv;
	}else{
		if (mode==0)	var curMDiv = parent_bpRDiv;
		else var curMDiv = parent_bpLDiv;
	}
	if(npMess[0]) 	createPageMessLink(curMDiv,npMess[0],npPosit,ndZindex,mode);
	if(npMess[1]) 	createPageMessLink(curMDiv,npMess[1],npPosit,ndZindex,mode);
	if(npMess[2]) 	createPageMessLink(curMDiv,npMess[2],npPosit,ndZindex,mode);
}


function createPageMessLink(top_Div,npMess,npPosit,ndZindex,mode){
		var cNewDiv = document.createElement("Div");
		with (cNewDiv ) {
			with ( style ) {
				cssText = "text-align=center; text-valign=middle; font:"+npMess.font+"; color:"+npMess.color+"; font-size:"+npMess.size+"pt";
				position = "absolute";
				visibility = "visible" ;
				left = npMess.x;
				top = npMess.y;
				zIndex = ndZindex ;
				cursor="hand";
			}
			innerHTML = npMess.mess;
			if(mode==0)
 				onmousedown=imgViewlSelect;
 			else
 				onmousedown=imgViewrSelect;
 		}
		top_Div.appendChild(cNewDiv);
		g_pageMessFlag = true;
}


function imgViewlSelect(){
	if( !fullViewFlag ) imgView(0);
}

function imgViewrSelect(){
	if( !fullViewFlag ) imgView(1);
}




function DestoryPageMessLink( top_Div,ndZindex) {
	var i ;
	if (top_Div) {
		for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) {
			var oChild = top_Div.children(i);
			if (oChild.style.zIndex == ndZindex ){
				 top_Div.removeChild(oChild) ;
			}
		}
	}

}

function  pageMessLdisp(sp,rx,ry){
	var np = sp;
	var npMess = g_pageMess[np];
	var npPosit= g_pSkin[11];
	var ndZindex = 65;
	if(npMess[0])    createPageMessLLink(parent_plLDiv,npMess[0],npPosit,ndZindex,rx);
	if(npMess[1])    createPageMessLLink(parent_plLDiv,npMess[1],npPosit,ndZindex,rx);
	if(npMess[2])    createPageMessLLink(parent_plLDiv,npMess[2],npPosit,ndZindex,rx);

}


function createPageMessLLink(top_Div,npMess,npPosit,ndZindex,rate){
       // LargeImgTop = top;
       // LargeImgLeft = left;
		var cNewDiv = document.createElement("Div");
		with (cNewDiv ) {
			with ( style ) {
				cssText = "text-align=center; text-valign=middle; font:"+npMess.font+"; color:"+npMess.color+"; font-size:"+Math.ceil(rate * npMess.size)+"pt";
				position = "absolute";
				visibility = "visible" ;
				left = Math.ceil(rate *npMess.x);
				top = Math.ceil(rate *npMess.y);
				zIndex = ndZindex ;
				cursor="hand";
			}
			innerHTML = npMess.mess;
			onclick=FullImg3Cancel;
			onmousewheel=onLargeMouseWheel;
			onmousedown=MouseSiScrollInit;
			onmouseup=MouseSiScrollStop;
		}

		top_Div.appendChild(cNewDiv);
		 g_pageMessLFlag = true;
}


function DestoryAllChildNode( top_Div ) {
	var i ;
	try {
		if (top_Div) {
			for(i=top_Div.childNodes.length - 1 ; i >-1 ; i--) 	 top_Div.removeChild(top_Div.children(i)) ;
		}
	} catch (e) { alert(e); }

}


function DestoryAllNode() {
	DestoryAllChildNode( parent_bpLDiv );
	DestoryAllChildNode( parent_bpRDiv );
	DestoryAllChildNode( parent_bpLarDiv );
	DestoryAllChildNode( parent_AVDiv );
	DestoryAllChildNode( parent_gSound );
	DestoryAllChildNode( parent_plMDiv );
	DestoryAllChildNode(  parent_plLDiv );
}


