//------------------------------------------------------------------------------------------
//
//                slic_func.js    ( version    v1.0.6 )
//
//                function
//
//
//
//                																  prg by pyc
//------------------------------------------------------------------------------------------

var g_ZoomProgressFlag = false;

function slicImgMovedragIt(){
    var nx =  event.clientX;
    var ny =  event.clientY;
    var x = g_OldMousePos_X - nx;
    var y = g_OldMousePos_Y - ny;
    if( Math.abs(x) > 5 || Math.abs(y) > 5){
    	scrollBigImg(x,y);
    	g_OldMousePos_X = nx;
    	g_OldMousePos_Y = ny;
    }
}


function MouseSiScrollInit(){
   	var mkey =  window.event.button;
             g_OldMousePos_X = event.clientX; //event.offsetX;
             g_OldMousePos_Y = event.clientY; //event.offsetY;
             g_zoomMouseAblity = false;
       if(mkey == 1) {
		  this.style.cursor ="MOVE" ;
                document.onmousemove = slicImgMovedragIt;
       }else if(mkey == 2) {
	    	  document.onmousemove = dlg_callMenu;
      		  FullImg3Cancel();
       	}
}


function MouseSiScrollStop(){
	    this.style.cursor ="hand" ;
	    document.onmousemove = dlg_callMenu;
}


function  slicLinkLoad(sp){
        //LargeImgTop = top;
        //LargeImgLeft = left;g_imgnY  -
       if(g_zoomposflag) {
       	   var starty = Math.ceil((g_height/2 - LargeImgTop)/g_py);
       	}else{
       	   var starty = Math.ceil((g_height/2)/g_py);
       	}
	createDivImg(parent_plLDiv,g_pxn,g_pyn,sp,starty,0);
}



function createDivImg(top_Div,xnum,ynum,sp,sy,sx){
	var x,y,ro=0,hy,ly ;
	var rFlag = true;
	hy = sy;
	ly = sy;
       y = sy;
	do {
		if( y >= 0  && y <ynum) {
			for(x=sx; x<xnum; x++){
				var cNewDiv = document.createElement("Div");
				var cNewImg = document.createElement("IMG");
				createSlicDiv(cNewDiv,x,y,sp);
				createSlicImg(cNewImg,x+1,y+1,sp);
				cNewDiv.appendChild(cNewImg);
				top_Div.appendChild(cNewDiv);
			}
		}else if( ly <0 && hy>= ynum) rFlag = false;
		if(++ro % 2 ==1) {
			hy = hy+1;
			y = hy;
		}else{
			ly = ly-1;
			y = ly;
		}
	}while(rFlag);
}



var g_SlicImgLoad = false;
function createSlicDiv(cDiv,x,y,sp){
		var id=x.toString()+y.toString();
		with (cDiv ) {
				with ( style ) {
					cursor = "hand";
					position = "absolute";
					visibility = "hidden" ;
					left = g_px * x+g_LimgMargin;
					top = g_py * y+g_LimgMargin;
				//	width = g_px;
				//	height = g_py;
					zIndex = 1;
				}
				try{
				// onclick=FullImg3Cancel;
				onmousewheel=onLargeMouseWheel;
				onmousedown=MouseSiScrollInit;
				onmouseup=MouseSiScrollStop;
				}catch(e) { alert(e); }
		}
		return cDiv;
}



function 	createSlicImg(cImg,x,y,sp){
		var id=x.toString()+y.toString();
		var fname = fileName('lc',sp);
		fname = fname.split('.mcd')[0];
		if (y <10 ) fname = fname + '_0'+y;
		else	 fname = fname + '_'+y;
		if (x <10 ) fname = fname + '_0'+x;
		else	 fname = fname + '_'+x;
		with (cImg ) {
				src = fname+".jpg";
				with ( style ) {
					position = "absolute";
					left = 0;
					top = 0;
				//	width = g_px;
				//	height = g_py;
					alt="";
				}
		}
		g_SlicImgLoad = true;
//		g_ZoomProgressFlag = false;
		return cImg;
}




//======================== destroy ============================
function DestorySlicLink() {
	var i,ndZindex=1;
	var top_Div = parent_plLDiv;
	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) ;
		}
	}
	g_SlicImgLoad = false;

}


function lLoadAfterDisp(sp){
    var np = sp- g_spage;
    //var ratioX = g_imgnX/g_bx;
    //var ratioY = g_imgnY/g_by;
    var ratioX = g_imgX/g_pageX[sp];
    var ratioY = g_imgY/g_pageY[sp];
    if( g_info1PageFlag ){		//page ¸µÅ© È£Ãâ
	    	if( g_info1Page[np] ) pageGoLinkLdisp(np,ratioX,ratioY);
    }

    if( g_info3PageFlag ){		//url ¸µÅ© È£Ãâ
	    	if( g_info3Page[np] ) urlGoLinkLdisp(np,ratioX,ratioY);
    }

    if( g_pageMessFlag ){		//ÆäÀÌÁö mess È£Ãâ
	    if( g_pageMess[np] ) pageMessLdisp(np,ratioX,ratioY);
    }
}

//======================== load large img ========================================


function ZoomPos(){
        var sx = event.clientX ;    //offsetX g_imgnX, g_imgnY     event.offsetY;
        var sy = event.clientY;    // offsetY g_bx g_by      g_height
        var nx =  Math.round(sx * g_imgnX / g_bx);
        var ny =  Math.round(sy * g_imgnY / g_by);

       if(g_imgnY > g_height+g_LimgMargind) {
           var top = Math.round(g_height/2) - ny ;
           if (top > 0 ) top = 0;
           else if ( (g_imgnY + top) < g_height ) top = g_height - g_imgnY-g_LimgMargind;
       }else{
           var top = Math.round((g_height-g_imgnY)/2);
       }

       if(g_imgnX > g_width+g_LimgMargind){
           var left = Math.round(g_width/2)- nx ;
           if( g_pos == 0 ){                           // left
                if (left > 0 ) left = 0;
                else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }else{                                                                             // right
                if (left > 0 ){
                     if( g_imgnX < g_width )   left = g_width - g_imgnX-g_LimgMargind;
                     else left = 0;
                }else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }
        }else if(g_imgnX > g_width/2){
          if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargind;
           }else{
	           if( g_pos == 1 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargind;
           }
        }else{
           if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = g_bxl2-g_imgnX-g_LimgMargind;
	           else              left = g_bxl2;
           }else{
	           if( g_pos == 1 )  left = g_bxl2-g_imgnX-g_LimgMargind;
	           else             left = g_bxl2;
           }
        }

        LargeImgTop = top;
        LargeImgLeft = left;
	return true;
}


function ZoomPos0(){
       var top = 0;
       var left = g_imgnX ;


       if(g_imgnX > g_width+g_LimgMargind){
           if( g_pos == 0 ){                           // left
                if (left > 0 ) left = 0;
                else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }else{                                                                             // right
                if (left > 0 ){
                     if( g_imgnX < g_width )   left = g_width - g_imgnX-g_LimgMargind;
                     else left = 0;
                }else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }
        }else if(g_imgnX > g_width/2){
           if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargin;
           }else{
	           if( g_pos == 1 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargin;
           }
        }else{
           if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = g_bxl2-8-g_imgnX-g_LimgMargin;
	           else              left = g_bxl2;
           }else{
	           if( g_pos == 1 )  left = g_bxl2-8-g_imgnX-g_LimgMargin;
	           else             left = g_bxl2;
           }
        }

        LargeImgTop = top;
        LargeImgLeft = left;
	return true;
}


function ZoomPos1(){
       var top = 0;
       var left = g_imgnX ;

       var top = Math.round((g_height-g_imgnY)/2);


       if(g_imgnX > g_width+g_LimgMargind){
           if( g_pos == 0 ){                           // left
                if (left > 0 ) left = 0;
                else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }else{                                                                             // right
                if (left > 0 ){
                     if( g_imgnX < g_width )   left = g_width - g_imgnX-g_LimgMargind;
                     else left = 0;
                }else if( (g_imgnX + left) < g_width && g_imgnX > g_width) left = g_width - g_imgnX-g_LimgMargind;
            }
        }else if(g_imgnX > g_width/2){
           if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargin;
           }else{
	           if( g_pos == 1 )  left = 0;
	           else              left = g_width - g_imgnX-g_LimgMargin;
           }
        }else{
           if ( b_direct == '0' ){
	           if( g_pos == 0 )  left = g_bxl2-8-g_imgnX-g_LimgMargin;
	           else              left = g_bxl2;
           }else{
	           if( g_pos == 1 )  left = g_bxl2-8-g_imgnX-g_LimgMargin;
	           else             left = g_bxl2;
           }
        }


        LargeImgTop = top;
        LargeImgLeft = left;
	return true;
}

function   calcuLayerPos(menu){
	    g_zoomposflag = true;
	    g_zoomMouseAblity= true;
	    var retV = true;
	    if (g_pSkin[17] == 't' ) {
	    		retV = ZoomPos0();									//»óÀ§ ±âÁØ È®´ë
	    }else if (g_pSkin[17] == 'c' ) {
			retV = ZoomPos1();									//Áß¾È ±âÁØ È®´ë
	    }else if (g_pSkin[17] == 'm' ) {
		    if (!menu)    retV = ZoomPos();							//¸¶¿ì½º ±âÁØ È®´ë
		    else retV = ZoomPos1();
	    }
           g_zoomposflag=false;
	    return retV;
}

function  fullWindow5_Open(sp){
	 load_lPage(sp,g_pos,g_showPage);

}


function fullWindow4_Open(count){    // Å« ÀÌ¹ÌÁö È£Ãâ 3/3
       clearTimeout(timeidplt);
       ++count;
       if ( g_LargeImgPreLoading == 0 && g_LargeImgPLCount > 0 && g_cpage == 0 ){
       	            var sp=0;
		    fullWindow5_Open(sp);
	 	    g_ZoomProgressFlag = false;
	}else if (g_LargeImgPreLoading == 0 && g_LargeImgPLCount > 0 &&  g_pos==0){
		    if(g_cpage == 0) var sp=0;
		    else var sp = g_cpage+g_pos;
		    fullWindow5_Open(sp);
	 	    g_ZoomProgressFlag = false;
	}else if (g_LargeImgPreLoading == 0 && g_LargeImgPLCount == 2 &&  g_pos==1){
		    if(g_cpage == 0) var sp=0;
		    else var sp = g_cpage+g_pos;
		   fullWindow5_Open(sp);
	 	    g_ZoomProgressFlag = false;
	}else{
	    if (count > 30) {
		    if(g_cpage == 0) var sp=0;
		    else var sp = g_cpage+g_pos;
		    fullWindow5_Open(sp);
	 	    g_ZoomProgressFlag = false;
	    }else{
	           timeidplt = setTimeout("fullWindow4_Open("+count+")",100);
	    }
	}
}






var    g_miniMapFlag=false;
var    g_coorFlag=false;

var AlphaFilter = true;

function fullWindow3_Open(){    // Å« ÀÌ¹ÌÁö È£Ãâ 3/3
//        LargeImgTop = top;
//        LargeImgLeft = left;
       layerfull.style.top = LargeImgTop;
       layerfull.style.left = LargeImgLeft;
	Fullimg.width = g_imgnX;
    	Fullimg.height = g_imgnY;

    if(g_cpage == 0) var sp=0;
    else var sp = g_cpage+g_pos;

    fullViewMoveFlag = false;
    //document.onmousemove = dlg_callMenu;


    if( g_coorFlag  &&  g_ZoomProgressFlag) {
    	if (g_imgnX+g_LimgMargind >  g_width ){
			showLayer(layercol);
			showLayer(layercor);
        		if(LargeImgLeft<0)		showTag("layercolDisp");
        		else	hiddenTag("layercolDisp");
      		       if(g_imgnX+LargeImgLeft>g_width) showTag("layercorDisp");
			else	hiddenTag("layercorDisp");
	}
	if (g_imgnY+g_LimgMargind >  g_height ){
			showLayer(layercot);
			showLayer(layercob);
        		if(LargeImgTop<0)		showTag("layercotDisp");
        		else	hiddenTag("layercotDisp");
      		       if(g_imgnY+LargeImgTop>g_height) showTag("layercobDisp");
			else hiddenTag("layercobDisp");
	}
   }
    lLoadAfterDisp(sp);
    g_ZoomProgressFlag = false;

}



var g_miniMapStart = false;
function miniMapDisp(sp)
{
	var ratio = g_imgnX/g_imgnY;

	if(!g_miniMapStart)
	{
		m_height = m_width/ratio;
		layermap.style.left = g_width- (m_width+4+30);
		layermap.style.top = g_height-(m_height+20+19 +10+30);

		layermapb.style.left = g_width- (m_width+4+30);
		layermapb.style.top = g_height-(m_height+20+10+30);
		layermapb.style.width = m_width+6;
		layermapb.style.height = m_height+6;

		layermapm.style.left = g_width- (m_width+4+30);
		layermapm.style.top = g_height-(m_height+20+10+30);

		mapimg.width=m_width+2;
		mapimg.height=m_height+2;
		g_miniMapStart = true;
	}

	if ( AlphaFilter ) {
		if(g_pSkin[2] == '0') mapimg.src = fileName('m',sp);
		else  mapimg.src = fileName('s',sp);
	}
	else	 mapimg.src = 'icon/sizeable2.gif';

	mapimgid.width=m_width+2;
	mapimgid.height=m_height+2;
	mapimgid.src = fileName('s',sp);

	mapDispb.style.width = m_width+6;
	mapDispb.style.height = m_height+6;

	showLayer('layermap');
	showLayer('layermapb');
	showLayer('layermapm');

	//	 mDbwcenter.style.width = Math.round(m_width * g_width / g_imgnX);
	//	 mDbhmiddle.style.height = Math.round(m_height * g_height / g_imgnY);
	m_cx = Math.floor(m_width * g_width / g_imgnX);
	m_cy = Math.floor(m_height * g_height / g_imgnY);

	if(g_imgnX>g_imgnY)
	{
		m_cx = m_width;
		m_cy = m_height;
	}
	showViewRec();
}


function viewSlicImgDiv() {
	var i,ndZindex=1;
	var top_Div = parent_plLDiv;
	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.style.visibility = "visible";
		}
	}

}


function fullWindow2_Open(pos,count){
//        LargeImgTop = top;
//        LargeImgLeft = left;
	var maxCount=5;
	clearTimeout(timeidplt);
	if(count++ < maxCount) {
		layerfull.style.top = g_top - ((g_top - LargeImgTop)*count/maxCount);
		if(g_cpage < 1)	 layerfull.style.left =  g_bxl1 + g_bx/2 - ((g_bxl1 + g_bx/2 - LargeImgLeft)*count/maxCount);
		else if(pos == 0)	    layerfull.style.left = g_bxl1 - ((g_bxl1 - LargeImgLeft)*count/maxCount);
		else    layerfull.style.left = g_bxl2 - ((g_bxl2 - LargeImgLeft)*count/maxCount);

	        Fullimg.width = g_bx + (g_imgnX-g_bx)*count/maxCount;
	        Fullimg.height = g_by + (g_imgnY-g_by)*count/maxCount;
	        
		 timeidplt = setTimeout("fullWindow2_Open("+pos+","+count+")",10 ); //LargeCallDelayTime
	}else{
		 fullImgCodi.border=2;
		 viewSlicImgDiv();
		 setTimeout("fullWindow3_Open()"); //LargeCallDelayTime
	}
}

var g_imgnX=0,g_imgnY=0;
var g_LimgMargin = 5;
var g_LimgMargind = 10;


var g_ratio=0;
function imgLargeSize(pos){
	    if (b_direct =='0')    var _pos = pos;
	    else if ( pos == 0 )   var _pos = 1;
	    else                       var _pos = 0;
	    if(g_cpage == 0) var sp=0;
	    else var sp = g_cpage+ _pos;

		    if(g_pageX[sp]) {
		    	var ratio = g_imgX/g_pageX[sp];
		    	g_imgnX = Math.round(g_pageX[sp]*ratio);
		    	g_imgnY = Math.round(g_pageY[sp]*ratio);
		    	//alert('p='+sp+' ratio='+ratio+' y='+g_pageY[sp]+' ly='+g_imgY+'  nY='+g_imgnY);
		    	g_imgX = g_imgnX;
		    	g_imgY = g_imgnY;
		    	g_ratio = ratio;
		    }else{
		    	g_imgnX = g_imgX;
		    	g_imgnY = g_imgY;
		    	g_ratio =   g_imgX/g_bx;
		    }
}

function fullWindow1_Open(pos,Menu){    // Å« ÀÌ¹ÌÁö È£Ãâ 1/3
    if (b_direct =='0')    g_pos = pos;    //  ZoomPos ¹Ø¿¡ Á¸Àç
    else if ( pos == 0 )   g_pos = 1;
    else                       g_pos = 0;

    if(g_cpage == 0) var sp=0;
    else var sp = g_cpage+g_pos;
    if( 0<= sp && sp <g_page) {
	     if (isWebPage(sp-g_spage)){		//page ¸µÅ© È£Ãâ
	     		if( fullViewFlag )   FullImg4Cancel();
		    	webLargePageView(sp);

		       g_menuFlag = true;
		       menutopFlag = true;
			//callmenu(true,24);
	              fullViewFlag = true;
	     }else{
	     	    if( fullViewFlag )   FullImg3Cancel();
	           fullViewFlag = true;
    		    g_ZoomProgressFlag = true;


	           if(g_pSkin[19]=='e'){
		    	g_imgnX = g_imgX;
		    	g_imgnY = g_imgY;
		    }

		    layerfull.style.top = g_top-g_LimgMargin;
		    if(g_cpage < 1)	 layerfull.style.left = g_bxl1 + g_bx/2-g_LimgMargin;
		    else if(pos == 0)	 layerfull.style.left = g_bxl1-g_LimgMargin;
		    else    layerfull.style.left = g_bxl2-g_LimgMargin;

		    Fullimg.width = g_bx;
		    Fullimg.height = g_by;
		    Fullimg.src =  fileName('m',sp);
		    showLayer('layerfull');
		    g_coorFlag = true;
		    g_miniMapFlag = true;
		    if(calcuLayerPos(Menu)){		//À§Ä¡ °è»êÀ» À§ÇØ ±â´Ù·Á¾ß ÇÑ´Ù.

			    switch (g_pSkin[16]) {
				case  '1' :     		//ÀÚµ¿  ¹æÇâÅ° + ¹Ì´Ï¸Ê(ÀÚµ¿)
						g_coorFlag = true;
						g_miniMapFlag = true;
						//if (g_imgnX >  g_width ) g_miniMapFlag = true;
						break;
				case  '2' :		//¹æÇâÅ°
						g_coorFlag = true;
						break;
				case  '3' :		//¹Ì´Ï¸Ê
						g_miniMapFlag = true;
						break;
				case  '4' :		//¹Ì´Ï¸Ê+¹æÇâÅ°
						g_coorFlag = true;
						g_miniMapFlag = true;
						break;
				case  '5' :		//ÁÒ±×
						showLayer('layerjbutton');
						break;
				case  '6' :		//ÁÒ±× + ¹æÇâÅ°
						g_coorFlag = true;
						showLayer('layerjbutton');
						break;
				default :
						break;
			   }
			    if ( g_miniMapFlag ) miniMapDisp(sp);
			   if(g_pxn==1 && g_pyn==1){	//´ÜÀÏ ÀÌ¹ÌÁö
				    if (g_LargeImgPreLoading == 0 && g_LargeImgPLCount == 0) {
				          if (g_pos==0) 	clearTimeout(timeidpl1);
				          else 			clearTimeout(timeidpl2);
				          fullWindow5_Open(sp);
				    }else{
				    	  fullWindow4_Open(0);
				    }
			   }else{	//´ÙÁß ÀÌ¹ÌÁö
				    slicLinkLoad(sp);

			   }
			   setTimeout("fullWindow2_Open("+pos+","+0+")",0 ); //LargeCallDelayTime
		    }

	     }
    }else{
    		fullViewFlag = false;
    }
}
//======================== Cancel large img ======================================

function FullImg5Cancel(count){
//        LargeImgTop = top;
//        LargeImgLeft = left;
	var maxCount=5;
	if(count == null) count = maxCount;
	if (b_direct =='0')    pos = g_pos;
	else if ( g_pos == 0 )   pos = 1;
	else                           pos = 0;
	if(--count>0) {
		layerfull.style.top = g_top - ((g_top - LargeImgTop)*count/maxCount);
		if(g_cpage < 1)	 layerfull.style.left =  g_bxl1 + g_bx/2 - ((g_bxl1 + g_bx/2 - LargeImgLeft)*count/maxCount);
		else if(pos == 0)	    layerfull.style.left = g_bxl1 - ((g_bxl1 - LargeImgLeft)*count/maxCount);
		else    layerfull.style.left = g_bxl2 - ((g_bxl2 - LargeImgLeft)*count/maxCount);

	        Fullimg.width = g_bx + (g_imgnX-g_bx)*count/maxCount;
	        Fullimg.height = g_by + (g_imgnY-g_by)*count/maxCount;
		 setTimeout("FullImg5Cancel("+count+")",10 ); //LargeCallDelayTime
	}else{
//   	    document.onkeydown=dlg_keydown;
//	    document.onmousemove = dlg_callMenu;
	    hiddenLayer('layerfull');
	    Fullimg.scr = 'icon/sizeable2.gif';
	    mapimg.src = 'icon/sizeable2.gif';
	    mapimgid.src = 'icon/sizeable2.gif';
	    if(g_miniMapFlag) {
		    hiddenLayer('layermapm');
		    hiddenLayer('layermapb');
		    hiddenLayer('layermap');
	    }
	    fullViewFlag = false;
	    g_zoomMouseAblity=false;
	    g_ZoomProgressFlag = false;
	}
}

function FullImg4Cancel(){
           if(g_coorFlag){
           	    hiddenLayer('layercol');
           	    hiddenLayer('layercot');
           	    hiddenLayer('layercor');
           	    hiddenLayer('layercob');
           }
           hiddenLayer('layerjbutton');
	    if ( g_SlicImgLoad ) DestorySlicLink();
	    fullImgCodi.border=0;
	    FullImg5Cancel();
}

function FullImg3Cancel(){
	   if (g_ZoomProgressFlag ) return;
	   g_ZoomProgressFlag = true;
	   if( g_info1PageLFlag  || g_info3PageLFlag || g_pageMessLFlag) {
			var plZindex = 65;
	 	       DestorypageLink( parent_plLDiv,plZindex);
	 	       g_info1PageLFlag = false;
	 	       g_info3PageLFlag = false;
	 	       g_pageMessLFlag = false;
	   }

	   if( g_bookPageLFlag ) {
	   	       DestoryWepLarPageLink( parent_bpLarDiv,65 );
	   }
          FullImg4Cancel();
}


function FullImgCancel(){
    var mkey =  window.event.button;

    if ( mkey == 2 ){
	    clearTimeout(timeidplt);
	    FullImg3Cancel();
    }
}


function FImgCancel(){
    if (fullViewFlag){
	    clearTimeout(timeidplt);
	    FullImg3Cancel();
    }
}

