// ------------------------------------------------
//      Custom DHTML scrollbar
// ------------------------------------------------
//      (c) 2000
//      
//      Last updated: January 26, 2001
// ------------------------------------------------

// Values below are defaults. overwrite in HTML

// ------------------------------------------------
//	Internal value, for IE only
var scrollback = false;

// ------------------------------------------------
//		I suggest you don't alter anything below

var ie4 = (document.all)? true:false;
var ns6 = (!ie4 && document.getElementById)? true:false;

var MID = 50;
var RIGHT = 60;
var MIDRIGHT = 70;
var sbars = MID;
var activeB;

if(!ie4 && navigator.appName != "Netscape")
{	alert('It seems you are using an unsupported browser');
}


// ------------------------------------------------
//		Initializes the scrollbar
//		- called by body onload()

function initScroller(sb)
{	
	sbars = sb;
	if(sb==MID || sb==MIDRIGHT){
		////Middle scrollbar////
		scrollbar = new Scrollbar(MID);
	
		if(ie4)	scrollbar.pageFromTop = getLayer(scrollbar.layerToScroll).style.pixelTop;
		if(ns6) scrollbar.pageFromTop = parseInt(getLayer(scrollbar.layerToScroll).style.top);
	
		if(scrollbar.autoSnap) snapPosition(scrollbar);
		else if(scrollbar.snapFullScreen) snapFull(scrollbar);
		else if(scrollbar.barXfromRight)
		{	scrollbar.barXstart = scrollbar.pageWidth - scrollbar.barXstart;		
		}
	
		scrollbar.build();	
		scrollbar.setMaxScroll();
		scrollbar.loaded = true;
		scrollbar.monitor();
	
		if(document.location.search)
		{	var fetch = document.location.search;
			if(fetch.indexOf('?sPage=') != -1)
			{	
				fetch = fetch.substring(7,fetch.length);
				if(getLayer(fetch) != null)
				{	scrollbar.layerToScroll = fetch;
				}			
			}		
		}
	
		scrollbar.setPage(scrollbar.layerToScroll);	
		if(ie4 && scrollbar.disableIEscroll) document.body.style.cssText="overflow-y:hidden;";
		
		activeB = scrollbar;
	}
	
	
	
	if(sb==RIGHT || sb==MIDRIGHT){
		////Right scrollbar////
		scrollbar2 = new Scrollbar(RIGHT);
	
		if(ie4)	scrollbar2.pageFromTop = getLayer(scrollbar2.layerToScroll).style.pixelTop;
		if(ns6) scrollbar2.pageFromTop = parseInt(getLayer(scrollbar2.layerToScroll).style.top);
	
		if(scrollbar2.autoSnap) snapPosition(scrollbar2);
		else if(scrollbar2.snapFullScreen) snapFull(scrollbar2);
		else if(scrollbar2.barXfromRight)
		{	scrollbar2.barXstart = scrollbar2.pageWidth - scrollbar2.barXstart;		
		}
	
		scrollbar2.build();	
		scrollbar2.setMaxScroll();
		scrollbar2.loaded = true;
		scrollbar2.monitor();
	
		if(document.location.search)
		{	var fetch = document.location.search;
			if(fetch.indexOf('?sPage=') != -1)
			{	
				fetch = fetch.substring(7,fetch.length);
				if(getLayer(fetch) != null)
				{	scrollbar2.layerToScroll = fetch;
				}			
			}		
		}
	
		scrollbar2.setPage(scrollbar2.layerToScroll);	
		if(ie4 && scrollbar2.disableIEscroll) document.body.style.cssText="overflow-y:hidden;";
		
		activeB = scrollbar2;
	}	
}

//////////////////SCROLLBAR CLASS//////////////////
// ------------------------------------------------
//		Scrollbar Object.
//		- defines values and functions

function Scrollbar(BStyle)
{	
	// ------------------------------------------------
	//		Values:
switch(BStyle){
	case MID :	
		this.scrollyr = "scrollyr_mid";
		this.scroller = "scroller_mid";
		this.arrowUp = "arrowUp_mid";
		this.arrowDown = "arrowDown_mid";
		
		this.barWidth  = 30;
		this.barHeight = 230;
		this.barXstart = 505;
		this.barXfromRight = false;
		this.barYstart = 140;
		this.scrollerHeight = 9;
		this.layerToScroll = "mainMid";
		this.arrowSpeed = 5;
		this.clickStepSize = 40;
		this.extraSpace = 5;
	
		this.scrollerBG  = "_images/scroller_m_bg.gif";
		this.upSRC     = "_images/arrow_m_up.jpg";
		this.downSRC   = "_images/arrow_m_down.jpg";
		this.scrollSRC = "_images/scroller_m.gif";
	
		this.snapToLayer = "mainFrameMid"
		this.autoSnap = false;
		this.snapFullScreen = false;
		this.disableIEscroll = true;
		this.autoDisable = true;
		this.onDisable = "hide";
	
		this.arrowControl = true;
		this.arrowGrouping = false;
		this.arrowMouseOver = false;
	
		this.sizeToContent = false;
		this.maxScrollerSize = 100;
		break;
	case RIGHT:
		this.scrollyr = "scrollyr_right";
		this.scroller = "scroller_right";
		this.arrowUp = "arrowUp_right";
		this.arrowDown = "arrowDown_right";
	
		this.barWidth  = 30;
		this.barHeight = 230;
		this.barXstart = 730;
		this.barXfromRight = false;
		this.barYstart = 140;
		this.scrollerHeight = 9;
		this.layerToScroll = "main";
		this.arrowSpeed = 10;
		this.clickStepSize = 40;
		this.extraSpace = 5;
	
		this.scrollerBG  = "_images/scroller_bg.jpg";
		this.upSRC     = "_images/arrow_up.jpg";
		this.downSRC   = "_images/arrow_down.jpg";
		this.scrollSRC = "_images/scroller.jpg";
	
		this.snapToLayer = "mainFrame";
		this.autoSnap = false;
		this.snapFullScreen = false;
		this.disableIEscroll = true;
		this.autoDisable = true;
		this.onDisable = "hide";
	
		this.arrowControl = true;
		this.arrowGrouping = false;
		this.arrowMouseOver = false;
	
		this.sizeToContent = false;
		this.maxScrollerSize = 145;
		break;
	}

	//this.bstyle = BStyle;
	
	this.width  = this.barWidth;
	this.height = this.barHeight;
	this.xPos = this.barXstart;
	this.yPos = this.barYstart;
	this.enabled = true;
	
	this.barString = "";
	this.arrowSize = this.barWidth;
	this.arrowUpYstart   = 0;
	this.pageToScroll = this.layerToScroll;
	this.toScrollHeight = 0;
	this.activePage = this.layerToScroll;
	this.maxScroll = this.height - this.arrowSize;
	this.sbHistory = new Array(this.layerToScroll);
	this.atHistory = 1;
	
	this.loaded = false;
	this.x;
	this.y;
	
	this.SCmove = null;
	this.keyLock = false;
	
	this.pageFromTop;
	
	this.upIMG    = '<IMG SRC="'+this.upSRC+'" WIDTH="'+this.barWidth+'" HEIGHT="'+this.barWidth+'" BORDER="0">';
	this.downIMG  = '<IMG SRC="'+this.downSRC+'" WIDTH="'+this.barWidth+'" HEIGHT="'+this.barWidth+'" BORDER="0">';
	this.scrollIMG = '<IMG name="theScroller" SRC="'+this.scrollSRC+'" WIDTH="'+this.barWidth+'" HEIGHT="'+this.scrollerHeight+'" BORDER="0">';

	this.pageWidth  = (ie4)? document.body.clientWidth:window.innerWidth;
	this.pageHeight = (ie4)? document.body.clientHeight:window.innerHeight;
	
	
	
	// ------------------------------------------------
	//		Functions:

	this.build   = build;
	this.monitor = monitor;
	this.setPage = setPage;
	this.toTop   = toTop;
	this.goBack  = goBack;
	this.setMaxScroll = setMaxScroll;
}


// ------------------------------------------------
//		Scrollbar Build function
//		- builds Scrollbar and writes it to page

function build()
{	
	
	
	upApos = (this.arrowGrouping)? (this.height - (2*this.arrowSize)):0;
	scrpos = (this.arrowGrouping)? 0:this.arrowSize;
	
	// ------------------------------------------------
	//		Internet Explorer 4+

	if(ie4)
	{	this.barString = '<DIV ID='+this.scrollyr+' STYLE="position:absolute; left:'+this.xPos+'; top:'+this.yPos+'; '
		+ 'z-index:20; width:'+this.width+'; height:'+this.height+';">'
		
		+ '<DIV ID='+this.arrowUp+' STYLE="position:absolute; left:0; top:'+upApos+'; width:'+this.arrowSize+'; height:'
		+ this.arrowSize+'; z-index:30; Clip:rect(0,'+this.arrowSize+','+this.arrowSize
		+ ',0); cursor:hand;">'+this.upIMG+'</DIV>'
			
		+ '<DIV ID='+this.scroller+' STYLE="position:absolute; left:0; top:'+scrpos+'; width:'+this.arrowSize
		+ '; height:'+this.scrollerHeight+';' // clip:rect(0,'+this.width+','+this.scrollerHeight+',0);'
		+ ' z-index:25; cursor:hand;">'+this.scrollIMG+'</DIV>'
		
		+ '<DIV ID='+this.arrowDown+' STYLE="position:absolute; left:0; top:'+(this.height-this.arrowSize)+'; width:'
		+ this.arrowSize+'; height:'+this.arrowSize+'; z-index:30; Clip:rect(0,'+this.arrowSize+','+this.arrowSize
		+ ',0); cursor:hand;">'+this.downIMG+'</DIV>'

		+ '</DIV>';
		
		document.body.insertAdjacentHTML("BeforeEnd", this.barString);			
		
		getLayer(this.scrollyr).onmousedown = goThere;
		if(this.scrollerBG != "none") 
		{	if(this.scrollerBG.indexOf('.') != -1) getLayer(this.scrollyr).style.backgroundImage = "url("+this.scrollerBG+")";
			else getLayer(this.scrollyr).style.backgroundColor = this.scrollerBG;
		}
	}	
	
	// ------------------------------------------------
	//		Mozilla - Netscape 5 or 6
	
	if(ns6)
	{	scrollbarElement = new ns6layer(this.scrollyr,  this.xPos, this.yPos, this.width, this.height, 20,this);
		arrowUpElement   = new ns6layer(this.arrowUp,   0, 0, this.arrowSize, this.arrowSize, 30,this);
		arrowUpElement.addImage(this.upSRC,null,this);
		arrowDownElement = new ns6layer(this.arrowDown, 0, (this.height-this.arrowSize), this.arrowSize, this.arrowSize, 30,this);
		arrowDownElement.addImage(this.downSRC,null,this);
		scrollerElement   = new ns6layer(this.scroller, 0, this.arrowSize, this.arrowSize, this.scrollerHeight, 25,this);
		scrollerElement.addImage(this.scrollSRC, "theScroller",this);
			
		scroller  = getLayer(this.scroller);
		scrollyr  = getLayer(this.scrollyr);
		arrowUp   = getLayer(this.arrowUp);
		arrowDown = getLayer(this.arrowDown);
		
		scrollyr.onmousedown = goThere;
	}
}

// ------------------------------------------------
//		Sets up mouse event listeners for the
//		elements of the scrollbar.

function monitor()
{	scroller = getLayer(this.scroller);
	scrollyr = getLayer(this.scrollyr);
	arrowUp = getLayer(this.arrowUp);
	arrowDown = getLayer(this.arrowDown);
	
	scroller.scrolling = false;
	scroller.moving = false;
	scroller.yStart = this.yPos;
	scroller.difY = 0;
	scroller.checkPos = checkPos;
	scroller.onmousedown = setDrag;
	scroller.onmouseup   = stopDrag;
	
	arrowUp.onmouseout   = stopScroll;
	arrowDown.onmouseout  = stopScroll;
	arrowUp.onmouseup    = stopScroll;
	arrowDown.onmouseup   = stopScroll;

	if(this.arrowMouseOver)
	{	arrowUp.onmouseover = scrollUp;
		arrowDown.onmouseover = scrollDown;
	}
	else
	{	arrowUp.onmousedown  = scrollUp;
		arrowDown.onmousedown = scrollDown;	
	}
	if(this.arrowControl)
	{	document.onkeydown = doKeyDown;
		document.onkeyup   = doKeyUp;
	}
	
	document.onmousemove = mouseMove;
	document.onmouseup = mouseUp;	
	if(ie4 && scrollback) window.onscroll = fixIeScroll
}

// ------------------------------------------------
//		Built in option to enable page flipping in
//		one document.
//
//		- scrollbar.setPage(arg) with arg as String
//		  representing a layername with content,
//		  nested in the clipped top level layer


function setPage(toWhat)
{	var hideThis = getLayer(this.activePage);
	hideThis.style.visibility = "hidden";

	var showThis = toWhat;
	showThis = getLayer(showThis);
	showThis.style.visibility = "visible";	

	this.pageToScroll = toWhat;
	if(ns6) this.pageToScroll = getLayer(this.pageToScroll);
	this.activePage = toWhat;

	if(ie4) this.toScrollHeight = document.all[this.pageToScroll].clientHeight;
	if(ns6) this.toScrollHeight = this.pageToScroll.offsetHeight;

		scrollyr = getLayer(this.scrollyr);
		if(this.autoDisable && this.toScrollHeight <= this.height)
		{	this.enabled = false; //this was scrollbar
			if(this.onDisable == "hide") 
			{	scrollyr.style.visibility = "hidden";
			}
		}

		else 
		{	this.enabled = true; //this was scrollbar
			scrollyr.style.visibility = "visible";
		}
	
	// ------------------------------------------------
	//		Experimental resizer of scrollelement.
	//		- IE and NS6 only preview, ugly image resizing.

		if(this.sizeToContent)
		{	if(this.maxScrollerSize > (this.height - 2*this.arrowSize))
			{	this.maxScrollerSize = this.height - 2*this.arrowSize;
			}
			
			var percentage = 100/(this.toScrollHeight/this.height);
			var adjustedHeight = Math.floor(percentage/100 * this.maxScrollerSize);
			
			if(ie4) document.all.theScroller.style.height = adjustedHeight;
			if(ns6) document.getElementById('theScroller').style.height = adjustedHeight;
			
			this.scrollerHeight = adjustedHeight
			scrollbar.setMaxScroll();
		}
		
	scroller.style.top = (this.arrowGrouping)? 0:this.arrowSize;
	scroller.checkPos(this);

	// ------------------------------------------------
	//		Tracking History

	this.sbHistory[this.atHistory] = toWhat;
	this.atHistory ++;
	
}

function toTop()
{	with(this)
	{	setPage(this.activePage);
	}
}

function goBack()
{	with(this)
	{	atHistory -= 2;
		if(atHistory < 0)
		{	atHistory = 0;
			history.go(-1);
		}

		else 
		{	setPage(sbHistory[atHistory]);
		}
	}
}

// ------------------------------------------------
//		Defines the range of the scroll-element,
//		how far you can drag it up and down.


function setMaxScroll()
{	
	scroller = getLayer(this.scroller);
	this.maxScroll = this.height - this.arrowSize - this.scrollerHeight;
	scroller.range = this.maxScroll - this.arrowSize;
}
///////////////////////////////////////////////////




//////////////////NS6LAYER CLASS//////////////////
// ------------------------------------------------
//		Mozilla layer function (as Object)
//		- creates and writes layer to page
//		- addImage() writes an image to the layer

	function ns6layer(name, left, top, width, height, z, scrlbr)
	{	this.nameSRC = document.createElement("Div");
		this.nameSRC.id = name;

		if(name == scrlbr.scrollyr) document.body.appendChild(this.nameSRC);
		else scrollbarElement.nameSRC.appendChild(this.nameSRC);

		this.lyr = document.getElementById(this.nameSRC.id);
		this.lyr.setAttribute("style","position:absolute; left:"+left
					+"; top:"+top+"; width:"+width+"; height:"+height+";");
		this.lyr.style.zIndex = z;
		
		if(name == scrlbr.scrollyr && scrlbr.scrollerBG != "none")
		{	if(scrlbr.scrollerBG.indexOf('.') != -1) this.lyr.style.backgroundImage = "url("+scrlbr.scrollerBG+")";
			else this.lyr.style.backgroundColor = scrlbr.scrollerBG;
		}

		this.addImage = addImage;
	}

		function addImage(path, imgName,scrlbr)
		{	this.imgElement = document.createElement("Img");
			this.imgElement.src = path
			this.imgElement.width = scrlbr.barWidth;
			if (imgName != null)
			{	this.imgElement.id = imgName;
				this.imgElement.height = scrlbr.scrollerHeight;
			}
			this.imgElement.border = 0;

			this.lyr.appendChild(this.imgElement);
		}
///////////////////////////////////////////////////



// ------------------------------------------------
//		Sets up mouse event listeners for the
//		elements of the scrollbar.

function scrollUp()
{
	if(this.id=="arrowUp_right")activeB = scrollbar2;
	else if(this.id=="arrowUp_mid")activeB = scrollbar;	
	
	activeB.keyLock = true;
	scroller = getLayer(activeB.scroller);
	scroller.moving = true;
	if(ns6)  activeB.SCmove = setInterval(moveScroller, 25,(0-activeB.arrowSpeed),activeB);
	else activeB.SCmove = setInterval("moveScroller(0-activeB.arrowSpeed,activeB)",25);
	
}

function scrollDown()
{	
	if(this.id=="arrowDown_right")activeB = scrollbar2;
	else if(this.id=="arrowDown_mid") activeB = scrollbar;
	
	activeB.keyLock = true;
	scroller = getLayer(activeB.scroller);
	scroller.moving = true;
	if(ns6)  activeB.SCmove = setInterval(moveScroller, 25, activeB.arrowSpeed,activeB);
	else activeB.SCmove = setInterval("moveScroller(activeB.arrowSpeed,activeB)",25);
}

function stopScroll()
{	
	if(this.id=="arrowUp_right" || this.id=="arrowUp_right")activeB = scrollbar2;
	else if(this.id=="arrowUp_mid" || this.id=="arrowUp_mid")activeB = scrollbar;
	
	scroller = getLayer(activeB.scroller);
	scroller.moving = false;
	if(activeB.SCmove != null) clearInterval(activeB.SCmove);
}

// ------------------------------------------------
//		Mouse event function, enables dragging

function setDrag()
{	
	if(this.id=="scroller_right")activeB = scrollbar2;
	else if(this.id=="scroller_mid")activeB = scrollbar;
	
	scroller = getLayer(activeB.scroller);
	scroller.scrolling = true;
	scroller.difY = (activeB.y - scroller.yStart);
	
	if(ie4) scroller.difY -= scroller.style.pixelTop;
	if(ns6) scroller.difY -= parseInt(scroller.style.top);

	scroller.difY += scroller.yStart;
}

// ------------------------------------------------
//		Mouse event functions, disables dragging

function stopDrag()
{	
	if(this.id=="scroller_right")activeB = scrollbar2;
	else if(this.id=="scroller_mid")activeB = scrollbar;
	
	scroller = getLayer(activeB.scroller);
	if(!activeB.loaded) return;
	scroller.scrolling = false;
}

function doKeyDown(e)
{	
	scroller = getLayer(activeB.scroller);
	thekey = (ie4)? event.keyCode:e.which;
	key = String.fromCharCode(thekey);
	key = key.toLowerCase();
	
	scroller.moving = true;
	if(thekey == 38 || key == 'a' && !activeB.keyLock) 
	{	if(key == 'a') 
		{	scrollUp();
		}
		else moveScroller(-3,activeB);
	}
	
	if(thekey == 40 || key == 'z' && !activeB.keyLock)
	{	if(key == 'z')
		{	scrollDown();
		}
		else moveScroller(3,activeB);
	}
}

function doKeyUp(e)
{	stopScroll();
	activeB.keyLock = false;
}



// ------------------------------------------------
//		Arrow Buttons events, up and down functions

function moveScroller(how,scrlbr)
{	
	
	scroller = getLayer(scrlbr.scroller);
	if(scroller.moving && scrlbr.enabled)
	{	if(ie4) scroller.style.pixelTop += how;
		if(ns6) scroller.style.top = parseInt(scroller.style.top) + how;

		scroller.checkPos(scrlbr);		
	}	
}

// ------------------------------------------------
//		Maps scroll-element position to the content
//		layer, the heart of the script.

function checkPos(scrlbr)
{	
	if(scrlbr.arrowGrouping)
	{	scrlbr.maxScroll -= scrlbr.arrowSize;
		scrlbr.arrowSize = 0;		
	}

	else
	{	if(parseInt(this.style.top) < scrlbr.arrowSize) this.style.top = scrlbr.arrowSize;
		if(parseInt(this.style.top) > scrlbr.maxScroll) this.style.top = scrlbr.maxScroll;
	}
	
	var position = 0 - scrlbr.arrowSize;
	position += parseInt(this.style.top);

	var amountToDo = (scrlbr.toScrollHeight - scrlbr.height) + scrlbr.pageFromTop + scrlbr.extraSpace;
	if(amountToDo < 0) amountToDo = 0;
	var stepSize = amountToDo/this.range;

	var newPosition = scrlbr.pageFromTop - (position * stepSize);

	if(ie4) document.all[scrlbr.pageToScroll].style.pixelTop = newPosition;
	if(ns6) scrlbr.pageToScroll.style.top = newPosition;
}


// ------------------------------------------------
//		Mouse event function, mouse positions

function mouseMove(e)
{
	if(!activeB.loaded) return;
	if (ns6) {activeB.x=e.clientX; activeB.y=e.clientY;}
	if (ie4) {activeB.x=event.x; activeB.y=event.y;}

	if(ie4 && activeB.loaded) 
	{	if(event.button == 0) stopDrag();		
	}
	scroller = getLayer(activeB.scroller);
	if(activeB.loaded && scroller.scrolling && activeB.enabled)
	{	if(ie4 || ns6) scroller.style.top = (activeB.y - scroller.yStart) - (scroller.difY - scroller.yStart);
		
		scroller.checkPos(activeB);		
		return false;
	}	
}

function mouseUp(e)
{	scroller = getLayer(activeB.scroller);
	if(!activeB.loaded) return;
	scroller.scrolling = false;	
}

function fixIeScroll()
{	window.scrollTo(0,0);
}

// ------------------------------------------------
//		Clicking in the bar causes the scroll
//		element to take a step towards the mouse

function goThere()
{	
	if(this.id=="scrollyr_right"){
		activeB = scrollbar2;
	}
	else if(this.id=="scrollyr_mid"){
		activeB = scrollbar;
	}
	
	var where = activeB.y - activeB.yPos;
	scroller = getLayer(activeB.scroller);
	if(!scroller.scrolling && !scroller.moving)
	{	if(where < ((ie4)? scroller.style.pixelTop:((ns6)? parseInt(scroller.style.top):scroller.top)))
		{	if(ie4) scroller.style.pixelTop -= activeB.clickStepSize;
			if(ns6) scroller.style.top = parseInt(scroller.style.top) - activeB.clickStepSize;
		}

		else
		{	if(ie4) scroller.style.pixelTop += activeB.clickStepSize;
			if(ns6) scroller.style.top = parseInt(scroller.style.top) + activeB.clickStepSize;
		}
		
		scroller.checkPos(activeB);
	}
}


// ------------------------------------------------
//		Snapping function 
//		- Connects the scrollbar to a layer stated
//		  in the layout list. for lazy people.

function snapPosition(scrlbr)
{	var snapLayer = getLayer(scrlbr.snapToLayer);
	if(ie4)
	{	scrlbr.barXstart = snapLayer.style.pixelLeft + snapLayer.clientWidth;
		scrlbr.barYstart = snapLayer.style.pixelTop;
		scrlbr.barHeight = snapLayer.clientHeight;
	}
	
	if(ns6)
	{	scrlbr.barXstart = parseInt(snapLayer.style.left) + snapLayer.offsetWidth;
		scrlbr.barYstart = parseInt(snapLayer.style.top);
		scrlbr.barHeight = snapLayer.offsetHeight;
	}
}

function snapFull(scrlbr)
{	scrlbr.barYstart = 0;
	
	if(ie4)
	{	document.body.style.cssText="overflow-x:hidden;overflow-y:hidden"
		scrlbr.barXstart = document.body.clientWidth - scrlbr.barWidth;
		scrlbr.barHeight = document.body.clientHeight;
	}

	else
	{	scrlbr.barXstart = window.innerWidth - scrlbr.barWidth;
		scrlbr.barHeight = window.innerHeight;
	}
}


// ------------------------------------------------
//		finds layers within document. Brainjar.
//		-  http://www.brainjar.com. 

function getLayer(name) 
{	if (ie4) return eval('document.all.' + name);
	
	// ------------------------------------------------
	//		added Mozilla support

	if (ns6) return document.getElementById(name);
	
	return null;
}

function findLayer(name, doc) 
{	var i, layer;

	for (i = 0; i < doc.layers.length; i++) 
	{	layer = doc.layers[i];
		if (layer.name == name)	return layer;
		if (layer.document.layers.length > 0) 
		{	layer = findLayer(name, layer.document);
			if (layer != null) return layer;
		}
	}
	return null;
}