/**
 * @author Kim Dae Il.
 *
 * Copyright by Softmagic. All rights reserved.
 */
var pdfPage;
var nowPageNumber;

var isLogo = true;
var isBookTitle = true;
var isAutoCount = true;
var isAutoplay = true;
var isgoFirst = true;
var isgoPre = true;
var isgoNext = true;
var isgoLast = true;
var isPageNumber = true;
var isMoveTargetNum = true;
var isGotoButton = true;
var isTOCButton = true;
var iseMail = true;
var isPDF = true;
var isBookMark = true;
var isPrint = true;
var isSoundArea = true;
var isPageSound = true;
var isMin = true;
var isClose = true;

var url;
var img;

var active = "true";

function ResetField(obj) {
	obj.value = "";
}

function initToolBar() {
	if (navigator.platform == "MacPPC") {
		if (typeof parent.frames['Frame_Menu'].document.body != "undefined") {
			parent.frames['Frame_Menu'].document.body.onload = new Function("SetSkin()");
		}
		else {
			setTimeout("initToolBar()", 100);
		}
	}
	else {
		SetSkin();
	}
}

function SetSkin() {
	CheckID();
	ShowLogo();
	ShowBookTitle();
	SetMoveButton();
	SetGotoButton();
	ShowPageNumber();
	SetTOCButton();
	SetMail();
	SetPDF();
	SetBookMark();
	SetPrint();
	SetSound();
	SetMin();
	SetClose();

	parent.menuFrameLoaded = true;
}

function CheckID() {
	if (typeof parent.frames['Frame_Menu'].Logo == "undefined")	{
		isLogo = false;
	}
	if (typeof parent.frames['Frame_Menu'].BookTitle == "undefined") {
		isBookTitle = false;
	}
	if (typeof parent.frames['Frame_Menu'].AutoCount == "undefined") {
		isAutoCount = false;
	}
	if (typeof parent.frames['Frame_Menu'].Autoplay == "undefined") {
		isAutoplay = false;
	}
	if (typeof parent.frames['Frame_Menu'].goFirst == "undefined") {
		isgoFirst = false;
	}
	if (typeof parent.frames['Frame_Menu'].goPre == "undefined") {
		isgoPre = false;
	}
	if (typeof parent.frames['Frame_Menu'].goNext == "undefined") {
		isgoNext = false;
	}
	if (typeof parent.frames['Frame_Menu'].goLast == "undefined") {
		isgoLast = false;
	}
	if (typeof parent.frames['Frame_Menu'].PageNumber == "undefined") {
		isPageNumber = false;
	}
	if (typeof parent.frames['Frame_Menu'].MoveTargetNum == "undefined") {
		isMoveTargetNum = false;
	}
	if (typeof parent.frames['Frame_Menu'].GotoButton == "undefined") {
		isGotoButton = false;
	}
	if (typeof parent.frames['Frame_Menu'].TOCButton == "undefined") {
		isTOCButton = false;
	}
	if (typeof parent.frames['Frame_Menu'].eMail == "undefined") {
		iseMail = false;
	}
	if (typeof parent.frames['Frame_Menu'].PDF == "undefined") {
		isPDF = false;
	}
	if (typeof parent.frames['Frame_Menu'].BookMark == "undefined") {
		isBookMark = false;
	}
	if (typeof parent.frames['Frame_Menu'].Print == "undefined") {
		isPrint = false;
	}
	if (typeof parent.frames['Frame_Menu'].SoundArea == "undefined") {
		isSoundArea = false;
	}
	if (typeof parent.frames['Frame_Menu'].PageSound == "undefined") {
		isPageSound = false;
	}
	if (typeof parent.frames['Frame_Menu'].Min == "undefined") {
		isMin = false;
	}
	if (typeof parent.frames['Frame_Menu'].Close == "undefined") {
		isClose = false;
	}
}

function newOpen(url) {
	window.open(url, "new", "top=0, left=0, toolbar=yes, status=yes, menubar=yes, scrollbar=yes, resizable=yes");
}

function logoOpen(url) {
	window.open(url, "new", "top=0, left=0, toolbar=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes");
}

function parentClose() {
	parent.window.close();
}

function ShowLogo() {
	if (isLogo) {
		var url = parent.logoUrl;

		if (!parent.isSkinSelection) {
			var img = parent.logoImg;
			if (img) {
				parent.frames['Frame_Menu'].Logo.src = "image/" + img;
			}
		}

		if (url)	{
			parent.frames['Frame_Menu'].Logo.style.cursor = "hand";
			parent.frames['Frame_Menu'].Logo.onclick = new Function("logoOpen('" + url + "')");
		}
		else {
			parent.frames['Frame_Menu'].Logo.style.cursor = "";
		}
	}
}

function ShowBookTitle() {
	if (isBookTitle) {
		if (parent.bookTitle != "") {
			if (navigator.platform == "MacPPC") {
				parent.frames['Frame_Menu'].BookTitle.style.width = 170;
			}
			else {
				parent.frames['Frame_Menu'].BookTitle.style.width = 170;
			}
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].BookTitle.innerHTML = " " + parent.bookTitle + " ";
			}
		}
	}
}

function SetMoveButton() {
	if (isgoFirst) {
		parent.frames['Frame_Menu'].goFirst.style.cursor = "hand";
		parent.frames['Frame_Menu'].goFirst.onclick		= new Function("LeafFirst()");
	}

	if (isgoPre) {
		parent.frames['Frame_Menu'].goPre.style.cursor = "hand";
		parent.frames['Frame_Menu'].goPre.onclick		= new Function("LeafPrev()");
	}

	if (isgoNext) {
		parent.frames['Frame_Menu'].goNext.style.cursor = "hand";
		parent.frames['Frame_Menu'].goNext.onclick		= new Function("LeafNext()");
	}

	if (isgoLast) {
		parent.frames['Frame_Menu'].goLast.style.cursor = "hand";
		parent.frames['Frame_Menu'].goLast.onclick		= new Function("LeafLast()");
	}
}

function SetGotoButton() {
	if (isMoveTargetNum && isGotoButton) {
		parent.frames['Frame_Menu'].MoveTargetNum.onKeypress = new Function("CheckEnterKey(parseInt(parent.frames['Frame_Menu'].MoveTargetNum.value))");
		parent.frames['Frame_Menu'].MoveTargetNum.onclick = new Function("ResetField(this)");

		parent.frames['Frame_Menu'].GotoButton.style.cursor = "hand";
		parent.frames['Frame_Menu'].GotoButton.onclick = new Function("GotoPage(parseInt(parent.frames['Frame_Menu'].MoveTargetNum.value))");
	}	
}

function ShowPageNumber() {
	if (isPageNumber) {
		if (navigator.platform == "MacPPC") {
			parent.frames['Frame_Menu'].PageNumber.style.width = 60;
		}
	    parent.frames['Frame_Menu'].PageNumber.innerHTML = "<b>" + eval(parent.briefLeftPage - parent.startRight) + "/" + eval(parent.lastPage - parent.startRight) + "</b>";
	}

	if (isMoveTargetNum) {
		parent.frames['Frame_Menu'].MoveTargetNum.value = eval(parent.briefLeftPage - parent.startRight);
	}

	nowPageNumber = parent.briefLeftPage - parent.startRight;

    if (parent.detailViewStatus) {
        switch (parent.detailRightPage) {
			case 0 : PageNumber.innerHTML = "";
			case 1 : PageNumber.innerHTML = "";				          
		}
    }
}

function SetTOCButton() {
	if (isTOCButton) {
		parent.frames['Frame_Menu'].TOCButton.style.cursor = "hand";
		parent.frames['Frame_Menu'].TOCButton.onmouseup = new Function("menumousedown(this)");
	}
}

function SetMail() {
	if (iseMail) {
		if (parent.mailUrl) {
			parent.frames['Frame_Menu'].eMail.style.cursor = "hand";
			parent.frames['Frame_Menu'].eMail.onclick = new Function("sendEmail()");
		}
		else {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].eMail.style.visibility = "hidden";
				parent.frames['Frame_Menu'].eMail.style.width = 0;
			}
		}
	}
}

function sendEmail() {
	location.href = "mailto:" + parent.mailUrl;
}

function SetPDF() {
	if (isPDF) {
		if (parent.usePDF) {
			parent.frames['Frame_Menu'].PDF.style.cursor = "hand";
			if (parent.multiplePDF) {
				pdffile = parent.PDFName;
				parent.frames['Frame_Menu'].PDF.onclick = new Function("showPDF('" + pdffile + "')");
			}
			else {
				parent.frames['Frame_Menu'].PDF.onclick = new Function("checkPDF()");
			}			
		}
		else {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].PDF.style.visibility = "hidden";
				parent.frames['Frame_Menu'].PDF.style.width = 0;
			}
		}
	}
}

function SetBookMark() {
	if (isBookMark) {
		parent.frames['Frame_Menu'].BookMark.style.cursor = "hand";
		parent.frames['Frame_Menu'].BookMark.onclick = new Function("showBookMark()");
	}
}

function checkPDF() {
	pdfPage = parent.briefLeftPage - parent.startRight;
	window.open("checkpdf.html", "checkPDF", "width=360, height=130,resizable=no,scrollbars=no,status=false,menubar=no'");
}

function showPDF(pdffile) {
	if (navigator.platform == "MacPPC" && navigator.userAgent.indexOf("5.2") != -1) {
		location.href = "pdf/" + pdffile;
	}
	else {
		newOpen("pdf/" + pdffile);
	}
}

function SetPrint() {
	if (isPrint) {
		agent = navigator.platform;
		if (agent != "MacPPC") {
			parent.frames['Frame_Menu'].Print.style.cursor = "hand";
			parent.frames['Frame_Menu'].Print.onclick = new Function("print()");
		}
		else {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].Print.style.visibility = "hidden";
				parent.frames['Frame_Menu'].Print.style.width = 0;
			}
		}
	}
}

function SetSound() {	
	if (parent.soundMode == false) {
		parent.frames['Frame_Screen'].isPlaySound = false;
		if (isSoundArea) {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].SoundArea.style.visibility = "hidden";
				parent.frames['Frame_Menu'].SoundArea.style.width = 0;
			}
		}
		if (isPageSound) {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].PageSound.style.visibility = "hidden";
				parent.frames['Frame_Menu'].PageSound.style.width = 0;
			}
		}
	} else {
		SetSoundArea();
	}

	SetAutoPlayArea();
}


function SetAutoPlayArea() {
	if (isAutoplay) {
		parent.frames['Frame_Menu'].Autoplay.style.cursor = "hand";
		parent.frames['Frame_Menu'].Autoplay.onclick = new Function("autoplay(this)");
	}
}

function PreventAutoPlayArea() {
	if (isAutoplay) {
		parent.frames['Frame_Menu'].Autoplay.style.cursor = "default";
		parent.frames['Frame_Menu'].Autoplay.onclick = "";
	}
}

function SetSoundArea() {
	if (isSoundArea) {
		parent.frames['Frame_Menu'].SoundArea.style.cursor = "hand";
		if (parent.isBGM) {
			if (!parent.isSkinSelection) {
				parent.frames['Frame_Menu'].PageSound.style.visibility = "hidden";
				parent.frames['Frame_Menu'].PageSound.style.width = 0;
			}
			parent.frames['Frame_Menu'].SoundArea.onclick = new Function("playOrStop(this)");
			setBGMSrc();
			setBGMVolume(0);
		} else {
			parent.frames['Frame_Menu'].PageSound.style.cursor = "hand";
			parent.frames['Frame_Menu'].SoundArea.onclick = new Function("isPlaySound(this)");
			parent.frames['Frame_Menu'].PageSound.onclick = new Function("isRelayPlay(this)");
		}
	}
}

function playOrStop(obj) {
	var agent = navigator.platform;
	if (active == "true") {
		active = "false";
		obj.src = obj.offsrc;
		if (agent == "MacPPC") {
			BGMPlayer.src = "";
		}
		else {
			setBGMVolume(-10000);
		}	
	} 
	else {
		active = "true";
		obj.src = obj.onsrc;
		if (agent == "MacPPC") {
			setBGMSrc();
		}
		else {
			setBGMVolume(0);
		}
	}
}

function setBGMSrc() {
	BGMPlayer.src = parent.soundDir + parent.bgmSrc;
}

function setBGMVolume(number) {
	if (number < -10000) {
		number = -10000;
	} else if (number > 0) {
		number = 0;
	}
	BGMPlayer.volume = number;
}

function SetMin() {
	if (isMin) {
		agent = navigator.platform;
		if (agent != "MacPPC") {
			parent.frames['Frame_Menu'].Min.style.cursor = "hand";
			parent.frames['Frame_Menu'].Min.onclick = new Function("MinSize.Click()");
		}
		else {
			if (parent.isSkinSelection) {
				parent.frames['Frame_Menu'].Min.style.visibility = "hidden";
				parent.frames['Frame_Menu'].Min.style.width = 0;
			}
		}
	}
}

function SetClose() {
	if (isClose) {
		parent.frames['Frame_Menu'].Close.style.cursor = "hand";
		parent.frames['Frame_Menu'].Close.onclick = new Function("parentClose()");
	}
}

function MouseMove() {
    if (parent.menuFrameLoaded != true) { 
        parent.frames['Frame_Screen'].ZoomInScrollStop();
    }
}

function CheckEnterKey(arg_PageNo) {
    if (window.event.keyCode == 13)
		GotoPage(arg_PageNo);
}

var id;
function LeafNext() {
    if (parent.frames['Frame_Screen'].isRunning == false) 
        id = setTimeout("parent.frames['Frame_Screen'].LeafToNext()", 10);
	
}

function LeafPrev() {
    if (parent.frames['Frame_Screen'].isRunning == false) 
        id = setTimeout("parent.frames['Frame_Screen'].LeafToPrev()", 10);
	
}

function LeafFirst() {
	if (parent.frames['Frame_Screen'].isRunning == false)
		id = setTimeout("GotoPage(parent.firstPage - parent.startRight)", 10);
}

function LeafLast() {
	if (parent.frames['Frame_Screen'].isRunning == false)
		id = setTimeout("GotoPage(parent.lastPage - parent.startRight)", 10);
}

function GotoPage(page) {
	if (parent.frames['Frame_Screen'].isRunning == true) {
		return;
	}

	if (parent.detailViewStatus) {
		parent.detailGotoPage = page + parent.startRight;
	}
	else {
		parent.detailGotoPage = -1;
	}

	var arg_Page = parseInt(page) + parseInt(parent.startRight);
	if (((arg_Page + parent.firstPage)%2) != 0) {
		--arg_Page;
	}

    if ((arg_Page >= parent.firstPage) && (arg_Page <= parent.lastPage)) {
		if (arg_Page > parent.briefLeftPage) {
			parent.briefLeftPage = arg_Page - 2;
			LeafNext();
		} else if (arg_Page < parent.briefLeftPage) {
			parent.briefLeftPage = arg_Page + 2;
			LeafPrev();
		} else if (arg_Page == parent.briefLeftPage) {
		}
		parent.frames['Frame_Screen'].focus();
    } else {
        alert("The page is out of range : [ " + parent.firstPage + " - " + parent.lastPage + " ]" );
	}
}

var page1, page2;
function print() { 
	page1 = top.parent.GetImgUrl(top.parent.briefLeftPage, 0, 0);             
	page2 = top.parent.GetImgUrl(top.parent.briefLeftPage + 1, 0, 0);  
	window.open("pageprint.htm", "mac_eBook", "left=0, top=0, width=800, height=600, directories=no, status=no, location=no, menubar=no, scrollbars=no, resizable=yes, fullscreen=no");
}

function PrintMouseClick() {
    if (parent.detailViewStatus) {
        PreparePrnWin();
    } else {
        alert("Print 기능은 현재 버전에서 지원하지 않습니다.");
    }
}

var softmagic_Url = "http://www.softmagic.com";
function GotoUrl(arg_Url) {
	window.open(arg_Url, "Softmagic", "left=0, top=0, width=800, height=600, directories=yes, status=yes, location=yes, menubar=yes, scrollbars=yes, resizable=yes, fullscreen=no");
}

var selectedmenu = null;
	function menumousedown(obj){
		var tmpobj = parent.frames['Frame_Screen'].document.all;
		isprocessing = true;
		////if(tmpobj.arrowimage.style.visibility == "visible"){
		////	tmpobj.arrowimage.style.visibility = "hidden";
		////}
		if(selectedmenu){
//			selectedmenu.src = selectedmenu.offsrc;
			eval("var tmpobj2 = tmpobj.DIV"+selectedmenu.id+";");
			tmpobj2.style.visibility = "hidden";
			if(selectedmenu != obj){
//				selectedmenu.src = selectedmenu.offsrc;
				if(obj.id == "TOCButton"){
					parent.frames['Frame_Screen'].IB_listdata = null;
					parent.frames['Frame_Screen'].IB_listdata = parent.IB_listdata;
					if(parent.frames['Frame_Screen'].IB_treearea.children.length == 0){
						parent.frames['Frame_Screen'].IB_pgini(parent.frames['Frame_Screen'].IB_treearea);
					}
				}
				eval("var tmpobj2 = tmpobj.DIV"+selectedmenu.id+";");
				tmpobj2.style.visibility = "hidden";
				selectedmenu = obj;
				eval("var tmpobj2 = tmpobj.DIV"+selectedmenu.id+";");
				tmpobj.menuwindow.style.pixelWidth = tmpobj2.offsetWidth*1+22;
				tmpobj2.style.visibility = "visible";
//				selectedmenu.src = selectedmenu.onsrc;
				if(obj.id == "search"){
					tmpobj.keyword.focus();	
				}
				isprocessing = false;
			}
			else{
				selectedmenu = obj;
//				selectedmenu.src = selectedmenu.offsrc;
				oInterval4 = window.setInterval("menuhideaction()",50);
			}
			isprocessing = false;
			parent.frames['Frame_Screen'].ShowBookMark();
		}
		else{
			if(obj.id == "TOCButton"){
				parent.frames['Frame_Screen'].HideBookMark();
				parent.frames['Frame_Screen'].IB_listdata = null;
				parent.frames['Frame_Screen'].IB_listdata = parent.IB_listdata;
				if(parent.frames['Frame_Screen'].IB_treearea.children.length == 0){
					parent.frames['Frame_Screen'].IB_pgini(parent.frames['Frame_Screen'].IB_treearea);
				}
			}
			selectedmenu = obj;
//			selectedmenu.src = selectedmenu.onsrc;
			oInterval3 = window.setInterval("menuviewaction()",50);
		}
	}
	
	var nowstep = 0;
	function menuviewaction(){ 
		var tmpobj = parent.frames['Frame_Screen'].document.all; 
		tmpobj.menuwindow.style.visibility = "visible";
		eval("var tmpobj2 = tmpobj.DIV"+selectedmenu.id+";");
		nowstep++;
		var step = 5;  
		if(nowstep > step){ 
			tmpobj2.style.visibility = "visible"; 
			nowstep = 0;
			window.clearInterval(oInterval3);
			isprocessing = false;
		}
		else{
			tmpobj.menuwindow.style.pixelWidth = Math.round((tmpobj2.offsetWidth*1+24)*nowstep/step);
		}
	}

	function menuhideaction(){
		var tmpobj = parent.frames['Frame_Screen'].document.all;
		eval("var tmpobj2 = tmpobj.DIV"+selectedmenu.id+";");
		tmpobj2.style.visibility = "hidden";
		nowstep++;
		var step = 5;
		if(nowstep > step){
			nowstep = 0;
			selectedmenu = null;
			window.clearInterval(oInterval4);
			tmpobj.menuwindow.style.visibility = "hidden";
			isprocessing = false;
		}
		else{
			tmpobj.menuwindow.style.pixelWidth = 24 + Math.round((tmpobj2.offsetWidth*1)*(step-nowstep)/step);
		}
	}

function autoplay(btn) {
	if (parent.frames['Frame_Screen'].isAutoplay == false) { 
		btn.src = btn.onsrc;
		parent.frames['Frame_Screen'].startAutoplay(parseInt(parent.frames['Frame_Menu'].AutoCount.value)*1000);
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].autoplaystop();
	}
}

function isPlaySound(btn) {
	var agent = navigator.platform;
	if (parent.frames['Frame_Screen'].isPlaySound == false) {
		btn.src = btn.onsrc;
		parent.frames['Frame_Screen'].isPlaySound = true;
		if (agent == "MacPPC") {
			parent.frames['Frame_Screen'].soundOnForMac();
		}
		else {
			parent.frames['Frame_Screen'].soundOn();
		}		
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].isPlaySound = false;
		if (agent == "MacPPC") {			
			SoundPlayerForMac.src = "";
		}
		else {
			parent.frames['Frame_Screen'].SoundPlayer.Stop();
		}
	}
}

function isRelayPlay(btn) {
	if (parent.frames['Frame_Screen'].relayPlay == false) { 
		btn.src = btn.onsrc;
		parent.frames['Frame_Screen'].relayPlay = true;
		parent.frames['Frame_Screen'].goRelayPlay();
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].relayPlay = false;
		parent.frames['Frame_Screen'].clearSound();
	}
}

function showBookMark() {
	if (parent.showBookMark) {
		parent.showBookMark = false;
		parent.frames['Frame_Screen'].HideBookMarkButton();
	}
	else {
		parent.showBookMark = true;
		parent.frames['Frame_Screen'].ShowBookMark();
	}
}

document.write('<object id="MinSize" type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">	');
document.write('    <param name="Command" value="minimize">																	');
document.write('</object>																									');