/**
 * @author Song Ji-Hoon.
 *
 * Copyright by Softmagic. All rights reserved.
 */

var bufferImg = new Image();
var bufferOrder = new Array(0, 1, 3, 2, -2, -1);

var sliceNum = parent.sliceNumber;
var currSliceNum;
var currDetailLeftPage;

var NZX, NZY; 
var SZX, SZY;
var SZMX, SZMY;

var SEP = false;
var SSP = false;
var isVirtualWidth = false;
var isVirtualHeight = false;

var borderThickness;
var displayAreaWidth, displayAreaHeight;
var briefViewLeft, briefViewTop;
var openedBookWidth, openedBookHeight; 
var totalOpenedBookWidth, totalOpenedBookHeight;
 
var ID_GotoPage, IIDGet_8X, IIDGet_2X, IIDGet_1X, IIDWFS, IIDPS, IIDPZ; 
var isRunning = false;
var detailViewLeft, detailViewTop;                                                               

var okSliceImgs = new Array();  
var okIPR, okIPL, okIPS, okIPS1, okRight_M_Img, okLeft_M_Img;                                       

var dragStartTop;
var dragStartLeft;
var isScrolling;
var isDragging;

var IIDScrollX, IIDScrollY;   
var currScrollPointX, currScrollPointY;
var beforeScrollPointX, beforeScrollPointY;  
var isMouseDown      = false;
var clickedGotoPage  = -1;
var psize            = 0;

var sPos_x = 0;
var sPos_y = 0;

var isImgLoadComplete;

function InitScreenFrame() {
    isRunning = true;
    if (parent.menuFrameLoaded != true) {
        setTimeout("InitScreenFrame()", 10);
        return;
    }
	
	if (parent.backgroundColor) {
		document.body.style.backgroundColor = parent.backgroundColor;
		BorderEdge1.style.backgroundColor = parent.backgroundColor;
		BorderEdge2.style.backgroundColor = parent.backgroundColor;
		BorderEdge3.style.backgroundColor = parent.backgroundColor;
		BorderEdge4.style.backgroundColor = parent.backgroundColor;
		BorderTop.style.backgroundColor = parent.backgroundColor;
		BorderBottom.style.backgroundColor = parent.backgroundColor;
	} else {
		document.body.background = "./image/bg.gif";
		BorderEdge1.style.backgroundimage = "./image/bg.gif";
		BorderEdge2.style.backgroundimage = "./image/bg.gif";
		BorderEdge3.style.backgroundimage = "./image/bg.gif";
		BorderEdge4.style.backgroundimage = "./image/bg.gif";
		BorderTop.style.backgroundimage = "./image/bg.gif";
		BorderBottom.style.backgroundimage = "./image/bg.gif";
	}

    displayAreaWidth  = document.body.clientWidth;
    displayAreaHeight = document.body.clientHeight;

    isVirtualWidth   = false;
    isVirtualHeight  = false;
    openedBookWidth  = parent.pageWidth_1X * 2;
    openedBookHeight = parent.pageHeight_1Y;

    if (parent.pageWidth_2X > displayAreaWidth)   isVirtualWidth = true;
    if (parent.pageHeight_2Y > displayAreaHeight) isVirtualHeight = true;
        
	borderThickness = parent.borderThickness;
    totalOpenedBookWidth  = openedBookWidth  + borderThickness * 2;
    totalOpenedBookHeight = openedBookHeight + borderThickness * 2;
    briefViewLeft = (displayAreaWidth - totalOpenedBookWidth)/2;
    briefViewTop  = (displayAreaHeight - totalOpenedBookHeight)/2;

    BriefViewLayer.style.top    = briefViewTop;
    BriefViewLayer.style.left   = briefViewLeft;
    BriefViewLayer.style.width  = totalOpenedBookWidth;
    BriefViewLayer.style.height = totalOpenedBookHeight;

    NZX = 0;
    NZY = 0;
           
    BorderEdge1.style.left   = 0;
    BorderEdge1.style.top    = 0;
    BorderEdge1.style.width  = parent.borderEdgeWidth;
    BorderEdge1.style.height = parent.borderEdgeHeight;

    BorderEdge2.style.width  = parent.borderEdgeWidth;
    BorderEdge2.style.height = parent.borderEdgeHeight;
    BorderEdge2.style.left   = totalOpenedBookWidth - parent.borderEdgeWidth;
    BorderEdge2.style.top    = 0;

    BorderEdge3.style.left   = totalOpenedBookWidth  - parent.borderEdgeWidth;
    BorderEdge3.style.top    = totalOpenedBookHeight - parent.borderEdgeHeight * 2;
    BorderEdge3.style.width  = parent.borderEdgeWidth;
    BorderEdge3.style.height = parent.borderEdgeHeight;

    BorderEdge4.style.left   = 0;
    BorderEdge4.style.top    = totalOpenedBookHeight - parent.borderEdgeHeight * 2;
    BorderEdge4.style.width  = parent.borderEdgeWidth;
    BorderEdge4.style.height = parent.borderEdgeHeight;
         
    BorderLeft.style.left    = 0;
    BorderLeft.style.top     = parent.borderEdgeHeight;
    BorderLeft.style.width   = parent.borderEdgeWidth;
    BorderLeft.style.height  = totalOpenedBookHeight - parent.borderEdgeHeight * 2;

    BorderTop.style.left     = parent.borderEdgeWidth;
    BorderTop.style.top      = 0;
    BorderTop.style.width    = totalOpenedBookWidth - parent.borderEdgeWidth * 2;
    BorderTop.style.height   = parent.borderEdgeHeight;

    BorderRight.style.left   = totalOpenedBookWidth - parent.borderEdgeWidth;
    BorderRight.style.top    = parent.borderEdgeHeight;
    BorderRight.style.width  = parent.borderEdgeWidth;
    BorderRight.style.height = totalOpenedBookHeight - parent.borderEdgeHeight * 2;

    BorderBottom.style.left  = parent.borderEdgeWidth;
    BorderBottom.style.top   = totalOpenedBookHeight - parent.borderEdgeHeight;
    BorderBottom.style.width = totalOpenedBookWidth  - parent.borderEdgeWidth * 2;
    BorderBottom.style.height= parent.borderEdgeHeight;
    
    OpennedBookLayer.style.top    = borderThickness;
    OpennedBookLayer.style.left   = borderThickness;
    OpennedBookLayer.style.width  = openedBookWidth;
    OpennedBookLayer.style.height = openedBookHeight;

    PL.style.top    = 0;
    PL.style.left   = 0;
    PL.style.width  = parent.pageWidth_1X;
    PL.style.height = parent.pageHeight_1Y;

    PR.style.top    = 0;
    PR.style.left   = parent.pageWidth_1X;
    PR.style.width  = parent.pageWidth_1X;
    PR.style.height = parent.pageHeight_1Y;

    Left_M_Layer.style.width   = parent.pageWidth_1X;
    Left_M_Layer.style.height  = parent.pageHeight_1Y;   
    Right_M_Layer.style.width  = parent.pageWidth_1X;
    Right_M_Layer.style.height = parent.pageHeight_1Y;

    Left_M_Img.style.width     = parent.pageWidth_1X;
    Left_M_Img.style.height    = parent.pageHeight_1Y;
    Right_M_Img.style.width    = parent.pageWidth_1X;
    Right_M_Img.style.height   = parent.pageHeight_1Y;
  
    IPL.width   = parent.pageWidth_1X;
    IPL.height  = parent.pageHeight_1Y;
    IPR.width   = parent.pageWidth_1X;
    IPR.height  = parent.pageHeight_1Y;
    IPS.width   = parent.pageWidth_1X;
    IPS.height  = parent.pageHeight_1Y;
    IPS1.width  = parent.pageWidth_1X;
    IPS1.height = parent.pageHeight_1Y;
    
	LeftCenterBorder.style.top = borderThickness;
	LeftCenterBorder.style.height = parent.pageHeight_1Y;
	LeftCenterBorder.style.visibility = "visible";
	RightCenterBorder.style.top = borderThickness;
	RightCenterBorder.style.height = parent.pageHeight_1Y;
	RightCenterBorder.style.visibility = "visible";

	BriefViewLayer.style.visibility = "visible";
    isRunning = false;
    if (parent.detailViewStatus) {
        if (parent.detailRightPage) {
            ID_GotoPage = setTimeout("GotoPage(parent.briefLeftPage+1)", 10);
        } else {
            ID_GotoPage = setTimeout("GotoPage(parent.briefLeftPage)", 10);
        }
    } else {
        ID_GotoPage = setTimeout("GotoPage(parent.briefLeftPage)", 10);
    }

	soundOn();
	startCache();
}

var currentPage = 1;
var cacheSize = 4;
var nextMBuffer = new Array(cacheSize);
var previousMBuffer = new Array(cacheSize);
function startCache() {
	for (var i=0; i<cacheSize; i++) {
		if (parent.briefLeftPage+i+2 <= parent.lastPage) {
			nextMBuffer[i] = new Image();
			nextMBuffer[i].src = parent.GetImgUrl(parent.briefLeftPage+i+2, 2, 0);
		}
		if (parent.briefLeftPage-i-2 >= 0) {
			previousMBuffer[i] = new Image();
			previousMBuffer[i].src = parent.GetImgUrl(parent.briefLeftPage-i-2, 2, 0);
		}
	}
}

function stopCache() {
	for (var i=0; i<cacheSize; i++) {
		if (nextMBuffer[i] && nextMBuffer[i].readyState != "complete") {
			nextMBuffer[i].src = "";
		}
		if (previousMBuffer[i] && previousMBuffer[i].readyState != "complete") {
			previousMBuffer[i].src = "";
		}
	}
}

function PageMove(isRight) {
	if (event.button == 2 || event.button == 3) {
		ZoomIn(isRight);
	} else {
		if (isRunning == false) {
			parent.detailRightPage = isRight;
			if (parent.detailRightPage) {
				setTimeout("LeafToNext()", 10);
			} else {
				setTimeout("LeafToPrev()", 10);
			}
		}
	}
}

function WheelMove() {
	if (!parent.detailViewStatus) {
		if(event.wheelDelta < 0) { 
			if (parent.frames['Frame_Screen'].isRunning == false)
				LeafToNext();
		} else {
			if (parent.frames['Frame_Screen'].isRunning == false)
				LeafToPrev();
		}
	}
}

function LeafToNext() { 
    if (!isRunning) {
		stopCache();
        if (parent.detailViewStatus) { 
            if (currDetailLeftPage < parent.lastPage) {
                GotoPage(currDetailLeftPage+1);
                DetailViewLayer.top = 0;       
            }
            return;
        }
        if (parent.briefLeftPage+2 < parent.lastPage) { 
            isRunning = true;
            ClearBuffering();

            HideLayer("Right_M_Layer");
            HideLayer("Left_M_Layer");

            PS.style.top   = 0;
			PS.style.left  = parent.pageWidth_1X;
            PS1.style.top  = 0;
            PS1.style.left = parent.pageWidth_1X;

            okIPS = okIPS1 = false;
            
            IPS.width  = parent.pageWidth_1X;
			IPS1.width = 0;
            IPS.src  = parent.GetImgUrl(parent.briefLeftPage+1, 2, 0);
            IPS1.src = parent.GetImgUrl(parent.briefLeftPage+2, 2, 0);

            IIDGet_8X = setTimeout("LeafToNext1()", 10); 
        }
	} else { 
        setTimeout("LeafToNext()", 10);    
    }
}

function LeafToNext1() { 
    if (okIPS && okIPS1) { 
        SetSrc("Left_M_Img", parent.backgroundImgFile);
        SetSrc("Right_M_Img", parent.backgroundImgFile);
        ShowLayer("PS");
        okIPR = false;
        IPR.src = parent.GetImgUrl(parent.briefLeftPage+3, 2, 0);
        IIDGet_8X = setTimeout("LeafToNext2()", 10);
    } else { 
		IIDGet_8X = setTimeout("LeafToNext1()", 10);
	}
}

function LeafToNext2() { 
    if (okIPR) { 
        IIDGet_8X = setTimeout("LeafToNext3(parent.pageWidth_1X - parent.stepForSkip)", 1);
    } else { 
		IIDGet_8X = setTimeout("LeafToNext2()", 10);
	}
}

function LeafToNext3(arg_Size) {
    if (arg_Size != 0) {
        arg_Size = arg_Size - parent.stepForSkip;
        if (arg_Size < parent.stepForSkip) {
            arg_Size = 0;
        }
		IPS.width = arg_Size;
        IIDPS = setTimeout("LeafToNext3("+arg_Size+")", 1);
    } else {
        HideLayer("PS");
        IIDPS = setTimeout("LeafToNext4()", 2);
    }
}

function LeafToNext4() {
    if (IsImgSrcCompleteLoaded("IPS1")) {
        ShowLayer("PS1");
        IIDPS = setTimeout("LeafToNext5(" + parent.stepForSkip + ")", 1);
    } else {
		IIDGet_8X = setTimeout("LeafToNext4()", 10);
	}
}

function LeafToNext5(arg_Size) {
    if (arg_Size != parent.pageWidth_1X) {	
        arg_Size = arg_Size + parent.stepForSkip;
        if (arg_Size >= parent.pageWidth_1X) {
            arg_Size = parent.pageWidth_1X;
			PS1.style.left = 0;
        } else {
			PS1.style.left = parent.pageWidth_1X - arg_Size;
		}
		IPS1.width = arg_Size;    
        IIDPS = setTimeout("LeafToNext5("+arg_Size+")", 1);
    } else {
        PS1.style.left = 0;
        IPS1.width = arg_Size;
        okIPL = false;
        IPL.src = parent.GetImgUrl(parent.briefLeftPage+2, 2, 0);
        IIDGet_8X = setTimeout("LeafToNext6()", 2);
    } 
}

function LeafToNext6() {
    if (okIPL) {
        HideLayer("PS1");
        parent.briefLeftPage = parent.briefLeftPage + 2;
        parent.frames['Frame_Menu'].ShowPageNumber();
        isRunning = false;
        IIDGet_8X = setTimeout("BufferingNext()", 10);
    } else {
		IIDGet_8X = setTimeout("LeafToNext6()", 10);
	}
}

function LeafToPrev() {
    if (!isRunning) {
		stopCache();
        if (parent.detailViewStatus) {                                                   
            if (currDetailLeftPage > parent.firstPage) {
                GotoPage(currDetailLeftPage - 1);
                DetailViewLayer.top = 0;                
            }
            return;
        }  
        if (parent.briefLeftPage > parent.firstPage) {   
            isRunning = true;
            ClearBuffering();

            HideLayer("Right_M_Layer");
            HideLayer("Left_M_Layer");

            PS.style.top   = 0;
            PS.style.left  = 0;
            PS1.style.top  = 0;
            PS1.style.left = parent.pageWidth_1X;

            okIPS = okIPS1 = false;

            
            IPS.width  = parent.pageWidth_1X;
			IPS1.width = 0;
            IPS.src    = parent.GetImgUrl(parent.briefLeftPage, 2, 0);
            IPS1.src   = parent.GetImgUrl(parent.briefLeftPage-1, 2, 0);
            IIDGet_8X  = setTimeout("LeafToPrev1()", 10);
        }
	} else {
        setTimeout("LeafToPrev()", 10);  
    }
}

function LeafToPrev1() {
    if (okIPS && okIPS1) {
        SetSrc("Left_M_Img", parent.backgroundImgFile);
        SetSrc("Right_M_Img", parent.backgroundImgFile);
        ShowLayer("PS");
        okIPL = false;
        IPL.src = parent.GetImgUrl(parent.briefLeftPage-2, 2, 0);	  	  
        IIDGet_8X = setTimeout("LeafToPrev2()", 10); 
    } else {
		IIDGet_8X = setTimeout("LeafToPrev1()", 10);
	}
}


function LeafToPrev2() {
    if (okIPL) {
        IIDGet_8X = setTimeout("LeafToPrev3(parent.pageWidth_1X - parent.stepForSkip)", 1);
    } else {
		IIDGet_8X = setTimeout("LeafToPrev2()", 10);
    }
}

function LeafToPrev3(arg_Size) {
    if (arg_Size != 0) {    		
        arg_Size = arg_Size - parent.stepForSkip;
        if (arg_Size < parent.stepForSkip) {
			PS.style.left = parent.pageWidth_1X;
            arg_Size = 0;
        } else {
			PS.style.left = parent.pageWidth_1X - arg_Size;
		}
		IPS.width = arg_Size;
        IIDPS = setTimeout("LeafToPrev3("+arg_Size+")", 1);
    } else {
        HideLayer("PS");
        IIDGet_8X = setTimeout("LeafToPrev4()", 2);
    }
}

function LeafToPrev4() {
    if (IsImgSrcCompleteLoaded("IPS1")) {
        ShowLayer("PS1");
        IIDGet_8X = setTimeout("LeafToPrev5(0)", 1);
    } else {
		IIDGet_8X = setTimeout("LeafToPrev4()", 10);
	}
}

function LeafToPrev5(arg_Size) {
    if (arg_Size != parent.pageWidth_1X) {
        arg_Size = arg_Size + parent.stepForSkip;
        if (arg_Size > parent.pageWidth_1X) {
			arg_Size = parent.pageWidth_1X;
		}
		IPS1.width = arg_Size; 
        IIDPS = setTimeout("LeafToPrev5("+arg_Size+")", 1);
    } else {
		PS1.style.left = arg_Size;
        IPS1.width = arg_Size;
        okIPR = false;
        IPR.src = parent.GetImgUrl(parent.briefLeftPage-1, 2, 0);
        IIDPS = setTimeout("LeafToPrev6()", 2);
    }
}

function LeafToPrev6() {
    if (okIPR) {
        HideLayer("PS1");
        parent.briefLeftPage = parent.briefLeftPage - 2;
        parent.frames['Frame_Menu'].ShowPageNumber();
        isRunning = false;
        IIDGet_8X = setTimeout("BufferingPrev()", 10);
    } else {
		IIDGet_8X = setTimeout("LeafToPrev6()", 10);
	}
}

function BufferingNext() {
    if (parent.briefLeftPage+2 < parent.lastPage) {
        delete bufferImg;
        bufferImg = new Image();
        SetBuffer(bufferImg, parent.GetImgUrl(parent.briefLeftPage+3, 2, 0));
        IIDGet_8X = setTimeout("BufferingNext1()", 10);
    } else {
        IIDGet_8X = setTimeout("Show_2XPage()", 10);
    }
}

function BufferingNext1() {
    if (IsBufferDone(bufferImg)) {
        delete bufferImg;
        bufferImg = new Image();
        SetBuffer(bufferImg, parent.GetImgUrl(parent.briefLeftPage+2, 2, 0));
        IIDGet_8X = setTimeout("Show_2XPage()", 10);
		soundOn();
		startCache();
    } else {
		IIDGet_8X = setTimeout("BufferingNext1()", 10);
	}
}

function BufferingPrev() {
    if (parent.briefLeftPage-2 > 0) {
        delete bufferImg;
        bufferImg = new Image();
        SetBuffer(bufferImg, parent.GetImgUrl(parent.briefLeftPage-2, 2, 0));
        IIDGet_8X = setTimeout("BufferingPrev1()", 10);
    } else {
        IIDGet_8X = setTimeout("Show_2XPage()", 10);
    }
}

function BufferingPrev1() {
    if (IsBufferDone(bufferImg)) {
        delete bufferImg;
        bufferImg = new Image();
        SetBuffer(bufferImg, parent.GetImgUrl(parent.briefLeftPage-1, 2, 0));
        IIDGet_8X = setTimeout("Show_2XPage()", 10);
		soundOn();
		startCache();
    } else {
		IIDGet_8X = setTimeout("BufferingPrev1()", 10);
	}
}

function ClearBuffering() {
    clearTimeout(IIDWFS);
    clearTimeout(IIDGet_8X);
    clearTimeout(IIDGet_2X);
    bufferImg.src = parent.backgroundImgFile;
    delete bufferImg;
    bufferImg = new Image();
}

function GotoPage(arg_Page) {
	stopCache();
    if ((arg_Page >= parent.firstPage) && (arg_Page <= parent.lastPage)) {
        isRunning = true;
        parent.briefLeftPage = arg_Page;
        if (((arg_Page + parent.firstPage)%2) != 0) parent.briefLeftPage--;
            
        HideLayer("Right_M_Layer");
        HideLayer("Left_M_Layer");
            
	    SetSrc("IPR", "image/s.gif");
	    SetSrc("IPL", "image/s.gif");

	    SetSrc("Right_M_Img", "image/s.gif");
	    SetSrc("Left_M_Img", "image/s.gif");

        ShowLayer("PR");
        ShowLayer("PL");

        if (parent.detailViewStatus) { 
            currDetailLeftPage = arg_Page;
            if (((arg_Page + parent.firstPage)%2) != 0) {
				parent.detailRightPage = true; 
            } else { 
				parent.detailRightPage = false; 
			}
            clearTimeout(IIDGet_1X); 
            clearTimeout(IIDPZ);      

            for(n = 1; n <= sliceNum; n++) { 
                document.images("DetailViewSliceImg_" + n).src = parent.backgroundImgFile;
            }           
        }
        parent.frames['Frame_Menu'].ShowPageNumber();
        okIPR = okIPL = false;
        IIDGet_8X = setTimeout("ShowTinyPage(0)", 10);
    }
}

function ShowTinyPage(Step) {
    switch (Step) {
		case 0 : if (parent.briefLeftPage >= 1) {
					 SetSrc("IPL", parent.GetImgUrl(parent.briefLeftPage, 2, 0));
				 }
                 Step++;
				 IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                 return;
        case 1 : if (IsImgSrcCompleteLoaded("IPL")) {
					 Step++;
					 if (parent.briefLeftPage+1 <= parent.lastPage) {
						 SetSrc("IPR", parent.GetImgUrl(parent.briefLeftPage+1, 2, 0));
					 }
                     IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                 } else {
                     IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                 }
                 return;
        case 2 : if (IsImgSrcCompleteLoaded("IPR")) {
                     if (parent.briefLeftPage+bufferOrder[Step] > parent.lastPage) Step = 4;
                     if (parent.briefLeftPage+bufferOrder[Step] < 1) {
                         isRunning = false;
                         IIDWFS = setTimeout("Show_2XPage()", 10);
                         return;
                     }
                     delete bufferImg;
                     bufferImg = new Image(); 
					 SetBuffer(bufferImg, parent.GetImgUrl(parent.briefLeftPage + bufferOrder[Step], 2, 0));
                     Step++;
                     IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                 } else {
                     IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                 }
                 return;
        default : if (IsBufferDone(bufferImg)) {
                      if (Step == 5) {
                          isRunning = false;
                          IIDWFS = setTimeout("Show_2XPage_()", 10);
                          return;
                      }
                      if (bufferOrder[Step] < 1) {
                          IIDWFS = setTimeout("Show_2XPage_()", 10);
                          isRunning = false;
                          return;
                      }
                      delete bufferImg;
                      bufferImg = new Image();                        
                      SetBuffer(bufferImg, temp = parent.GetImgUrl(parent.briefLeftPage+bufferOrder[Step], 2, 0));
                      Step++;
                      IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                  } else {
                      IIDGet_8X = setTimeout("ShowTinyPage("+Step+")", 10);
                  }
                  return;
	}
}

function Show_2XPage() {
    if (parent.detailViewStatus) {
        t = true;
        for (n = 1; n <= sliceNum; n++) {
             t = t && document.images("DetailViewSliceImg_" + n).complete;
        }

        if (t) {
            NZY = document.body.clientHeight - parent.pageHeight_2Y;
            detailViewTop = NZY / 2;
            DetailViewLayer.style.left = (document.body.clientWidth  - parent.pageWidth_2X ) / 2;
            DetailViewLayer.style.top  = (document.body.clientHeight - parent.pageHeight_2Y) / 2;

            SetSrc("IZ", parent.GetImgUrl(currDetailLeftPage, 2, 0));

            IIDGet_1X = setTimeout("ShowZoom()", 10);
        } else {
            IIDGet_1X = setTimeout("Show_2XPage()", 10);
        }
	}  

    isRunning = false;
    okLeft_M_Img = okRight_M_Img = false;
          
    SetSrc("Left_M_Img", parent.GetImgUrl(parent.briefLeftPage, 0, 0));
    IIDGet_2X = setTimeout("Show_2XPage1()", 10);
}  

function Show_2XPage_() {
    if (parent.detailViewStatus) {
        t = true;
        for (n = 1; n <= sliceNum; n++) {
             t = t && document.images("DetailViewSliceImg_" + n).complete;
        }
        if (t) {
            NZY = document.body.clientHeight - parent.pageHeight_2Y;
            DetailViewLayer.style.left = (document.body.clientWidth - parent.pageWidth_2X) / 2;
            if (document.body.clientHeight > parent.pageHeight_2Y) {
                DetailViewLayer.style.top = (document.body.clientHeight - parent.pageHeight_2Y) / 2;
            } else {
                DetailViewLayer.style.top = 0;
                detailViewTop = 0;
                NZY = 0;
            }

            if (document.body.clientWidth < parent.pageWidth_2X) {
                ShowImg(LeftAutoScrollArea, 0);
                ShowImg(RightAutoScrollArea, 2);
            } else {
                HideImg(LeftAutoScrollArea, 0);
                HideImg(RightAutoScrollArea, 2);
            }
            if (document.body.clientHeight < parent.pageHeight_2Y) {
                HideImg(TopAutoScrollArea, 1);
                ShowImg(BottomAutoScrollArea, 3);
            } else {
                HideImg(TopAutoScrollArea, 1);
                HideImg(BottomAutoScrollArea, 3);
            }
              
            SetSrc("IZ", parent.GetImgUrl(currDetailLeftPage, 2, 0));

            IIDGet_1X = setTimeout("ShowZoom()", 10);
        } else {
            IIDGet_1X = setTimeout("Show_2XPage()", 10);
        }
	}

    isRunning = false;
    okLeft_M_Img = okRight_M_Img = false;
    SetSrc("Left_M_Img", parent.GetImgUrl(parent.briefLeftPage, 0, 0));
    IIDGet_2X = setTimeout("Show_2XPage1()", 10);
}        

function Show_2XPage1() {
    if (okLeft_M_Img) {
        SetSrc("Right_M_Img", parent.GetImgUrl(parent.briefLeftPage+1, 0, 0));
        ShowLayer("Left_M_Layer");
        IIDGet_2X = setTimeout("Show_2XPage2()", 10);
    } else {
		IIDGet_2X = setTimeout("Show_2XPage1()", 10);
	}
}

function Show_2XPage2() {
    if (okRight_M_Img) {
        ShowLayer("Right_M_Layer");
		soundOn();
		startCache();
    } else {
		IIDGet_2X = setTimeout("Show_2XPage2()", 10);
	}
}

function ShowZoom() {
    if (IsImgSrcCompleteLoaded("IZ")) {
        SEP = SSP = false;
        currSliceNum = Math.floor((displayAreaHeight/3 - NZY) / parent.sliceImgHeight);

        if (currSliceNum > sliceNum) currSliceNum = sliceNum;
        else if (currSliceNum < 1) currSliceNum = 1;

        document.images("DetailViewSliceImg_" + currSliceNum).src = parent.GetImgUrl(currDetailLeftPage, 1, currSliceNum);
        IIDGet_1X = setTimeout(("ZoomIn3(0)"), 10);
		hideLink();
		showLink();
        isRunning = false;
    } else {
		IIDGet_1X = setTimeout("ShowZoom()", 10);
	}
}

function ZoomIn(isRight) {
    if (isRunning) {
        return;
    }
    isRunning = true;
    parent.detailViewStatus = true;

    parent.detailRightPage = isRight;
    eventOffsetX = event.offsetX;
    detailViewLeft = briefViewLeft + borderThickness;
    currDetailLeftPage = parent.briefLeftPage;
    if (parent.detailRightPage) {
        detailViewLeft = detailViewLeft + parent.pageWidth_1X;
        currDetailLeftPage++;
    }

    parent.frames['Frame_Menu'].ShowPageNumber();

    eventOffsetY = event.offsetY;
    currSliceNum = Math.floor(eventOffsetY*parent.sliceNumber / parent.pageWidth_2X) + 3;
    if (currSliceNum > sliceNum) {
		currSliceNum = sliceNum;
	}

    detailViewTop = briefViewTop + borderThickness;

    if (displayAreaWidth >= parent.pageWidth_2X) {
        NZX = Math.floor((displayAreaWidth - parent.pageWidth_2X)/2);
    } else {
        NZX = Math.floor(displayAreaWidth/2 - eventOffsetX*parent.zoomRatio);
        if (NZX > 0) {
			NZX = 0;
        } else if (NZX < (displayAreaWidth - parent.pageWidth_2X)) {
			NZX = displayAreaWidth - parent.pageWidth_2X;
		}
    }

    if (displayAreaHeight >= parent.pageHeight_2Y) {
        NZY = Math.floor((displayAreaHeight - parent.pageHeight_2Y)/2);
    } else { 
        NZY = Math.floor(displayAreaHeight/2 - eventOffsetY*parent.zoomRatio);
        if (NZY > 0) {
			NZY = 0;
        } else if (NZY < (displayAreaHeight - parent.pageHeight_2Y)) {
			NZY = displayAreaHeight - parent.pageHeight_2Y;
		}
    }

    SZX  = Math.round((parent.pageWidth_2X - parent.pageWidth_1X) / parent.stepForDetailView);
    SZY  = Math.round((parent.pageHeight_2Y - parent.pageHeight_1Y) / parent.stepForDetailView);
    SZMX = Math.round((NZX - detailViewLeft) / parent.stepForDetailView);
    SZMY = Math.round((NZY - detailViewTop) / parent.stepForDetailView);
              
    DetailView.style.width  = parent.pageWidth_2X;
    DetailView.style.height = parent.pageHeight_2Y;	
	DetailViewLayer.style.left = detailViewLeft;          
    DetailViewLayer.style.top  = detailViewTop;                  
    
    IZ.width = parent.pageWidth_1X;
    IZ.height = parent.pageHeight_1Y;
    
	if (parent.detailRightPage) SetSrc("IZ", IPR.src);
    else SetSrc("IZ", IPL.src);

    IIDPZ = setTimeout("ZoomIn1()", 1);
}

function ZoomIn1() {
    if (IsImgSrcCompleteLoaded("IZ")) { 
		ShowLayer("DetailView");
        ShowLayer("DetailViewLayer");
        IIDPZ = setTimeout("ZoomIn2(1)", 1);
    } else {
		IIDPZ = setTimeout("ZoomIn1()", 2);
	}
}

function ZoomIn2(step) {
    if (step == parent.stepForDetailView) {
        DetailViewLayer.style.left = NZX;
        DetailViewLayer.style.top  = NZY;

        IZ.width  = parent.pageWidth_2X;
        IZ.height = parent.pageHeight_2Y;

        if (parent.detailRightPage && (Right_M_Img.width > 100)) {
            SetSrc("IZ", Right_M_Img.src);
        } else if (!parent.detailRightPage && (Left_M_Img.width > 100)) {
            SetSrc("IZ", Left_M_Img.src);
        }
      
        for (n = 1; n <= sliceNum; n++) {
             document.all("DetailViewSlice_" + n).style.top = parent.sliceImgHeight*(n-1);
             document.all("DetailViewSlice_" + n).style.left = 0;
             document.images("DetailViewSliceImg_" + n).src = parent.backgroundImgFile;
        }

        isRunning = false;
        SEP = SSP = false;
        okSliceImgs[currSliceNum] = false;
        document.images("DetailViewSliceImg_" + currSliceNum).src = parent.GetImgUrl(currDetailLeftPage, 1, currSliceNum);    
        IIDGet_1X = setTimeout(("ZoomIn3(0)"), 1);

        if (parseInt(DetailViewLayer.style.left) < 0) ShowImg(LeftAutoScrollArea, 0);
        if (parseInt(DetailViewLayer.style.top)  < 0) ShowImg(TopAutoScrollArea, 1);
        if (parseInt(DetailView.style.width) + parseInt(DetailViewLayer.style.left) > document.body.clientWidth) ShowImg(RightAutoScrollArea , 2);
        if (parseInt(DetailView.style.height) + parseInt(DetailViewLayer.style.top) > document.body.clientHeight) ShowImg(BottomAutoScrollArea , 3);
	} else {
        DetailViewLayer.style.left = detailViewLeft + SZMX*step;
        DetailViewLayer.style.top = detailViewTop + SZMY*step;
        IZ.width = parent.pageWidth_1X + SZX*step;
        IZ.height = parent.pageHeight_1Y + SZY*step;

        if (IZ.width > parent.pageWidth_2X) {
            IZ.width = parent.pageWidth_2X;
        }
        if (IZ.height > parent.pageHeight_2Y ) {
            IZ.width = parent.pageHeight_2Y;
        }

        step++;
        IIDPZ = setTimeout("ZoomIn2("+step+")", 1);
	}
}   
   
function ZoomIn3(step) {
    temp = currSliceNum + step;
    if ((temp > sliceNum) || ( temp < 0)) {
        if (step > 0) step = -step; 
        else step = 1 - step;
    }
    if (IsImgSrcCompleteLoaded("DetailViewSliceImg_" + temp)) {
        ShowLayer("DetailViewSlice_" + temp);
        if (SEP && SSP) {
            IIDPZ = setTimeout("ZoomIn4()", 1); 
            return;
        }
        if (step == 0) {
            for (n = 1; n <= sliceNum; n++) {
                 okSliceImgs[n] = false;
            }
            ShowLayer("DetailViewLayer");
            if (temp != sliceNum) 
				step = +1;
            else { 
                SEP = true;
                step = -1;
            }
        } else if (step > 0) {
            if (currSliceNum-step > 0) step = -step;
            else {
                SSP = true;
                if ((temp != sliceNum) || (temp != 1)) 
					step++;
                else {
					IIDPZ = setTimeout("ZoomIn4()", 1); 
					return;
                }
            }
        } else {
            if (currSliceNum-step < sliceNum) 
				step = 1 - step;
            else {
                if ((temp != 1) || (temp != sliceNum)) 
					step--;
                else {
					IIDPZ = setTimeout("ZoomIn4()", 1); 
					return;
                }
            }
        }
        temp = currSliceNum + step;
        if ((temp < 1) || (temp > sliceNum)) {
            IIDPZ = setTimeout("ZoomIn4()", 1); 
            return;
        }
        document.images("DetailViewSliceImg_" + temp).src = parent.GetImgUrl(currDetailLeftPage, 1, temp);
        IIDGet_1X = setTimeout(("ZoomIn3("+step+")"), 1);
	} else {
        IIDGet_1X = setTimeout(("ZoomIn3("+step+")"), 1);
    }
}


function ZoomIn4() {
	GoodsLayer.style.left = NZX;
    GoodsLayer.style.top  = NZY;
	GoodsLayer.style.width = DetailViewLayer.style.width;
	GoodsLayer.style.height = DetailViewLayer.style.height;	
	showLink();
}

function ZoomOut() {
    if (isRunning) return;

    isRunning = true;
    clearTimeout(IIDScrollX);
    clearTimeout(IIDScrollY);
    clearTimeout(IIDGet_1X);
    clearTimeout(IIDPZ);

	hideLink();

    parent.detailViewStatus = false;
    parent.frames['Frame_Menu'].ShowPageNumber();

    detailViewLeft = briefViewLeft + borderThickness;
    if (parent.detailRightPage) {
        detailViewLeft = detailViewLeft + parent.pageWidth_1X;
    }
    detailViewTop = briefViewTop + borderThickness;
    for (n = 1; n <= sliceNum; n++) {
         HideLayer("DetailViewSlice_" + n);
         SetSrc("DetailViewSliceImg_" + n, parent.backgroundImgFile);
    }

    SZMX = Math.round((NZX-detailViewLeft) / parent.stepForDetailView);
    SZMY = Math.round((NZY-detailViewTop) / parent.stepForDetailView);

    IIDPZ = setTimeout("ZoomOut1(parent.stepForDetailView)", 1);

    HideImg(TopAutoScrollArea, 1);
    HideImg(BottomAutoScrollArea, 3);
    HideImg(LeftAutoScrollArea, 0);
    HideImg(RightAutoScrollArea, 2);
}   

function ZoomOut1(arg_StepForDetailView) {
    if (arg_StepForDetailView == 1) {
        IZ.width = parent.pageWidth_1X;
        IZ.height = parent.pageHeight_1Y;
        HideLayer("DetailViewLayer");
        HideLayer("DetailView");
        isRunning = false;
    } else {
        DetailViewLayer.style.left = detailViewLeft + SZMX*arg_StepForDetailView;
        DetailViewLayer.style.top = detailViewTop + SZMY*arg_StepForDetailView;
        IZ.width = parent.pageWidth_1X + SZX*arg_StepForDetailView;
        IZ.height = parent.pageHeight_1Y + SZY*arg_StepForDetailView;
        arg_StepForDetailView--;
        IIDPZ = setTimeout("ZoomOut1("+arg_StepForDetailView+")", 1);
    }
}   

function Scrolling(arg_obj) {
    var ScrollImg = arg_obj.all.tags("IMG");
    
	if (ScrollImg[0].style.visibility == "hidden") return; 
    if (!(parent.detailViewStatus)) return;

    currScrollPointX = event.clientX;
    currScrollPointY = event.clientY;

    if ((currScrollPointX == beforeScrollPointX) && (currScrollPointY == beforeScrollPointY)) return;

	beforeScrollPointX = currScrollPointX;
	beforeScrollPointY = currScrollPointY;
    ZoomInScrollStop();

    var itmp = 0;
    switch (eval(arg_obj.id)) {
		case 0 : t = (event.clientX);
                 isScrolling = true;
                 IIDScrollX = setTimeout("ZoomInScrollRight("+t+")", 10);
                 return;               
        case 1 : t = (event.clientY);
                 isScrolling = true;
                 IIDScrollY = setTimeout("ZoomInScrollDown("+t+")", 10);
                 return;
        case 2 : t = (displayAreaWidth - event.clientX);
                 isScrolling = true;
                 IIDScrollX = setTimeout("ZoomInScrollLeft("+t+")", 10);
                 return;
        case 3 : t = (displayAreaHeight - event.clientY);
                 isScrolling = true;
                 IIDScrollY = setTimeout("ZoomInScrollUp("+t+")", 10);
                 return;
	}
}

function ZoomInScrollStop() {
    clearTimeout(IIDScrollX);
    clearTimeout(IIDScrollY);
}

function ZoomInScrollRight(arg_tempo) {
    if (isMouseDown) return;
    if (parseInt(DetailViewLayer.style.left) + parent.stepForScroll < 0) {
        detailViewLeft = parseInt(DetailViewLayer.style.left) + parent.stepForScroll;
        GoodsLayer.style.left = DetailViewLayer.style.left = detailViewLeft;
        NZX = detailViewLeft;

        IIDScrollY = setTimeout("ZoomInScrollRight("+arg_tempo+")", arg_tempo);
        ShowImg(LeftAutoScrollArea, 0);
        ShowImg(RightAutoScrollArea, 2);
    } else {
        GoodsLayer.style.left = DetailViewLayer.style.left = 0;
        ShowImg(RightAutoScrollArea, 2);
        setTimeout("HideImg(LeftAutoScrollArea, 0)", 10);
    }
}

function ZoomInScrollDown(arg_tempo) {
    if (isMouseDown) return;
    if (parseInt(DetailViewLayer.style.top) + parent.stepForScroll < 0) {
        detailViewTop = parseInt(DetailViewLayer.style.top) + parent.stepForScroll;
        GoodsLayer.style.top = DetailViewLayer.style.top = detailViewTop;
        NZY = detailViewTop;
        IIDScrollY = setTimeout("ZoomInScrollDown("+arg_tempo+")", arg_tempo);
        ShowImg(TopAutoScrollArea, 1);
        ShowImg(BottomAutoScrollArea, 3);
    } else {
        GoodsLayer.style.top = DetailViewLayer.style.top = 0;
        setTimeout("HideImg(TopAutoScrollArea, 1)", 10);
    }
}

function ZoomInScrollLeft(arg_tempo) {
    if (isMouseDown) return;
    if (displayAreaWidth - parseInt(DetailViewLayer.style.left) + parent.stepForScroll < parent.pageWidth_2X) {
        detailViewLeft = parseInt(DetailViewLayer.style.left) - parent.stepForScroll;
        GoodsLayer.style.left = DetailViewLayer.style.left = detailViewLeft;
        NZX = detailViewLeft;
        IIDScrollY = setTimeout("ZoomInScrollLeft("+arg_tempo+")", arg_tempo);
        ShowImg(LeftAutoScrollArea, 0);
        ShowImg(RightAutoScrollArea, 2);
    } else {
        GoodsLayer.style.left = DetailViewLayer.style.left = displayAreaWidth - parent.pageWidth_2X;
        ShowImg(LeftAutoScrollArea, 0);
        setTimeout("HideImg(RightAutoScrollArea, 2)", 10);
    }
}

function ZoomInScrollUp(arg_tempo) {
    if (isMouseDown) return;
    if (displayAreaHeight - parseInt(DetailViewLayer.style.top) + parent.stepForScroll < parent.pageHeight_2Y) {
        detailViewTop = parseInt(DetailViewLayer.style.top) - parent.stepForScroll;
        GoodsLayer.style.top = DetailViewLayer.style.top = detailViewTop;
        NZY = detailViewTop;
        IIDScrollY = setTimeout("ZoomInScrollUp("+arg_tempo+")", arg_tempo);
        ShowImg(TopAutoScrollArea, 1);
        ShowImg(BottomAutoScrollArea, 3);
    } else {
        GoodsLayer.style.top = DetailViewLayer.style.top = displayAreaHeight - parent.pageHeight_2Y;
        setTimeout("HideImg(BottomAutoScrollArea, 3)", 10);
    }
}

function ZoomInMouseWheel(arg_obj) {
	var ScrollImg = arg_obj.all.tags("IMG");
    
	if (ScrollImg[0].style.visibility == "hidden") return; 
    if (!(parent.detailViewStatus)) return;

	var viewerTop;
	var newPosition;
	switch (event.wheelDelta) {
		case 120 :
		case 240 :
		case 360 :
		case 480 :
		case 600 :
		case 720 :
		case 840 :
		case 960 :
		case 1080 :
		case 1200 :
		case 1320 : ZoomInScrollStop();
		            newPosition = parseInt(DetailViewLayer.style.top) + (parseInt(event.wheelDelta) / 2);
					if (newPosition < 0) {
						GoodsLayer.style.top = DetailViewLayer.style.top = newPosition;
						NZY = newPosition;
						ShowImg(TopAutoScrollArea, 1);
						ShowImg(BottomAutoScrollArea, 3);
					} else {
						GoodsLayer.style.top = DetailViewLayer.style.top = 0;
						NZY = 0;
						HideImg(TopAutoScrollArea, 1);
					}
					break;
		case -120 :
		case -240 :
		case -360 :
		case -480 :
		case -600 :
		case -720 :
		case -840 :
		case -960 :
		case -1080 :
		case -1200 :
		case -1320 : ZoomInScrollStop();
					 viewerTop = parseInt(displayAreaHeight) - parseInt(DetailView.style.height);
		             newPosition = parseInt(DetailViewLayer.style.top) + (parseInt(event.wheelDelta) / 2);
					 if (newPosition > viewerTop) {
						 GoodsLayer.style.top = DetailViewLayer.style.top = newPosition;
						 NZY = newPosition;
						 ShowImg(TopAutoScrollArea, 1);
						 ShowImg(BottomAutoScrollArea, 3);
					 } else {
						GoodsLayer.style.top = DetailViewLayer.style.top = viewerTop;
						NZY = viewerTop;
						HideImg(BottomAutoScrollArea, 3);
					}
					break;
	}
}

function MouseDown(arg_Obj) {
	if (parent.detailViewStatus == true) {
		arg_Obj.setCapture();

        isMouseDown = true;
        sPos_x     = event.screenX;
        sPos_y     = event.screenY;
        dragStartTop  = parseInt(DetailViewLayer.style.top);
        dragStartLeft = parseInt(DetailViewLayer.style.left);
        DetailViewLayer.style.cursor = "hand";
    }
}

function MouseUp(arg_Obj) { 
    if (parent.detailViewStatus == true) {
        if (isDragging) {
            sPos_x = 0;
            sPos_y = 0;
            DetailViewLayer.style.cursor = "default";
        }
        arg_Obj.releaseCapture();
    }
    isMouseDown = false;

    if (clickedGotoPage > 0) {  
        GotoPage(clickedGotoPage);
        return;
    }

    if (isDragging) { 
        isDragging = false;
    } else { 
		if (event.button == 2 || event.button == 3) {
			ZoomOut();
		}
    }
}

function ZoomInMove(arg_obj) {
    if (!(parent.detailViewStatus)) { return; }

    if (isMouseDown) {
        if ((Math.abs(sPos_x - event.x) > 5) || (Math.abs(sPos_y - event.y) > 5)) {
            isDragging = true;
            DetailViewLayer.style.cursor = "hand";
            Dragging();
            return;
        }
    }
}

function Dragging() {
	var MPos_x;
    var MPos_y;

    var ResultDragTop;
    var ResultDragLeft; 

    MPos_x = event.screenX;
    MPos_y = event.screenY;

    if (parent.detailViewStatus && isMouseDown) {
		ResultDragTop  = DetailViewLayer.style.top;
		ResultDragLeft = DetailViewLayer.style.left;
      
		if (((document.body.clientWidth - parent.pageWidth_2X) >= 0) && ((document.body.clientHeight - parent.pageHeight_2Y) >= 0)) {
			HideImg(TopAutoScrollArea   , 1);
			HideImg(BottomAutoScrollArea, 3);
			HideImg(LeftAutoScrollArea  , 0);
			HideImg(RightAutoScrollArea , 2);
		} else if (((document.body.clientWidth - parent.pageWidth_2X) >= 0 ) && ((document.body.clientHeight - parent.pageHeight_2Y) < 0 )) {
			ResultDragTop = dragStartTop + MPos_y - sPos_y;
			if (ResultDragTop > 0) {
				HideImg(TopAutoScrollArea, 1);
				ResultDragTop = 0;
			} else {
				ShowImg(TopAutoScrollArea, 1);
			}
			if (ResultDragTop < (document.body.clientHeight - parent.pageHeight_2Y)) {
				ResultDragTop = document.body.clientHeight - parent.pageHeight_2Y;
				HideImg(BottomAutoScrollArea, 3);
			} else {
				ShowImg(BottomAutoScrollArea, 3);
			}  
		} else if (((document.body.clientWidth - parent.pageWidth_2X) < 0) && ((document.body.clientHeight - parent.pageHeight_2Y) >= 0 )) {
			ResultDragLeft = dragStartLeft + MPos_x - sPos_x;
			if (ResultDragLeft > 0) {
				HideImg(LeftAutoScrollArea, 0);
				ResultDragLeft = 0;
			} else {
				ShowImg(LeftAutoScrollArea, 0);
			}
			if (ResultDragLeft < (document.body.clientWidth - parent.pageWidth_2X)) {
				HideImg(RightAutoScrollArea, 2);
				ResultDragLeft = document.body.clientWidth - parent.pageWidth_2X;
			} else {
				ShowImg(RightAutoScrollArea, 2);
			}
		} else {
			ResultDragTop  = dragStartTop  + MPos_y - sPos_y;
			ResultDragLeft = dragStartLeft + MPos_x - sPos_x;
			if (ResultDragTop >= 0) {
				ResultDragTop = 0;
				HideImg(TopAutoScrollArea, 1);
			} else {
				ShowImg(TopAutoScrollArea, 1);
			}
			if (ResultDragLeft >= 0) {
				ResultDragLeft = 0;
				HideImg(LeftAutoScrollArea, 0);
			} else {
				ShowImg(LeftAutoScrollArea, 0);
			}
			if (ResultDragTop <= (document.body.clientHeight - parent.pageHeight_2Y)) {
				ResultDragTop = document.body.clientHeight - parent.pageHeight_2Y;
				HideImg(BottomAutoScrollArea, 3);
			} else {
				ShowImg(BottomAutoScrollArea, 3);
			}
			if (ResultDragLeft <= (document.body.clientWidth - parent.pageWidth_2X)) {
				ResultDragLeft = document.body.clientWidth - parent.pageWidth_2X;
				HideImg(RightAutoScrollArea, 2);
			} else {
				ShowImg(RightAutoScrollArea, 2);
			}
		}      
		GoodsLayer.style.top = DetailViewLayer.style.top  = ResultDragTop;
		GoodsLayer.style.left = DetailViewLayer.style.left = ResultDragLeft;
	}
}

function ShowLayer(IN) {  
    document.all(IN).style.visibility = "visible";
}

function HideLayer(IN) {
    document.all(IN).style.visibility = "hidden";
}

function ShowImg(arg_Div, arg_Num) {
    var ScrollImg = arg_Div.all.tags("IMG");
    ScrollImg[0].style.visibility = "visible";
    arg_Div.style.zIndex = 1000 + arg_Num;
}

function HideImg(arg_Div, arg_Num) {
    var ScrollImg = arg_Div.all.tags("IMG");
    ScrollImg[0].style.visibility = "hidden";
    arg_Div.style.zIndex = arg_Num;
}

function SetSrc(IN, URL) {
    document.images(IN).src = URL;
}

function SetBuffer(IN, URL){
    IN.src = URL;
}

function SetImgLayer(o) {
    switch(o) {
		case 0 : okIPL = true;
                 break;
        case 1 : okIPR = true;
                 break;
        case 2 : okIPS = true;
                 break;
        case 3 : okIPS1 = true;
                 break;
                
        case -1 : okLeft_M_Img = true;
                  break;
        case -2 : okRight_M_Img = true;
                  break;
	}
    if (o > 100) okSliceImgs[o-100] = true;
}

function IsImgSrcCompleteLoaded(IN) {
    return document.images(IN).complete;
}

function IsBufferDone(IN) {
    return IN.complete;                                                                                
}

function IsImgLoadComplte() {
    isImgLoadComplete = true; 
}

function Resize() {
    InitScreenFrame();
}



function IB_pgini(obj){
	IB_loadtree(obj);
}

var IB_imageDir = "image/menu/";
var IB_listdata = null;
var IB_listpage = null;
function IB_loadtree(tarobj){ 
	tarobj.innerHTML = "";
	IB_listpage = parent.IB_listpage;
	for(var i=0;i<IB_listdata.length;i++){
		var source = "";
			source 	+= 	'<TABLE	BORDER		= "0"'
					+'	CELLSPACING	= "0"'
					+'	CELLPADDING	= "0">'
					+'<TR height="18">'
					+'<TD	WIDTH		= "18"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left">'
					+'<IMG	SRC		= "'+IB_imageDir+'default_E.gif"'
					+'	SUPERID		= "'+i+'"'
					+'	ONCLICK		= "treeiconclick(this)">'
					+'</TD>'
					+'<TD	WIDTH		= "16"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left">'
					+'<IMG	SRC		= "'+IB_imageDir+'icon_field.gif">'
					+'</TD>'
					+'<TD	NOWRAP		= "false"'
					+'	ONMOUSEOUT	= "textmouseout(this)"'
					+'	ONMOUSEOVER	= "textmouseover(this)"'
					+'	ONCLICK		= "textclick(this)"'
					+'	ONDBLCLICK	= "treeiconclick(this.parentElement.children(0).children(0))"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left"'
					+'	CLASS		= "normal"'
					+'	GOURL		= "'+IB_listpage[i]+'"'
					+'	ID		= ""'
					+'	STYLE		= "cursor:hand;">'
					+ IB_listdata[i]
					+'</TD>'
					+'</TR>'
					+'</TABLE>'
					+'<TABLE	BORDER		= "0"'
					+'	CELLSPACING	= "0"'
					+'	CELLPADDING	= "0"'
					+'	STYLE		="display:none">'
					+'<TR>'
					+'<TD	WIDTH		= "18"'
					+'	VALIGN		= "middle"><img src="'+IB_imageDir+'null.gif">'
					+'</TD>'
					+'<TD	ID		= "SUB'+i+'"'
					+'	VALIGN		= "middle"'
					+'	CLASS		= "normal"'
					+'	ALIGN		= "left">'
					+'</TD>'
					+'</TR>'
					+'</TABLE>'; 

			tarobj.insertAdjacentHTML("beforeend",source);
	}
}

function IB_opentree(str,obj){
	for(var i=0;i<IB_listdata.length;i++){
		var source = "";
		var listdataArray = IB_listdata[i].split("|");
		if(listdataArray[0] == str){
			if(listdataArray[1]=="0"){
				menudataTreeSrc = IB_imageDir+"default_E.gif";
			}
			else{
				menudataTreeSrc = IB_imageDir+"cross_E.gif";
			}

			source 	+= 	'<TABLE	BORDER		= "0"'
					+'	CELLSPACING	= "0"'
					+'	CELLPADDING	= "0">'
					+'<TR height="18">'
					+'<TD	WIDTH		= "18"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left">'
					+'<IMG	SRC		= "'+menudataTreeSrc+'"'
					+'	SUPERID		= "'+i+'"'
					+'	ONCLICK		= "treeiconclick(this)">'
					+'</TD>'
					+'<TD	WIDTH		= "16"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left">'
					+'<IMG	SRC		= "'+IB_imageDir+listdataArray[3]+'">'
					+'</TD>'
					+'<TD	NOWRAP		= "false"'
					+'	ONMOUSEOUT	= "textmouseout(this)"'
					+'	ONMOUSEOVER	= "textmouseover(this)"'
					+'	ONCLICK		= "textclick(this)"'
					+'	ONDBLCLICK	= "treeiconclick(this.parentElement.children(0).children(0))"'
					+'	VALIGN		= "middle"'
					+'	ALIGN		= "left"'
					+'	CLASS		= "normal"'
					+'	GOURL		= "'+listdataArray[4]+'"'
					+'	ID		= ""'
					+'	STYLE		= "cursor:hand;">'
					+ listdataArray[2]
					+'</TD>'
					+'</TR>'
					+'</TABLE>'
					+'<TABLE	BORDER		= "0"'
					+'	CELLSPACING	= "0"'
					+'	CELLPADDING	= "0"'
					+'	STYLE		="display:none">'
					+'<TR>'
					+'<TD	WIDTH		= "18"'
					+'	VALIGN		= "middle"><img src="'+IB_imageDir+'null.gif">'
					+'</TD>'
					+'<TD	ID		= "SUB'+i+'"'
					+'	VALIGN		= "middle"'
					+'	CLASS		= "normal"'
					+'	ALIGN		= "left">'
					+'</TD>'
					+'</TR>'
					+'</TABLE>';
			var tmpobject = obj.parentElement;
			while(tmpobject.id.indexOf("IB_tree") == -1){
				tmpobject = tmpobject.parentElement;	
			}
			eval("var obj=tmpobject.all.SUB"+listdataArray[0]+";");
			if(obj.children.length > 0){
				var temp = obj.children(obj.children.length-2).children(0).children(0).children(0).children(0);
				temp.src = temp.src.substring(0,temp.src.length-5)+"C.gif";
				
				obj.children(obj.children.length-1).children(0).children(0).children(0).background = IB_imageDir+"vline.gif";
			}
			obj.insertAdjacentHTML("beforeend",source);	
		}
	}
}

var clickObject = null;
function treeiconclick(obj){
	var tmpidx = getchildrenIndex(obj.parentElement.parentElement.parentElement.parentElement.parentElement,obj.parentElement.parentElement.parentElement.parentElement);
	var tmpobj = obj.parentElement.parentElement.parentElement.parentElement.parentElement.children(tmpidx+1);
	
	if(obj.src.substring(obj.src.length-11) == "cross_C.gif"){
		obj.src = IB_imageDir+"minus_C.gif";
		if(!tmpobj.children(0).children(0).children(1).children(0)){
			IB_opentree(obj.SUPERID,obj);
		}
		tmpobj.style.display = "";
	}
	else if(obj.src.substring(obj.src.length-11) == "cross_E.gif"){
		obj.src = IB_imageDir+"minus_E.gif";
		if(!tmpobj.children(0).children(0).children(1).children(0)){
			IB_opentree(obj.SUPERID,obj);
		}
		tmpobj.style.display = "";
	}
	else if(obj.src.substring(obj.src.length-11) == "minus_C.gif"){
		obj.src = IB_imageDir+"cross_C.gif";
		tmpobj.style.display = "none";
	}
	else if(obj.src.substring(obj.src.length-11) == "minus_E.gif"){
		obj.src = IB_imageDir+"cross_E.gif";
		tmpobj.style.display = "none";
	}
	menuwindow.style.pixelWidth = IB_treearea.offsetWidth*1+22+10;
	menuwindow.style.pixelWidth = IB_treearea.offsetWidth*1+22+10;
}

function getchildrenIndex(sobj,obj){
	var idx = -1;
	for(var i=0;i<sobj.children.length;i++){
		if(sobj.children(i) == obj){
			idx = i;
			break;
		}
	}
	return idx;
}

function textclick(obj){
	if(clickObject != null){
		if(clickObject != obj){
			clickObject.className = "normal";
			clickObject = null;
			clickObject = obj;
			clickObject.className = "click";
		}
	}
	else{
		clickObject = obj;
		clickObject.className = "click";
	}
	if(obj.GOURL.length > 0){
		GotoPage(eval(obj.GOURL));
	}
}

function textmouseover(obj){
	if(clickObject != obj){
		obj.className = "mouseon";
	}
}

function textmouseout(obj){
	if(clickObject != obj){
		obj.className = "normal";
	}
}

var autoplay = null;
var isAutoplay = false;
function startAutoplay(autoInterval) { 
	autoplay = window.setInterval("autoAction()", autoInterval);
}
function autoplaystop() {
	window.clearInterval(autoplay);
	autoplay = null;
	isAutoplay = false;
}

function autoAction() { 
	if (!parent.detailViewStatus && !isRunning) {
		isAutoplay = true;
		if (parent.briefLeftPage >= parent.lastPage-1) {
			GotoPage(parent.firstPage);
		} else {
			LeafToNext();
		}
	}
}

var linkData = null;
var linkImgPath = "./image/link_color/";
var linkImgExt = ".gif";
var source = "";
function showLink() {
	if (parent.userLinkData) {
		linkData = parent.userLinkData; 
		var linkDataArray = new Array();
		
		for(var i=0; i<linkData.length; i++){ 
			linkDataArray = linkData[i].split(" ");			
			if (parseInt(linkDataArray[0]) == parseInt(currDetailLeftPage)) {
				createLink(linkDataArray);
			}
		}
		GoodsLayer.innerHTML = source;
		ShowLayer("GoodsLayer");
	}
}

function createLink(linkDataArray) {
	source += '<div '
			+ 'style="position:absolute; '
			+ 'left:' + linkDataArray[2] + '; '
			+ 'top:' + linkDataArray[3] + '; '
			+ 'z-index:250; '
			+ 'visibility:visible;">'
			+ '    <img '
			+ '    src="' + linkImgPath + linkDataArray[7] + linkImgExt + '" '
			+ '    style="width:' + linkDataArray[4] + '; '
			+ '    height:' + linkDataArray[5] + '; '
			+ '    cursor:hand; '
			+ '    filter:alpha(opacity=10); '
			+ '    visibility:visible;" '
			+ '    GALLERYIMG="no" '
			+ '	   ALT="' + getMessage(linkDataArray[1], linkDataArray[6]) + '" '
			+ '    OnMouseOver="this.style.filter=\'alpha(opacity=30)\'" '
			+ '    OnMouseOut="this.style.filter=\'alpha(opacity=10)\'" '
			+ '    OnClick="GotoLink(\'' + linkDataArray[1] + '\' , \'' + linkDataArray[6] + '\')">'
			+ '</div>';
}

function getMessage(type, message) {
	var msg = "";
	if (type == "L") {
		msg = "Go to Web : " + message;
	} else if (type == "G") {
		msg = "Go to Page : " + message;
	} else if (type == "M") {
		msg = "Go to Media : " + message;
	}
	return msg;
}

function hideLink() {
	source = "";
	HideLayer("GoodsLayer");
	GoodsLayer.innerHTML = "";
}

function GotoLink(type, data) {
	var id = "LinkWindow";
	//var id = Math.round(Math.random()*(1000000 - 1) + 1);
	if (type == "L") {
		window.open(data, id, "left=0, top=0, width=724, height=500, directories=yes, status=yes, location=yes, menubar=yes, scrollbars=yes, resizable=yes, fullscreen=no");
	} else if (type == "G") {
		GotoPage(parseInt(data));
	} else if (type == "M") {
		var position = parseMyUrl(self.location.href);
		var url = position + parent.soundPage + "?bgm=" + parent.soundDir + data;
		window.open(url, id, "left=0, top=0, width=340, height=270, directories=no, status=no, location=no, menubar=no, scrollbars=no, resizable=yes, fullscreen=no");
	}
}

function parseMyUrl(currentUrl) {
	var tokens = currentUrl.split("body.htm");
	return tokens[0];
}