if (document.all) classFix = "className"
else classFix = "class"

var originalHeight;
//var fontSize = 14;
var fontSize = 12;
var lineHeight = 16;
var currentPos = 0; //tracks position of columns

var tHeight = 0;

columnMode = 2;

col2Width = 300;
col1Width = 600;
colWidth = 0;

FONT_SMALLEST = 8;
FONT_LARGEST = 24;

function getHeight(obj)
	{		
	if (obj == "window") 
		{
			if (window.innerHeight) return window.innerHeight;			
			else{
				if(window.name != "main"){
					return document.getElementById("bodyNode").offsetHeight+8;
				}else{
				  return document.getElementById("bodyNode").offsetHeight-50;
			  }
			}
		}
	else
		{
			obj = document.getElementById(obj)
			if (obj.offsetHeight) return obj.offsetHeight;
		}
		
	}

function getWidth(obj)
	{
	if (obj == "window") 
		{
		if (window.innerWidth) return window.innerWidth;
		else return document.getElementById("bodyNode").offsetWidth;
		}
	else
		{
		obj = document.getElementById(obj)
		if (obj.offsetWidth) return obj.offsetWidth;
		}
	}

function nextPageOver()
	{
	//displays next page icon when mousing over column
	
	parentHeight = getHeight("articleParent")
	
	if ((parentHeight*(currentPos+columnMode)) < tHeight)
	{	
		obj = document.getElementById("nextCool")
		obj.style.visibility = "hidden"
		obj = document.getElementById("nextHot")
		obj.style.visibility = "visible"
		}
	}

function prevPageOver()
	{
	//displays next page icon when mousing over column
	if (currentPos > 0)
	{	
		obj = document.getElementById("prevCool")
		obj.style.visibility = "hidden"
		obj = document.getElementById("prevHot")
		obj.style.visibility = "visible"
		}
	
	}

function hidePageOver()
	{
	//hides mouse icon when leaving the column
	obj = document.getElementById("prevCool")
	obj.style.visibility = "visible"
	obj = document.getElementById("prevHot")
	obj.style.visibility = "hidden"
	
	obj = document.getElementById("nextCool")
	obj.style.visibility = "visible"
	obj = document.getElementById("nextHot")
	obj.style.visibility = "hidden"
}
	
function articleSetup()
	//makes the columns and copies the text node into the newly created columns 
	//ac is the div holding the cloned node - at
	{
	parentDiv = document.getElementById("articleParent")
	currentPos = 0;
	for (i=0; i < 3; i++)
		{
		col = document.createElement("div")
		col.setAttribute("id", "ac"+i) //set id for div
		col.setAttribute(classFix, "artCol") //give the div style

		parentDiv.appendChild(col);
		obj = document.getElementById("articleBody")
		
		artText = obj.cloneNode(true)
		
		artText.setAttribute("id","at"+i)
		artText.style.display = "block" //display the column		
		artText.style.top = "0px"
		
		artText.style.fontSize = fontSize+"px";
		artText.style.lineHeight = lineHeight+"px";
				
		col.appendChild(artText);		
		}
	}	

function layoutArticles()
	//moves the columns into position, but adjust the top
	{	
	parentHeight = getHeight("articleParent")
	for (i = 0; i < columnMode; i++)
		{
		obj = document.getElementById("at"+i);
		if (parentHeight > 2*lineHeight) //make sure at least 2 rows of article text are available 
			{
			obj.style.top = -1*(parentHeight*(i+currentPos))//"px"//-1*(parentHeight*(i+currentPos))+"px"
			}
		}
		articlePages();
	}
	
function setSnap(mod) 
	//returns the snap to align article; this adjusts the height of the article window with a number divisible by line height
	//the minium number of rows is 10
	{
	if (mod == null) mod =0;
	//snap = lineHeight*Math.round((getHeight("window")-mod)/lineHeight)
	snap = lineHeight*Math.round((getHeight("window")-mod)/lineHeight)

	if (snap < lineHeight*10) 
		{
		snap = lineHeight*10; //make the article parent 10 rows tall;
		if (window.scrollTo) window.scrollTo(0,75);
		}
	else if (window.scrollTo) window.scrollTo(0,0);
	return snap;	
	}

function setArticleHeight() //clips the parent layer to the defined visible area
	{
	//if space allows include bottom, otherwise clip out most of bottom
	//originalHeight = getHeight("articleParent")
	if (columnMode > 1)
	{
	if (document.getElementById("articleBody") != null)
		{
		document.getElementById("articleParent").style.height = setSnap(295)
		tHeight = getHeight("at1")
		parentHeight = getHeight("articleParent")
		
		while ((parentHeight*(currentPos+columnMode-1)) > tHeight && currentPos > 0) //check to make sure page is still visible 
			{
			currentPos= currentPos-1;
			}
		layoutArticles()
		}		
	}
	}

function articlePages()
	{
	//returns the number of screens an article spans, ie the number of pages 
	parentHeight = getHeight("articleParent")
	
	totalColumns = tHeight/parentHeight;
	totalPages = Math.ceil(totalColumns);
	tPos = (currentPos+columnMode)/columnMode;

	pagesTotal = Math.ceil(totalPages/columnMode)+1;
	pagesCurrent = Math.round(tPos+1);

	if (pagesCurrent - 1 > 1) {
		document.getElementById("articlePrevPage").style.display = "block";
	}
	else {
		document.getElementById("articlePrevPage").style.display = "none";
	}
	
	if (pagesTotal  > pagesCurrent ) {
		document.getElementById("articleNextPage").style.display = "block";
	}
	else {
		document.getElementById("articleNextPage").style.display = "none";
	}
}
	
function nextPage()
	{
	parentHeight = getHeight("articleParent")
	
	if ((parentHeight*(currentPos+columnMode)) < tHeight) //check to make sure page is still visible 
		{
		currentPos= currentPos+columnMode;
		}

	layoutArticles();
	}
	
function prevPage()
	{
	currentPos= currentPos-columnMode;
	if (currentPos < 0) currentPos = 0
	layoutArticles()
	}
	

function eventTwoColumn() 
	{
	if (window.scrollTo) window.scrollTo(0,0);
	twoColumn();
	setArticleHeight();
	articlePages();
	}

function twoColumn() //switches to two Column mode
	{
	currentPos = 0;
	columnMode = 2
	
	colWidth = col2Width;
	
	obj = document.getElementById("at0")
	obj.style.width = colWidth;
	obj.style.left = 0;
	if (document.all) obj.style.cursor = "hand";
	else  obj.style.cursor = "pointer";
	obj.onmousedown = prevPage;
	
	obj = document.getElementById("at1")
//	obj.style.left = colWidth+20;
	obj.style.left = colWidth+12;
	obj.style.width = colWidth;
	obj.style.display = "block"
	if (document.all) obj.style.cursor = "hand";
	else  obj.style.cursor = "pointer";
	obj.onclick = nextPage;
	
	obj = document.getElementById("at2")
	obj.style.display = "none"
	
	document.getElementById("articleNextPage").style.display = "block";
	document.getElementById("articlePrevPage").style.display = "block";
	
	saveFaceSize();
	}


function saveFaceSize()
	{
	var expire = new Date ();
   	expire.setTime (expire.getTime() + (6000 * 24 * 3600000)); //expires in 6 days from users clock
   	expire = expire.toGMTString();
	document.cookie="fontSize="+fontSize+"; columnMode="+columnMode+"; path=/; expires="+expire;
//	document.cookie="columnMode="+columnMode+"; path=/; expires="+expire;  	
	}
	
function setFaceSize()
	{
	lineHeight = fontSize+Math.round(.3*fontSize);
	
	for (i = 0; i < 3; i++)
		{
		obj = document.getElementById("at"+i);
		obj.style.fontSize = fontSize+"px";
		obj.style.lineHeight = lineHeight+"px"
		}
	setArticleHeight();
	saveFaceSize();
	}
	
//´Ù´ÜÀÏ¶§ÀÇ fontsize
function eventFaceLarger()
	{
	//alert(document.all.textColumn0.document.style.fontSize)
	fontSize = fontSize+2;

	if (fontSize > 26) {fontSize = 26;}
	setFaceSize()
	}
		
function eventFaceSmaller()
	{
	fontSize = fontSize-2
	if (fontSize < 9) fontSize = 9;
	setFaceSize();
	}

		
function eventArticleFocus()
	{
	layoutArticles();
	event.cancelBubble = true;
	}	

function eventArticleBlur()
	{
	window.status = "article blurred"
	}		
	
function testArticle()
	{
	obj = document.getElementById("articleParent")
	obj.doScroll("up");
	window.status = "This interface does not support scrolling.";
	}

//Àå¹®ÀÏ¶§ÀÇ fontsize
function fontSetup(){
	if (isIE4) { 
		loadFontSize();		
		t1.style.fontSize = fontSize+"px";
	}
}
function fontPlus(){
	fontSize = fontSize+2;
	if (fontSize > 26) {fontSize = 26;}
	t1.style.fontSize = fontSize+"px";
	saveFaceSize();
}
function fontMinus(){
	fontSize = fontSize-2;
	if (fontSize < 9) fontSize = 9;	
	t1.style.fontSize = fontSize+"px";
	saveFaceSize();
}
//Àå¹®ÀÏ¶§ÀÇ fontsize
	
function loadFontSize()
	//get font size from a cookie
	{
	tempArray = document.cookie.split(";");		
	for (tA = 0; tA < tempArray.length; tA++)
			{
			if (tempArray[tA].indexOf('fontSize') > -1) //found the font section in cookie
				{
				fontValue = tempArray[tA].split("=")
				fontSize = parseInt(fontValue[1]);
				lineHeight = fontSize+Math.round(.3*fontSize);
				}
/*			if (tempArray[tA].indexOf('columnMode') > -1) //found the font section in cookie
				{
				colValue = tempArray[tA].split("=")
				columnMode = parseInt(colValue[1]);
				}*/
			}
	}

function initArticle()
	{
	//loadUserPref()
	if (document.getElementById("articleBody") != null)
		{
		//loadFontSize();

		articleSetup();
		
		setArticleHeight();

		col1Width=getWidth("articleParent") - 15
		col2Width=col1Width / 2 ;//- 10

		twoColumn();
		 
		setFaceSize();
		
		layoutArticles()
		
		//attempt to get article to NOT scroll when space bar is pressed in IE
		obj = document.getElementById("articleParent");
		obj.onkeyup = eventArticleFocus;
		
		obj.onscroll = testArticle;

		}
	}
