var characterName = new Array(
	"Kisaeng", 
	"Farmer", 
	"Pobusang",	"Yangban",
	"Shaman", 
	"Yangban"
);

function popKeyTerm(wKeyTerm) {
	MM_openBrWindow('../viewTerm.html?keyTerm=' + wKeyTerm,'term','toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width=400,height=150');
}

var characterText = new Array(
	"Kisaeng, female entertainers of the Choson period, ranged from poor prostitutes to celebrated courtesans involved in major political intrigues of the day. While most kisaeng were much more educated than even their yangban counterparts, they ultimately held one of the least respected class positions in Choson society. By definition, kisaeng violated the strict code of sex segregation upheld in the Choson Dynasty, as well as the Confucian virtue of modesty.  ",
	"Korean farmers were the backbone of the Choson dynasty.  They represented the majority of the Korea's citizens, and were the constituent base leaders relied upon to carry their rule.  As part of the <i>chunin</i> class, they were well respected by their rulers",
	"A pobusang was a specialized merchant who traveled throughout the country on set five and seven day cycles, trading goods and spreading news between cities and towns.  They were better respected than most other merchants, because they often played important roles as government agents.",
	"As a member of Korea's upper class, this yangban with other members of his social group held positions as government officials and Confucian scholars.  They viewed the fulfillment of their government duties as the strictest of Confucian obligations.",
	"Korean shamans, also known as mansin, were women who held positions vital to Korean society, yet occupied the lowest rung on the Choson Dynasty's class system. By performing kuts and exorcising demons, shamans provided all members of society, from butchers to princes, with the supernatural intervention necessary to dispel bad fortune and angry spirits.  ",
	"As a member of Korea's ruling class of literati, yangban women were expected to fulfill the normal feminine obligation of securing a profitable marriage and birthing many sons, but were also expected to provide all classes with ideal examples of the feminine Confucian virtues."
);

var thisChar = queryField("thisChar")
if (thisChar == "") {
	thisChar = 1;
}

var lastpage = 7;

function setChar() {
	document.images['charImage'].src = 'images/s_char_' + thisChar + '.jpg';
}

function loadup() {
	if (thispage == 'page05') {
		pageup();
	}
	setChar();
	document.images['nav' + thispage.substring(4,6)].src = 'images/nav_' + thispage.substring(4,6) + 'b.gif';
	document.images['bav' + thispage.substring(4,6)].src = 'images/nav_' + thispage.substring(4,6) + 'b.gif';
	if (eval(thispage.substring(4,6)) < 2) {
		document.images['prev'].src = 'images/grey.gif';
		document.images['brev'].src = 'images/grey.gif';
	}
	if (eval(thispage.substring(4,6)) > lastpage - 1) {
		document.images['next'].src = 'images/grey.gif';
		document.images['bext'].src = 'images/grey.gif';
	}
	document.images['subtitle'].src = 'images/subtitle_' + thispage.substring(4,6) + '.gif';
}


function changeChar(which) {
	if (which == thisChar) {
		this.window.location= "charInfo" + thisChar + ".html?frompage=" + thispage.substring(5,6) + "&thisChar=" + thisChar;;
		return;
	}
	else {
		this.window.location= "charView" + which + ".html?frompage=" + thispage.substring(5,6) + "&thisChar=" + thisChar;
		return;
	}
}

function gotopage(wPage) {
	if (wPage == 'prev') {
		pPage = eval(thispage.substring(4,6)) - 1;
		if (pPage > 0) {
			this.window.location= "page0" + pPage + ".html?thisChar=" + thisChar;
		}
		return;
	}
	if (wPage == 'next') {
		nPage = eval(thispage.substring(4,6)) + 1;
		if (nPage < lastpage + 1) {
			this.window.location= "page0" + nPage + ".html?thisChar=" + thisChar;
		}
		return;		
	}
	this.window.location= "page" + wPage + ".html?thisChar=" + thisChar;
}

var pCount = new Array(
	1,
	1,
	1
);

var cStory = new Array(
	1,
	1,
	1
);

function storyNext(wStory) {
	if (cStory[wStory] < totalPages[wStory]) {
		cStory[wStory] = cStory[wStory] + 1
		gotostory(wStory);
		if (pageScroll > 0) {
			this.window.scrollTo(0, pageScroll);
		}
	}
}

function storyPrev(wStory) {
	if (cStory[wStory] > 1) {
		cStory[wStory] = cStory[wStory] - 1
		gotostory(wStory);
		if (pageScroll > 0) {
			this.window.scrollTo(0, pageScroll);
		}			
	}
}

function gotostory(wStory) {
	for (i = 0; i < totalPages[wStory]; i++) {
		mLayer = 's' + wStory + 'page' + (i+1);
		MM_showHideLayers(mLayer,'','hide');
	}
	mLayer = 's' + wStory + 'page' + cStory[wStory];
	MM_showHideLayers(mLayer,'','show');
}
	

function exitLesson(toPage) {
	if(confirm("Are you sure you want to exit this lesson?")) {
		this.window.location= toPage;
	}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MU_swapImage() { //v3.0
  var i,j=0,x,a=MU_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if (((x=MM_findObj(a[i]))!=null) && (a[i].substring(3,5) != thispage.substring(4,6))){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function queryField(opt)
{
  var keyloc		// The location of the start of "key=value"
  var nextkey 		// The start of the next key
  var start 		// The start of the value
  var opts			// The options specified by the search string
  var optval		// The value of the selected option
  // Determine the options/search string
  opts=location.search
  // Most keys start after an & and are followed by an = sign
  keyloc = opts.indexOf("&" + opt + "=")
  // If a string isn't found, indexOf returns -1.  So, we try the "first"
  // key, which appears right after the initial question mark
  if(keyloc == -1) {
    keyloc = opts.indexOf("?" + opt + "=")
  }
  // If, at this point, we still haven't found the key, stop.
  if (keyloc == -1) {
    return ""
  } 
  // The value normally ends with an ampersand (which marks the start of the next key/value pair)
  nextkey = opts.indexOf("&",keyloc+1)  
  // But sometimes there is no next pair
  if (nextkey == -1) {
    nextkey = opts.length
  }
  // Okay, what next?  Verify that it's reasonable
  if (nextkey < keyloc) {
    return ""
  }  
  // Get and return the value
  sval = keyloc+2+opt.length
  optval = plustospace(unescape(opts.substring(sval,nextkey)))
  return optval
} // getOption()

// Function
//   plustospace
// Description
//   Converts all the plus signs in a string to spaces.
//   (Most browsers convert spaces to pluses for form submission)
// Note
//   Not all of the code is what I'd expect, but this has been
//   thoroughly tested on Netscape Navigator 3.0 for the Mac.
function plustospace(txt)
{
  // Sanity check on empty string
  if (txt == "") { return txt }
  
  // Variables
  var newtxt=""  // The txt without the spaces
  var pos=0      // The position of the plus sign
  var prev=0     // The position of the previous plus sign
  var done=false // sentinel for loop
  var tmp        // Used for debugging
  
  // Repeatedly find the next + sign, stopping when no more
  // are found
  // alert("Text is '" + txt + "'") // DEBUG
  while (!done) {
    pos = txt.indexOf("+",prev)
    // tmp = prompt("Plus found at '" + pos + "'", "OK")  // DEBUG
    // if (tmp != "OK") { done = 1 }// DEBUG
    if (prev >= txt.length) {
      done = true
    }
    else if (pos == 0) {
      prev=1
      newtxt += " "
    }
    else if ((pos < 0) || (pos == "")) {
      // Not found ... exit
      done = true
    }
    else {
      // Copy text
      if (pos>prev) { newtxt += txt.substring(prev,pos) }
      newtxt += " "
      // And move on
      prev=pos+1
    }
  }
  // Get the last little bit
  newtxt += txt.substring(prev,txt.length)
  return newtxt  
} // plustospace()

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


