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

var mouseX = mouseY = 0;
var currentPos = 0;
var columnMode = 2;
var colWidth = 0;
var col1Width = 500;
var col2Width = 248;
var col3Width = 100;
var fontSize = 10;
var theight = 0;
var lineHeight = 30;


function nextPage() {
	tHeight = getHeight("at0")
	parentHeight = getHeight("articleParent")
	
	if ((parentHeight*(currentPos+columnMode)) < tHeight)  {
		currentPos= currentPos+columnMode;
	
		layoutArticles()
	}

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

function eventThreeColumn() {
	if (window.scrollTo) window.scrollTo(0,0);
	threeColumn();
	setArticleHeight();
	
	//saveFaceSize();
	//articlePages();
}

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

function eventOneColumn() {
	if (window.scrollTo) window.scrollTo(0,0);
	OneColumn();
	setArticleHeight();
	
	//saveFaceSize();
	//articlePages();
}

function OneColumn() {
	currentPos = 0;
	columnMode =1 
	colWidth = col1Width;
	
	obj = document.getElementById("at0")
	obj.style.width = colWidth;
	obj.style.left= 0
	obj = document.getElementById("articleParent");
	obj.style.height = getHeight("at0")//col2Width;
	
	obj = document.getElementById("at1")
	obj.style.display = 'none';
	
	obj = document.getElementById("at2")
	obj.style.display = "none"

	document.getElementById("previcon").style.display = "none"
	document.getElementById("nexticon").style.display = "none"
	//------- document.getElementById("pagepart").style.display = "none"

	
	parentHeight = getHeight("articleParent")
	
	for (i = 0; i < columnMode; i++)
		{
		obj = document.getElementById("at"+i);
		obj.style.top = -1*(parentHeight*(i+currentPos))//"px"//-1*(parentHeight*(i+currentPos))+"px"
		}
	
	
	//saveFaceSize();
	//articlePages();
	
	
	depthtoggle('on');
}
	
function threeColumn() {
	currentPos = 0;
	columnMode = 3
	
	colWidth = col3Width;
	
	if (fontSize > 20) {fontSize = 20}
	obj = document.getElementById("at0")
	if (document.all) obj.style.cursor = "hand";
	else  obj.style.cursor = "pointer";
	obj.style.zIndex = 5;
	obj.style.width = colWidth;
	obj.onmousemove = prevPageOver;
	obj.onmouseout = hidePageOver;
	obj.onmousedown = prevPage;
	obj.onmouseup = hidePageOver;
	obj.style.left = 0;
	
	obj = document.getElementById("at1")
	obj.style.left = colWidth+14;
	obj.style.display = "block"
	obj.style.width = col3Width;
	obj.style.cursor = "default";
	obj.onmousemove = null;
	obj.onmouseout = null;
	obj.onclick = null;
	obj.onmouseup = null;

	obj = document.getElementById("at2")
	if (document.all) obj.style.cursor = "hand";
	else  obj.style.cursor = "pointer";
	obj.style.display = "block"
	obj.style.left = 2*(colWidth+14);
	obj.style.width = colWidth;
	obj.onmousemove = nextPageOver;
	obj.onmouseout = hidePageOver;
	obj.onclick = nextPage;
	obj.onmouseup = hidePageOver;
	

	document.getElementById("articleNextPage").style.display = "block";
	document.getElementById("articlePrevPage").style.display = "block";
	
	depthtoggle('off');
}

function twoColumn() {
	currentPos = 0;
	columnMode = 2;
	
	colWidth = col2Width;
	
	if (fontSize > 20) {fontSize = 20}
	obj = document.getElementById("at0")
	obj.style.zIndex = 5;
	obj.style.width = colWidth;
	obj.style.left = 0;
	
	obj = document.getElementById("at1")
	obj.style.left = colWidth+12;
	obj.style.display = "block"
	obj.style.width = col2Width;
	obj.style.cursor = "default";

	obj = document.getElementById("at2")
	obj.style.display = "none"

	document.getElementById("previcon").style.display = "block"
	document.getElementById("nexticon").style.display = "block"
	//----------- document.getElementById("pagepart").style.display = "inline"

	depthtoggle('off');
}
	
function screenObject(){

	this.bottom = function(){
		if (document.body.scrollHeight) return document.body.scrollHeight;
	}
	
	this.height = function() {
		if (document.body.offsetHeight) return document.body.offsetHeight;
	}
	
	this.visHeight = function() {
		if (window.innerHeight) return window.innerHeight;
		if (document.body.clientHeight) return document.body.clientHeight;
	}
	
	this.width = function() {
		if (document.body.offsetWidth) return document.body.offsetWidth;
	}
	
	this.scrollTop = function() {
		if(document.body.scrollTop) return document.body.scrollTop
		if (window.pageYOffset) return window.pageYOffset;
		else return 0;
	}
	
}


function articlePages() {
	parentHeight = getHeight("articleParent")
	
	tHeight = getHeight("at1")
	
	totalColumns = tHeight/parentHeight;
	totalPages = Math.ceil(totalColumns);
	tPos = (currentPos+columnMode)/columnMode;

	pagesTotal = Math.ceil(totalPages/columnMode)+1;
	pagesCurrent = Math.round(tPos+1);
	
	//alert (pagesCurrent);
	
	if (pagesCurrent - 1 > 1) {
		document.getElementById("previcon").style.display = "block";
	}
	else {
		document.getElementById("previcon").style.display = "none";
	}
	
	if (pagesTotal  > pagesCurrent ) {
		document.getElementById("nexticon").style.display = "block";
	}
	else {
		document.getElementById("nexticon").style.display = "none";
	}

	
	/*---------------------
	if (pagesCurrent > 9) {
		
		total = pagesCurrent+""; //make it a string;
		document.getElementById("pgCol0").style.top = (parseInt(total.substring(0,1))+1)*-5;
		document.getElementById("pgCol1").style.top = (parseInt(total.substring(1,2))+1)*-5;
	}
		
	else {
		document.getElementById("pgCol0").style.top = 0;
		document.getElementById("pgCol1").style.top = pagesCurrent*-5;
	}
	
	if (pagesTotal > 9) {
		total = pagesTotal+""; //make it a string;
		document.getElementById("pgCol2").style.top = (parseInt(total.substring(0,1))+1)*-5;
		document.getElementById("pgCol3").style.top = (parseInt(total.substring(1,2))+1)*-5;
	}
	else {
		document.getElementById("pgCol3").style.top = 0;
		document.getElementById("pgCol2").style.top = pagesTotal*-5;
	}
	------------------*/
	
	
}
	
function loadFontSize() {
	tempArray = document.cookie.split(";");		
	for (tA = 0; tA < tempArray.length; tA++) {
		if (tempArray[tA].indexOf('fontSize') > -1) {
			fontValue = tempArray[tA].split("=")
			fontSize = parseInt(fontValue[1]);
			lineHeight = fontSize+Math.round(.3*fontSize);
		}
		if (tempArray[tA].indexOf('columnMode') > -1) {
			colValue = tempArray[tA].split("=")
			columnMode = parseInt(colValue[1]);
			}
	}
}

function getHeight(obj){
	if (obj == "window") {
		if (window.innerHeight) return window.innerHeight;
		else return document.getElementById("bodyNode").offsetHeight;
	}
	else {
		obj = document.getElementById(obj)
		if (obj.offsetHeight) return obj.offsetHeight;
	}
}
	
function setSnap(mod) {
	if (mod == null) mod =0;
	snap = lineHeight*Math.round((getHeight("window")-mod + 40)/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 layoutArticles(){	
	parentHeight = getHeight("articleParent")
	for (i = 0; i < columnMode; i++){
		obj = document.getElementById("at"+i);
		if (parentHeight > 2*lineHeight) {
			obj.style.top = -1*(parentHeight*(i+currentPos))//"px"//-1*(parentHeight*(i+currentPos))+"px"
		}
	}

	
	if (columnMode > 1) articlePages();
}

	
function setArticleHeight() {
	if (columnMode > 1) 	{
		if (document.getElementById("articleBody") != null)	{

			document.getElementById("articleParent").style.height = setSnap(330)

			tHeight = getHeight("at1")
		
			parentHeight = getHeight("articleParent")

			while ((parentHeight*(currentPos+columnMode-1)) > tHeight && currentPos > 0) {
				currentPos= currentPos-1;
			}
			layoutArticles()
		}
		
	}
}


function articleSetup() {
	parentDiv = document.getElementById("articleParent")
	currentPos = 0;
	for (i=0; i < 3; i++) {
		// µðºñÁ¯ 3°³ »ý¼º, ÄÃ·³ 
		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+"pt";
		artText.style.lineHeight = lineHeight+"px";
				
		col.appendChild(artText);		
	}
}

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(1.1*fontSize);
	
	for (i = 0; i < 3; i++) {
		obj = document.getElementById("at"+i);
		obj.style.fontSize = fontSize+"pt";
		obj.style.lineHeight = lineHeight+"px"
	}
	setArticleHeight();
	if (columnMode == 1) eventOneColumn();
	//saveFaceSize();
}

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

}

function testArticle(){
	obj = document.getElementById("articleParent")
	obj.doScroll("up");
	window.status = "This interface does not support scrolling.";
}
	
	
function initArticle(cold) {
	
	
	if (document.getElementById("articleBody") != null) {
		//loadFontSize();
		articleSetup();
		setArticleHeight();
		if (cold == '1') columnMode=1;
		if (columnMode == 1) eventOneColumn();
		if (columnMode == 2) twoColumn();
		if (columnMode == 3) threeColumn();
		setFaceSize();
		layoutArticles()

		obj = document.getElementById("articleParent");
		obj.onkeyup = eventArticleFocus;
		obj.onscroll = testArticle;

	}
		
}

function userEventsInit() {
	for (i=0; i < menus.length; i++){
		obj = document.getElementById("nav"+menus[i])
		obj.onclick = eventShowMenu;
		
		obj = document.getElementById("menu"+menus[i])
		obj.onmouseover = menuOver;
		obj.onmouseout = menuOut;
	}
		
	obj = document.getElementById("navClippingsCounter")
	obj.onclick = eventShowNextClipping; //in ihtClippings.js
		
	obj = document.getElementById("navHelp")
	obj.onclick = eventHelp; //in ihtClippings.js
	

}

function mousePosition(e){
	if (e) event = e;   //for Netscape
	mouseX = event.clientX;
	mouseY = event.clientY;
}

function windowResize(){
	if (document.getElementById("articleBody") != null) setArticleHeight() //adjust article layout
	
}
	
function depthtoggle(onoff) {

	var obj = document.getElementById("hidepoint") ;
	var more = document.getElementById("hidemore") ;


	if (obj != null) {
		if (onoff == "off") {
			obj.style.display = "none";
			more.style.display = "block";
			
		}
		else {
			obj.style.display = "block";
			more.style.display = "none";
		}
	}

}

function fontPlus() { 
	if (fontSize < 16) {
		fontSize = fontSize + 2; 
		setFaceSize(); 
	} 
}

function fontMinus() { 
	if (fontSize >= 10) {
		fontSize = fontSize - 2; 
		setFaceSize(); 
	} 
}

function initialize1() {
	ihtScreen = new screenObject(); 
	if (document.getElementById("articleBody") != null) initArticle(1);	  //lays out the article in columns(if one exists)
	document.onmousemove = mousePosition; //moz
	window.onresize = windowResize;	
}

function initialize2() {
	ihtScreen = new screenObject(); 
	if (document.getElementById("articleBody") != null) initArticle();	  //lays out the article in columns(if one exists)
	document.onmousemove = mousePosition; //moz
	window.onresize = windowResize;	
}