/**
 * @author Song Ji-Hoon.
 *
 * Copyright by Softmagic. All rights reserved.
 */
function ResetField(obj) {
	obj.value = "";
}

function InitMenuFrame() {
	if (parent.soundMode == false) {
		SetAutoPlayArea();
		parent.frames['Frame_Screen'].isPlaySound = false;
	} else {
		SetSoundArea();
	}
	SetMail();
	ShowLogo();
    ShowPageNumber();
    ShowBookTitle();
    parent.menuFrameLoaded = true;
}

function SetAutoPlayArea() {
	var source = '<table border="0" cellspacing="0" cellpadding="0">'
			+ '<tr>'
			+ '<td>'
			+ '<select name="AutoCount" size=1>'
			+ '<option value="3" selected>3sec'
		+ '<option value="5">5sec'
		+ '<option value="10">10sec'
		+ '<option value="20">20sec'
		+ '<option value="30">30sec'
		+ '<option value="60">60sec'
            +      '</select></td>' 
            +    '<td width="35" height="32" rowspan="2" valign="bottom"><table width="33" border="0" cellspacing="0" cellpadding="0">' 
            +        '<tr>' 
            +          '<td><IMG SRC="image/skin-1_30.jpg" offsrc="image/skin-1_30.jpg" onsrc="image/skin-1_30-S.jpg" WIDTH=33 HEIGHT=32 ALT="Auto" style="cursor:hand" onClick="autoplay(this)"></td>' 
            +        '</tr>'
            +      '</table>'
			+ '</td>'
			+ '</tr>'
			+ '</table>';
	AutoPlayArea.innerHTML = source; 
}

function SetSoundArea() {
	var source = '';
	if (parent.isBGM) {
		SetAutoPlayArea();
		setBGMSrc();
		setBGMVolume(0);
		source += '<table width="84" border="0" cellspacing="0" cellpadding="0">'
			+ '<tr>'
			+ '<td colspan="2" width="41" height="39">'
			+ '<IMG SRC="image/skin-1_14.jpg" offsrc="image/skin-1_14-S.jpg" onsrc="image/skin-1_14.jpg" active="true"  WIDTH=41 HEIGHT=39 ALT="" style="cursor:hand" onClick="playOrStop(this)">'
			+ '</td>'
			+ '</tr>'
			+ '<tr>'
			+ '<td>'
			+ '<IMG SRC="image/skin-1_43.jpg" WIDTH=41 HEIGHT=4 ALT="">'
			+ '</td>'
			+ '<td>'
			+ '<IMG SRC="image/skin-1_43.jpg" WIDTH=43 HEIGHT=4 ALT="">'
			+ '</td>'
			+ '</tr>'
			+ '</table>';
		SoundArea.innerHTML = source;
	} else {
		source += '<table width="84" border="0" cellspacing="0" cellpadding="0">'
		+ '<tr>'
		+ '<td width="41" height="39">'
		+ '<IMG SRC="image/skin-1_14.jpg" offsrc="image/skin-1_14-S.jpg" onsrc="image/skin-1_14.jpg" active="true" WIDTH=41 HEIGHT=39 ALT="" style="cursor:hand" onClick="isPlaySound(this)">'
		+ '</td>'
		+ '<td width="43">'
		+ '<IMG SRC="image/skin-1_15_S.jpg" offsrc="image/skin-1_15.jpg" onsrc="image/skin-1_15_S.jpg" WIDTH=43 HEIGHT=39 ALT="" style="cursor:hand" onClick="isRelayPlay(this)">'
		+ '</td>'
		+ '</tr>'
		+ '<tr>'
		+ '<td>'
		+ '<IMG SRC="image/skin-1_43.jpg" WIDTH=41 HEIGHT=4 ALT="">'
		+ '</td>'
		+ '<td>'
		+ '<IMG SRC="image/skin-1_43.jpg" WIDTH=43 HEIGHT=4 ALT="">'
		+ '</td>'
		+ '</tr>'
		+ '</table>';
		SoundArea.innerHTML = source;
	}
}

function SetMail() {
	var mail;
	if (parent.mailUrl) {
		mail = parent.mailUrl;
	} else {
		mail = parent.defaultMailUrl;
	}
	Mail.innerHTML = '<a href="mailto:' + mail + '"><IMG SRC="image/skin-1_23.jpg" WIDTH=34 HEIGHT=36 ALT="ÃßÃµ¸ÞÀÏ" GALLERYIMG="no" style="border:none;cursor:hand"></a>';
}

function ShowLogo() {
	var url, img;
	if (parent.logoUrl) {
		url = parent.logoUrl;
	} else {
		url = parent.defaultLogoUrl;
	}
	if (parent.logoImg) {
		img = parent.logoImg;
	} else {
		img = parent.defaultLogoImg;
	}
	Logo.innerHTML = '<A HREF="' + url + '" TARGET="_blank"><IMG SRC="image/' + img + '" HEIGHT="33" BORDER="0" GALLERYIMG="no"></A>';
}

function ShowPageNumber() {
    RightPageNumber.innerHTML = "<b>" + eval(parent.briefLeftPage - parent.startRight) + "/" + eval(parent.lastPage - parent.startRight) + "</b>";
	PageNum.value = eval(parent.briefLeftPage - parent.startRight);
    if (parent.detailViewStatus) {
        switch (parent.detailRightPage) {
			case 0 : RightPageNumber.innerHTML = "";
			case 1 : RightPageNumber.innerHTML = "";				          
		}
    }
}

function playOrStop(obj) {
	if (obj.active == "true") {
		obj.active = "false";
		obj.src = obj.offsrc;
		setBGMVolume(-10000);
	} else {
		obj.active = "true";
		obj.src = obj.onsrc;
		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 MouseMove() {
    if (parent.menuFrameLoaded != true) { 
        parent.frames['Frame_Screen'].ZoomInScrollStop();
    }
}

function CheckEnterKey(arg_PageNo) {
    if (window.event.keyCode == 13)
		GotoPage(arg_PageNo);
}

function ShowBookTitle() {
    if (parent.bookTitle != "")
        BookTitle.innerHTML = "&nbsp;" + parent.bookTitle + "&nbsp;";
}

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) {
	var arg_Page = page + parent.startRight;
    if ((arg_Page >= parent.firstPage) && (arg_Page <= parent.lastPage)) {
        parent.frames['Frame_Screen'].GotoPage(arg_Page);
        parent.frames['Frame_Screen'].focus();  
    } else {
        alert("Àß¸øµÈ ÆäÀÌÁö ¼ýÀÚ¸¦ ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù."  + "\n" +
              "ÀÌ ¾Ù¹üÀÇ ÆäÀÌÁö ¹üÀ§ : [ " + 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 == "contents"){
					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;
		}
		else{
				if(obj.id == "contents"){
					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(AutoCount.value)*1000);
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].autoplaystop();
	}
}

function isPlaySound(btn) {
	if (parent.frames['Frame_Screen'].isPlaySound == false) {
		btn.src = btn.onsrc;
		parent.frames['Frame_Screen'].isPlaySound = true;
		parent.frames['Frame_Screen'].soundOn();
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].isPlaySound = false;
		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;
	} else { 
		btn.src = btn.offsrc;
		parent.frames['Frame_Screen'].relayPlay = false;
		parent.frames['Frame_Screen'].clearSound();
	}
}