DynLayerSlideInit = new Function()
DynLayer.prototype.slideInit = new Function()
var iZmax, iZTop, iZBottom, iZLow, iZHigh, zIndexScreen
	iZmax=2000000;
	iZTop=iZmax;
	iZBottom = 10;
	iZLow = 1000;
	iZHigh = 1500000;
	zIndexScreen = 10000;
	
function GeneratePopup(sName, sParent, iTop, iLeft, iWidth, iHeight, iHeadHeight, sHeadContent, iStripHeight, sStripContent, iBodyHeight, iFootHeight, sFootContent, iLeftBarWidth, sLeftBarContent, iScrollWidth, sScrollContent, sScrollType, iRightBarWidth, sRightBarContent, sBackContent, sVisible, iZIndex) {
		var iStripTop, iBodyTop, iFootTop, iScrollLeft, iRightBarLeft, sBackDiv

		// zIndex
		if (iZIndex==null) {
			iZIndex = zIndexScreen;
		}

		// Perform Layer Analysis 
		iStripTop = iHeadHeight
		iBodyTop = iStripTop + iStripHeight
		iFootTop = iBodyTop + iBodyHeight
		iScrollLeft = iLeftBarWidth
		iRightBarLeft = iScrollLeft + iScrollWidth
		
		// Create Base Layer
		sBackDiv = sName + 'BackDiv'
		createLayer(sBackDiv,sParent,iLeft,iTop,iWidth,iHeight,sBackContent,null,sVisible, iZIndex);
		if (sParent!=null) {
			eval(sName+' = new DynLayer("'+sBackDiv+'", "'+ sParent +'")'); }
		else {
			eval(sName+' = new DynLayer("'+sBackDiv+'")'); }
		eval( sName+'.Popup = \'1\' ' );
		eval( sName+'.PopupName = \''+sName+'\' ' );		
		eval( sName+'.PopupType = \'GENERIC\' ' );
		if (document.all) {
			}
		else {
			eval( sName+'.zLow()')
		}
		
		// Set Popup Parameters & Create Layers
		// Create Head Layer
		if (iHeadHeight > 0) { 
			var sHeadDiv = sName + 'HeadDiv';
			var sHeadName = sName + 'Head';			
			eval( sName+'.HeadLayer = \'1\' ' );	
			createLayer(sHeadDiv,sBackDiv,0,0,iWidth,iHeadHeight,sHeadContent);
			eval(sHeadName+' = new DynLayer("'+sHeadDiv+'", "'+ sBackDiv +'")');
		}
		else {
			eval( sName+'.HeadLayer = \'0\' ' );
		}
		// Create Strip Layer
		if (iStripHeight > 0) { 
			var sStripDiv = sName + 'StripDiv';
			var sStripName = sName + 'Strip';
			createLayer(sStripDiv,sBackDiv,0,iStripTop,iWidth,iStripHeight,sStripContent);
			eval(sStripName+' = new DynLayer("'+sStripDiv+'", "'+ sBackDiv +'")');
			eval( sName+'.StripLayer = \'1\' ' );	
		}
		else {
			eval( sName+'.StripLayer = \'0\' ' );
		}
		// Create Left Side Layer
		if (iLeftBarWidth > 0) { 
			var sLeftBarDiv = sName + 'LeftBarDiv';
			var sLeftBarName = sName + 'LeftBar';			
			createLayer(sLeftBarDiv,sBackDiv,0,iBodyTop,iLeftBarWidth,iBodyHeight,sLeftBarContent);
			eval(sLeftBarName+' = new DynLayer("'+sLeftBarDiv+'", "'+ sBackDiv +'")');
			eval( sName+'.LeftBarLayer = \'1\' ' );	
		}
		else {
			eval( sName+'.LeftBarLayer = \'0\' ' );
		}
		// Create Scroll Layer
		if (iScrollWidth > 0) { 
		
			var sScrollContentDiv = sName + 'ScrollContentDiv';
			var sScrollContentName = sName + 'ScrollContent';			
			var sScrollWindowDiv = sName + 'ScrollWindowDiv';
			var sScrollWindowName = sName + 'ScrollWindow';
			var sScrollName = sName + 'Scroll';	
			
			switch (sScrollType) {
				case 'V': 
				{ 
					// Verticle Scroll
					// Scroll Window Layer
					createLayer(sScrollWindowDiv,sBackDiv, iScrollLeft,iBodyTop,iScrollWidth, iBodyHeight,'');
					eval(sScrollWindowName+' = new DynLayer("'+sScrollWindowDiv+'", "'+ sBackDiv +'")');

					// Scroll Content Layer
					if (document.all) {
											createLayer(sScrollContentDiv,sScrollWindowDiv, 0, 0,iScrollWidth, 5000, sScrollContent);
											eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sScrollWindowDiv +'")');
					}
					else {
						createNsNestedLayer(sScrollContentDiv, sBackDiv, sScrollWindowDiv, 0, 0,iScrollWidth, 5000, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sBackDiv +'.document.'+sScrollWindowDiv +'")');						
					}
					

					// Create Scroll Window
					eval(sScrollName + "= new MiniScroll("+sScrollWindowName+", "+sScrollContentName+")");
					break;
				} 
				case 'H': 
				{ 
					// Horizontal Scroll
					// Scroll Window Layer
					createLayer(sScrollWindowDiv, sBackDiv, iScrollLeft, iBodyTop, iScrollWidth, iBodyHeight,'');
					eval(sScrollWindowName+' = new DynLayer("'+sScrollWindowDiv+'", "'+ sBackDiv +'")');

					// Scroll Content Layer
					if (is.ns) {
						createNsNestedLayer(sScrollContentDiv, sBackDiv, sScrollWindowDiv, 0, 0, 3400, iBodyHeight, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sBackDiv +'.document.'+sScrollWindowDiv +'")');						
					}
					else {
						createLayer(sScrollContentDiv, sScrollWindowDiv, 0, 0, 3400, iBodyHeight, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sScrollWindowDiv +'")');
					}

					// Create Scroll Window
					eval(sScrollName + "= new MiniScroll("+sScrollWindowName+", "+sScrollContentName+")");
					
					break;
				} 
				case 'B': 
				{ 
					// Both Scroll
					// Scroll Window Layer
					createLayer(sScrollWindowDiv, sBackDiv, iScrollLeft, iBodyTop, iScrollWidth, iBodyHeight,'');
					eval(sScrollWindowName+' = new DynLayer("'+sScrollWindowDiv+'", "'+ sBackDiv +'")');

					if (is.ns) {
						createNsNestedLayer(sScrollContentDiv, sBackDiv, sScrollWindowDiv, 0, 0, 600, 600, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sBackDiv +'.document.'+sScrollWindowDiv +'")');						
					}
					else {
						createLayer(sScrollContentDiv, sScrollWindowDiv, 0, 0, 600, 600, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sScrollWindowDiv +'")');
					}

					// Create Scroll Window
					eval(sScrollName + "= new MiniScroll("+sScrollWindowName+", "+sScrollContentName+")");
					
					break;
				}
				default: 
				{ 
					// Both Scroll
					// Scroll Window Layer
					createLayer(sScrollWindowDiv, sBackDiv, iScrollLeft, iBodyTop, iScrollWidth, iBodyHeight,'');
					eval(sScrollWindowName+' = new DynLayer("'+sScrollWindowDiv+'", "'+ sBackDiv +'")');

					if (is.ns) {
						createNsNestedLayer(sScrollContentDiv, sBackDiv, sScrollWindowDiv, 0, 0, 600, 600, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sBackDiv +'.document.'+sScrollWindowDiv +'")');						
					}
					else {
						createLayer(sScrollContentDiv, sScrollWindowDiv, 0, 0, 600, 600, sScrollContent);
						eval(sScrollContentName+' = new DynLayer("'+sScrollContentDiv+'", "'+ sScrollWindowDiv +'")');
					}

					// Create Scroll Window
					eval(sScrollName + "= new MiniScroll("+sScrollWindowName+", "+sScrollContentName+")");
					
					break;
				} // default */
			} // Switch
			eval( sName+'.ScrollLayer = \'1\' ' );	
		}
		else {
			eval( sName+'.ScrollLayer = \'0\' ' );
		}
		// Create Right Layer
		if (iRightBarWidth > 0) { 
			var sRightBarDiv = sName + 'RightBarDiv';
			var sRightBarName = sName + 'RightBar';			
			createLayer(sRightBarDiv,sBackDiv,iRightBarLeft,iBodyTop,iRightBarWidth,iBodyHeight,sRightBarContent);
			eval(sRightBarName+' = new DynLayer("'+sRightBarDiv+'", "'+ sBackDiv +'")');
			eval( sName+'.RightBarLayer = \'1\' ' );	
		}
		else {
			eval( sName+'.RightBarLayer = \'0\' ' );
		}
		// Create Foot Layer
		if (iFootHeight > 0) { 
			var sFootDiv = sName + 'FootDiv';
			var sFootName = sName + 'Foot';			
			createLayer(sFootDiv,sBackDiv,0,iFootTop,iWidth,iFootHeight,sFootContent);
			eval(sFootName+' = new DynLayer("'+sFootDiv+'", "'+ sBackDiv +'")');
			eval( sName+'.FootLayer = \'1\' ' );	
		}
		else {
			eval( sName+'.FootLayer = \'0\' ' );
		}
	
		if (document.layers) {	
			if (sVisible=='visible') {
				eval( sName+'.pshow()');
			}
		}
}

function GeneratePopupScrollUp(sName, iWidth, iHeight, sContent, sImage) {

	var sUp,sScrollName
	sScrollName = sName + "Scroll"
	sUp = '<A HREF="#" onFocus="parent.focus();" onMouseDown="javascript:'+sScrollName+'.up();" onMouseUp="javascript:'+sScrollName+'.stop()">';
	if ((sImage==null) || (sImage=='')) {
		sImage='../Images/Browser/empty.gif'
	}
	sUp += '<IMG SRC="'+sImage+'" onMouseDown="ScrollUpDown()" onMouseUp="ScrollUpUp();" BORDER="0" WIDTH="'+iWidth+'" HEIGHT="'+iHeight+'" ALT="Scroll Up" NAME="img'+sName+'ScrollUp">';
	sUp += sContent;
	sUp += '</A>';
	//alert(sUp);
	return sUp
}
function test (s) {
alert ('asdf' + s)
}
function GeneratePopupScrollDown(sName, iWidth, iHeight, sContent, sImage) { 
	var sDown,sScrollName
	
	//ButtonsScrollLayerScroll  ScrollImageDown(sImage);  ScrollImageUp(sImage);
	
	sScrollName = sName + "Scroll"
	//alert(sScrollName);
	//alert(sImage);
	sDown = '<A HREF="#" onFocus="parent.focus();" onMouseDown="javascript:'+sScrollName+'.down();" onMouseUp="javascript:'+sScrollName+'.stop();" >';
	//sDown = '<A HREF="#" onFocus="parent.focus();" onMouseDown="javascript:test('+sScrollName+');" onMouseUp="javascript:'+sScrollName+'.stop();" >';
	if ((sImage==null) || (sImage=='')) {
		sImage='../Images/Browser/empty.gif'
	}
	sDown += '<IMG SRC="'+sImage+'" ALT="Scroll Down" onMouseDown="ScrollDownDown()" onMouseUp="ScrollDownUp();" BORDER="0" WIDTH="'+iWidth+'" HEIGHT="'+iHeight+'" NAME="img'+sName+'ScrollDown">';
	sDown += sContent;
	sDown += '</A>';
	//alert(sDown)
	return sDown
}

function createLayer(id,nestref,left,top,width,height,content,bgColor,visibility,zIndex) {
	if (document.all) {
			var str = '\n<DIV id='+id+' style="position:absolute; left:'+left+'; top:'+top+'; width:'+width
			if (height!=null) {
				str += '; height:'+height
				str += '; clip:rect(0,'+width+','+height+',0)'
			}
			if (bgColor!=null) str += '; background-color:'+bgColor		
			if (zIndex!=null) str += '; z-index:'+zIndex
			if (visibility) str += '; visibility:'+visibility
			str += ';">'+((content)?content:'')+'</DIV>'
			if (nestref) {
				index = nestref.lastIndexOf(".")
				var nestlyr = (index != -1)? nestref.substr(index+1) : nestref
				document.all[nestlyr].insertAdjacentHTML("BeforeEnd",str);
			}
			else {
				document.body.insertAdjacentHTML("BeforeEnd",str)
			}
	}
	else {
		if (nestref) {
			var lyr = eval("document."+nestref+".document."+id+" = new Layer(width, document."+nestref+")")
		}
		else {
			var lyr = document.layers[id] = new Layer(width)
			eval("document."+id+" = lyr")
		}
		lyr.name = id
		lyr.left = left
		lyr.top = top
		if (height!=null) lyr.clip.height = height
		if (bgColor!=null) lyr.bgColor = bgColor
		lyr.visibility = 'hide'		
		// lyr.visibility = (visibility=='hidden')? 'hide' : 'show'
		if (zIndex!=null) lyr.zIndex = zIndex
		if (content) {
			lyr.document.open()
			lyr.document.write(content)
			lyr.document.close()
		}
	}
	
}

function DynLayer(id,nestref,frame) {
	if (!DynLayer.set && !frame) DynLayerInit()
	this.frame = frame || self
	if (document.all) {
				this.elm = this.event = this.frame.document.all[id]
				this.css = this.frame.document.all[id].style
				this.doc = document
				this.x = this.elm.offsetLeft
				this.y = this.elm.offsetTop
				this.w = (document.all)? this.css.pixelWidth : this.elm.offsetWidth
				this.h = (document.all)? this.css.pixelHeight : this.elm.offsetHeight 
				
				
		}
	else {
		if (is.ns4) {
			if (!frame) {
				if (!nestref) var nestref = DynLayer.nestRefArray[id]
				if (!DynLayerTest(id,nestref)) return
				this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
			}
			else this.css = (nestref)? eval("frame.document."+nestref+".document."+id) : frame.document.layers[id]
			this.elm = this.event = this.css
			this.doc = this.css.document
		}
		if (is.ns5) {
			this.elm = document.getElementById(id)
			this.css = this.elm.style
			this.doc = document
		}
		this.x = this.css.left
		this.y = this.css.top
		this.w = this.css.clip.width
		this.h = this.css.clip.height
	}
	
	this.id = id
	this.nestref = nestref
	this.obj = id + "DynLayer"
	this.zFloat = 0; // - SPYDA
	this.dRestrict = 0;	// - SPYDA
	this.obj.zIndex = zIndexScreen++;
	eval(this.obj + "=this")
}

function DynLayerInit(nestref) {
	if (!DynLayer.set) DynLayer.set = true
	if (document.all) {
			for (var i=0; i<document.all.tags("DIV").length; i++) {
				var divname = document.all.tags("DIV")[i].id
				var index = divname.indexOf("Div")
				if (index > 0) {
					eval(divname.substr(0,index)+' = new DynLayer("'+divname+'")')
				}
			}
	}
	else {
		if (nestref) ref = eval('document.'+nestref+'.document')
		else {nestref = ''; ref = document;}
		for (var i=0; i<ref.layers.length; i++) {
			var divname = ref.layers[i].name
			DynLayer.nestRefArray[divname] = nestref
			var index = divname.indexOf("Div")
			if (index > 0) {
				eval(divname.substr(0,index)+' = new DynLayer("'+divname+'","'+nestref+'")')
			}
			if (ref.layers[i].document.layers.length > 0) {
				DynLayer.refArray[DynLayer.refArray.length] = (nestref=='')? ref.layers[i].name : nestref+'.document.'+ref.layers[i].name
			}
		}
		if (DynLayer.refArray.i < DynLayer.refArray.length) {
			DynLayerInit(DynLayer.refArray[DynLayer.refArray.i++])
		}
	}
	
	return true
}

function createLayer(id,nestref,left,top,width,height,content,bgColor,visibility,zIndex) {
	if (document.all) {
			var str = '\n<DIV id='+id+' style="position:absolute; left:'+left+'; top:'+top+'; width:'+width
			if (height!=null) {
				str += '; height:'+height
				str += '; clip:rect(0,'+width+','+height+',0)'
			}
			if (bgColor!=null) str += '; background-color:'+bgColor		
			if (zIndex!=null) str += '; z-index:'+zIndex
			if (visibility) str += '; visibility:'+visibility
			str += ';">'+((content)?content:'')+'</DIV>'
			if (nestref) {
				index = nestref.lastIndexOf(".")
				var nestlyr = (index != -1)? nestref.substr(index+1) : nestref
				document.all[nestlyr].insertAdjacentHTML("BeforeEnd",str);
			}
			else {
				document.body.insertAdjacentHTML("BeforeEnd",str)
			}
	}
	else {
		if (nestref) {
			var lyr = eval("document."+nestref+".document."+id+" = new Layer(width, document."+nestref+")")
		}
		else {
			var lyr = document.layers[id] = new Layer(width)
			eval("document."+id+" = lyr")
		}
		lyr.name = id
		lyr.left = left
		lyr.top = top
		if (height!=null) lyr.clip.height = height
		if (bgColor!=null) lyr.bgColor = bgColor
		lyr.visibility = 'hide'		
		// lyr.visibility = (visibility=='hidden')? 'hide' : 'show'
		if (zIndex!=null) lyr.zIndex = zIndex
		if (content) {
			lyr.document.open()
			lyr.document.write(content)
			lyr.document.close()
		}
	}
	
}

function MiniScroll(window,content) {
	this.window = window
	this.content = content
	this.content.slideInit()
	this.inc = 8
	this.speed = 20
	this.contentHeight = (document.layers)? this.content.doc.height : this.content.elm.scrollHeight
	this.contentWidth = (document.layers)? this.content.doc.width : this.content.elm.scrollWidth
	this.up = MiniScrollUp
	this.home = MiniScrollHome
	this.down = MiniScrollDown
	this.left = MiniScrollLeft
	this.right = MiniScrollRight
	this.stop = MiniScrollStop
	this.activate = MiniScrollActivate
	this.activate(this.contentWidth,this.contentHeight)
}

function MiniScrollActivate(w,h) {

	this.offsetHeight = h-this.window.h
	this.offsetWidth = w-this.window.w
	
	//alert(' this.offsetHeight = ' + this.offsetHeight )
	//alert(' this.offsetWidth = ' + this.offsetWidth )
	this.enableVScroll = (this.offsetHeight>0)
	this.enableHScroll = (this.offsetWidth>0)
}
function MiniScrollUp() {
	//if (this.enableVScroll) this.content.slideTo(null,0,this.inc,this.speed)
	this.content.slideTo(null,0,this.inc,this.speed)
}
function MiniScrollDown() {
//alert(this.enableVScroll)
	//if (this.enableVScroll) this.content.slideTo(null,-this.offsetHeight,this.inc,this.speed)
	//this.content.slideTo(null,-this.offsetHeight,this.inc,this.speed)
	this.content.slideTo(null,-245,this.inc,this.speed)
}
function MiniScrollLeft() {
	if (this.enableHScroll) this.content.slideTo(0,null,this.inc,this.speed)
}
function MiniScrollRight() {
	if (this.enableHScroll) this.content.slideTo(-this.offsetWidth,null,this.inc,this.speed)
}
function MiniScrollStop() {
	this.content.slideActive = false
}
function MiniScrollHome() {
	if (this.enableVScroll) this.content.slideTo(null,0,1000,1000)
	if (this.enableHScroll) this.content.slideTo(0,null,1000,1000)
}

// Slide Methods
function DynLayerSlideTo(endx,endy,inc,speed,fn) {
	if (endx==null) endx = this.x
	if (endy==null) endy = this.y
	var distx = endx-this.x
	var disty = endy-this.y
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DynLayerSlideBy(distx,disty,inc,speed,fn) {
	var endx = this.x + distx
	var endy = this.y + disty
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DynLayerSlideStart(endx,endy,distx,disty,inc,speed,fn) {
	if (this.slideActive) return
	if (!inc) inc = 10
	if (!speed) speed = 20
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc
	if (num==0) return
	var dx = distx/num
	var dy = disty/num
	if (!fn) fn = null
	this.slideActive = true
	this.slide(dx,dy,endx,endy,num,1,speed,fn)
}
function DynLayerSlide(dx,dy,endx,endy,num,i,speed,fn) {
	if (!this.slideActive) return
	if (i++ < num) {
		this.moveBy(dx,dy)
		this.onSlide()
		if (this.slideActive) setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed)
		else this.onSlideEnd()
	}
	else {
		this.slideActive = false
		this.moveTo(endx,endy)
		this.onSlide()
		this.onSlideEnd()
		eval(fn)
	}
}
DynLayerSlideInit = new Function()
DynLayer.prototype.slideInit = new Function()
DynLayer.prototype.slideTo = DynLayerSlideTo
DynLayer.prototype.slideBy = DynLayerSlideBy
DynLayer.prototype.slideStart = DynLayerSlideStart
DynLayer.prototype.slide = DynLayerSlide
DynLayer.prototype.onSlide = new Function()
DynLayer.prototype.onSlideEnd = new Function()

function DynLayerMoveTo(x,y) {
		if (this.dRestrict==1) {
			// Drag Restrict Enabled - SPYDA
			var iDLeft, iDTop, iDRight, iDBottom
			iDLeft = this.dLeft
			iDRight = this.dRight - this.w
			iDTop = this.dTop
			iDBottom = this.dBottom - this.h
			if (x!=null) {
				// Check Right - SPYDA
				if (x>iDRight) {
					x = iDRight;}
				// Check Left - SPYDA
				if (x<iDLeft) {
					x = iDLeft;}
				// Perform Move
				this.x = x
				if (is.ns) this.css.left = this.x
				else this.css.pixelLeft = this.x
			}
			if (y!=null) {
				// Check Top - SPYDA
				if (y<iDTop) {
					y = iDTop;}
				// Check Bottom - SPYDA
				if (y>iDBottom) {
					y = iDBottom;}
				this.y = y
				if (is.ns) this.css.top = this.y
				else this.css.pixelTop = this.y
			}
		}
		else {
			if (x!=null) {
				this.x = x
				if (document.layers) this.css.left = this.x
				else this.css.pixelLeft = this.x
			}
			if (y!=null) {
				this.y = y
				if (document.layers) this.css.top = this.y
				else this.css.pixelTop = this.y
			}
		}	
}

function DynLayerMoveBy(x,y) {
	this.moveTo(this.x+x,this.y+y)
}
function DynLayerShow() {
	this.css.visibility = (is.ns)? "show" : "visible"
}
function DynLayerHide() {
		this.css.visibility = (is.ns)? "hide" : "hidden"
}
// Spyda Popup Shortcuts
function DynLayerPHide() {
	PopupHide(this.PopupName);
}	
function DynLayerPShow() {
	PopupShow(this.PopupName);
}	

DynLayer.prototype.moveTo = DynLayerMoveTo
DynLayer.prototype.moveBy = DynLayerMoveBy
DynLayer.prototype.show = DynLayerShow
DynLayer.prototype.hide = DynLayerHide
DynLayerTest = new Function('return true')
DynLayer.prototype.pshow = DynLayerPShow
DynLayer.prototype.phide = DynLayerPHide
	