/*
 ___________________________________
/ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ\
| Another JavaScript from Uncle Jim |
|                                   |
| Feel free to use this script as   |
| long as this part stays unchanged |
|                                   |
|  Visit www.jdstiles.com for more  |
|Javascripts like this one.  Thanks.|
|   Created: 1996  Updated: 2006    |
|         Flip Text script          |
\___________________________________/
 ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
*/
var scrollLayer1="divscroll",scrollLayer2="divscroll2"
var underLayer1="divtext",underLayer2="divtext2"
var addText=false,nextChapter="",prevChapter="",nextLink="",prevLink="",prevId=null,nextId=null
var penh=0,t,interval=10,fadeInterval=50,isRun=false
var increment=2
var doLayer;
var range1;
var range2;

	if(document.getElementById){
		range1 	 = "getElementById(";
		range2 	 = ")";
		styleObj = ".style";
		doLayer = false;
	} else if(document.all) {
		range1 	 = "all.";
		range2 	 = "";
		styleObj = ".style";
		doLayer = false;
	} else {
		range1 	 = "layers.";
		range2 	 = "";
		styleObj = "";
		doLayer = true;
		interval=5
		}

function getObj(obj,stil) {
	var tmpObj;
	if (typeof obj == "string" && obj != "") {
		if(range2==""){
			if(stil){
				tmpObj = eval("document." + range1 + obj + range2 + styleObj)
			} else {
				tmpObj = eval("document." + range1 + obj + range2)
			}
		} else {
			if(stil){
				tmpObj = eval("document." + range1 + "\"" + obj + "\"" + range2 + styleObj)
			} else {
				tmpObj = eval("document." + range1 + "\"" + obj + "\"" + range2)
			}
		}
	}
	else {
		tmpObj = obj;
	}
	
	if(tmpObj){
		var xp = tmpObj;
	} else {
		var xp = "Not An Object";
	}
	return xp;
}


var h=220 
var dy=20 
var current,pages=1,pos=0,pageNr=1,pageMax=1,spill,left,right,end=false,begin=true,loop=false,isInited=false,counter=0
var varY=0,varY2=0;
var scrollSize,boxHeight

var lineheight=15,pictureheight=47

var txt=""

var ms=0,timerOn=false
var isFading

function goForObj(){
	alert(typeof(navicon))
}

function init(){
	counter+=1

	if (isInited){
		return
	} else {
		k=setTimeout("delayInit("+counter+")",1000)
	}
}

function layerWrite(lyr,strTxt){
	if (!doLayer){
		getObj(lyr,false).innerHTML = strTxt
	} else {
		getObj(lyr,false).document.write(strTxt)
		getObj(lyr,false).document.close()
	}
}

function delayInit(lastcounter){     
	clearTimeout(k)         
	if (lastcounter==counter){
		clearTimeout(k)
		isInited=true
		if (typeof(getObj(scrollLayer1,false))=='object') scrollinit()
	} else {
		k=setTimeout("delayInit("+counter+")",1000)
	}
}
function penstretch(thisDiv){
	if(!doLayer){
		getObj(fadeLayer,true).visibility='visible';
		getObj(fadeLayer,true).clip="rect(0px 410px "+penh+"px 0px)";
	} else {
		getObj(thisDiv,false).visibility='visible';
		getObj(thisDiv,false).clip.bottom=penh;
	}
	penh+=increment
	if (penh<=283){
		t=setTimeout("penstretch(\""+thisDiv+"\")",interval)
	} else {
		clearTimeout(t)
		done()
	}
}

function penfade(){
	if(fadeLayer!=""){
		high(document.fadeimg)
	}
}

function high(which2){
	theobject=which2
	highlighting=setInterval("highlightit(theobject)",fadeInterval)
}
function low(which2){
	clearInterval(highlighting)
	which2.filters.alpha.opacity=20
}

function highlightit(cur2){
	isFading=true
	if (cur2.filters.alpha.opacity<100){
		cur2.filters.alpha.opacity+=5
	} else if (window.highlighting) {
		clearInterval(highlighting)
		isFading=false
		done()
	}
}

var lineheight=15

function scrollinit(){
  if(scrollLayer1!=""){
		if(typeof(initNews)=='function'){
			initNews();
		}
	left=((!doLayer)?getObj(scrollLayer1,false).offsetLeft:getObj(scrollLayer1,false).left)-1;
	right=left+282

	scrollSize = (!doLayer)?getObj(underLayer1,false).offsetHeight:document.layers[scrollLayer1].document.layers[underLayer1].document.height;

	var tmp
	if (scrollSize>h){
		tmp=h%lineheight
		boxHeight=h-tmp
		dy=boxHeight
		h=boxHeight
		tmp=boxHeight
	} else {
		dy=h
		tmp=h
	}	
	
	writePages()
	setLimits(200,pageMax)

	if (!doLayer){
		getObj(scrollLayer1,true).clip = "rect(0px 300px "+tmp+"px 0px)"
		getObj(scrollLayer2,true).clip = "rect(0px 300px "+tmp+"px 0px)"
	} else {
		getObj(scrollLayer1,true).clip.bottom=tmp
		getObj(scrollLayer2,true).clip.bottom=tmp
	}
	getObj(scrollLayer1,true).visibility='visible'
  }
}

function writePages(){
	if(getObj("navbar",false)) actualWrite();
}
function actualWrite(){
		pages=((scrollSize-5)/h)+1
	
		var imgs=makeImg(1)
		for (var i=2;i<=pages;i++){
			imgs+=makeImg(i)
		}
		imgs=imgs+makeImg(0)
		pageMax=i-1
		spill=scrollSize-(pageMax-1)*h
		var nxt=""
		var prv=""
		if (nextId){
			nxt="<a href='"+nextLink+"' target='_self' class='cal'> </a>"
			prv="<font size='1' face='Verdana' color='666666'>Chapter "+ noThisChapter +" of "+ noOfChapters +"&nbsp;&nbsp;</font><img align='absmiddle' 'http://jdstiles.com/java/images/tile0.gif' height='16' width='13' src='' border='0'>"
		}
		if (prevId){
			prv="<font size='1' face='Verdana' color='666666'>Chapter "+ noThisChapter +" of "+ noOfChapters +"&nbsp;&nbsp;</font><a href='"+prevLink+"' target='_self' class='cal'></a>"
			if (!nextId) nxt="<img align='absmiddle' src='http://jdstiles.com/java/images/tile0.gif' height='16' width='12' border='0'>"
		}
		if (pageMax>1){
			layerWrite("navbar",imgs)
			if (nextId||prevId) layerWrite("chapters",prv+nxt)
			pageOf(1)
				getObj("navicon",true).visibility='visible'
		} else if (nextId||prevId){
			layerWrite("chapters",prv+nxt+"<br>")
		}
}

function visaPloppen(){
	getObj("navicon",true).visibility='visible'
}

function pageOf(nr){
	layerWrite("divpages","<font size='1' face='Verdana' color='666666'>Page "+nr+" of "+pageMax+"</font>")
}

function makeImg(nr){

	switch (nr){
		case 1:
			return "<a href='javascript:gotoPage("+nr+")' target='_self'><img name='mark1' src='' width=12 height=16 alt='' border='0'></a>"
		case 0:
			return "<img name='mark3' src='http://jdstiles.com/java/images/tile0.gif' width=1 height=16 alt='' border='0'>"
		default:
			return "<a name='mark2' href='javascript:gotoPage("+nr+")' target='_self'><img src='' width=12 height=16 alt='' border='0'></a>"
	}
}

function timerStart(){
	if (timerOn) return
	timerOn=true
	ms=0
	timer=setTimeout("timerRun()",1000)
}

function timerRun(){
	ms+=1000
	if (timerOn){
		timer=setTimeout("timerRun()",1000)
	} else {
		clearTimeout(timer)
	}
}

function timerStop(){
	timerOn=false
}

function slide(interval){
	var posx=(!doLayer)?getObj(scrollLayer1,false).offsetLeft:getObj(scrollLayer1,false).left;
	posx+=interval
	if ((posx<right||end)&&(posx>left)){
		getObj(scrollLayer1,true).left=posx
		setTimeout("slide("+interval+")",10)
	} else {
			if (interval>0){
				end=true
 				getObj(scrollLayer1,true).zIndex=50
 			slide(-interval)
			} else {
				end=false
				gotoPosition(current,"")
					getObj(scrollLayer1,true).left=left+1
					getObj(scrollLayer1,true).zIndex=200
					getObj(scrollLayer2,true).visibility='hidden'
				loop=false
			}			
	}
}

function makeLink(nr){
	return "<a href='javascript:gotoPage("+nr+")' target='_self'>"+nr+"</a>"
}

function gotoPage(nr){
	if (nr>pageMax) nr=pageMax
	if (loop) return
	var dpage=nr-pageNr
	
	layerWrite("navicon","<img src='http://jdstiles.com/java/images/tile0.gif' height='14' width='10'>")

	if (dpage==0) return
	loop=true
		current=h*dpage
	pageNr=nr
		getObj(scrollLayer2,true).visibility='visible'
	pageOf(nr)
	gotoPosition(current,"2")
	slide(interval)
	movePlopp(nr)
}

function sublayerWrite(lyr1,lyr2,txt){
	if (!doLayer){
		getObj(lyr2,false).innerHTML = txt
	} else {
		var lyrdoc=getObj(lyr1,false).document.layers[lyr2].document
		lyrdoc.write(txt)
		lyrdoc.close()
	}
}

function moveIt(y){
	varY=y
	if (!doLayer){
		getObj(underLayer1,true).top = varY;
	} else {
		getObj(scrollLayer1,false).document.layers[underLayer1].top = varY;
	}
}

function moveItLyr(y,lyrnr){
	var tmpLyr,tmpUnd
	if (lyrnr==""){
		varY=y
		tmpLyr=scrollLayer1
		tmpUnd=underLayer1
	} else {
		varY2=y
		tmpLyr=scrollLayer2
		tmpUnd=underLayer2
	}
	if (!doLayer){
		getObj(tmpUnd,true).top = y;
	} else {
		getObj(tmpLyr,false).document.layers[tmpUnd].top=y
	}
}

function gotoPosition(move,nr){
	var refy
	if (nr==''){
		refy=varY
	} else {
		refy=varY2
	}
	if (move<0){
		moveItLyr(refy-move,nr)
	} else {
		moveItLyr(refy-move,nr)
	}
}




