﻿/* 
fleXcroll v1.8.5
This license text has to stay intact at all times:
fleXcroll Public License Version
Cross Browser Custom Scroll Bar Script by Hesido.
Public version - Free for non-commercial uses.

This script cannot be used in any commercially built
web sites, or in sites that relates to commercial
activities. This script is not for re-distribution.
For licensing options:
Contact Emrah BASKAYA @ www.hesido.com

Derivative works are only allowed for personal uses,
and they cannot be redistributed.

FleXcroll Public Key Code: 20050907122003339
MD5 hash for this license: 9ada3be4d7496200ab2665160807745d

End of license text---
*/

/*
use code like this:
var scrollingDiv=document.getElementById('horizontalscroll');
scrollingDiv.contentScroll('1s',false,true);
on any button that you want to use as a scrolling button.
*/

function CSBfleXcroll(targetId){
	arrowStyle = "";
	fleXcrollWithOptions(targetId,arrowStyle,true)
};

function scrollToTop(targetId) {
	if ( 	!document.getElementById  //if getElementById is not defined
			|| document.getElementById(targetId) == null //or if the id entered is not in the document.
		) {
		return true;
	} else if ( !document.createElement //if document.createElement is not defined
				|| ( navigator.userAgent.indexOf('Safari') != -1 && !(typeof(HTMLElement) != "undefined" && HTMLElement.prototype) )
				|| navigator.vendor == 'KDE'
				|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Netscape') != -1) // try to fix netscape for mac
				|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('MSIE') != -1 ) //ie for mac, not supported
	) { 
		//todo scroll handle anchor scrolling in
		var scrollingDiv = document.getElementById(targetId);
		scrollingDiv.scrollTop = 0;
		return false;
	} else {	
		var scrollingDiv = document.getElementById(targetId);
		scrollingDiv.contentScroll(false,'-100p',true);
		return false;
	};
}

function scrollToAnchor(divId, targetId) {
	//stop execution if this won't be supported
	if ( 	!document.getElementById  //if getElementById is not defined
			|| document.getElementById(divId) == null //or if the id entered is not in the document.
			|| document.getElementById(targetId) == null //or if the id entered is not in the document.			
		) {
		return true;
	} else {
		var obj = document.getElementById(targetId);
		anchorPos = obj.offsetTop;
		while ( obj = obj.offsetParent ) {
			anchorPos += obj.offsetTop;
		}
		
		var scrollingDiv = document.getElementById(divId);
		obj = scrollingDiv;
		divPos = obj.offsetTop;
	//	alert("div " + divPos);		
		while ( obj = obj.offsetParent ) {
			divPos += obj.offsetTop;
		}
	
		scrollAmount = anchorPos - divPos - 15;
		if (scrollAmount < 0) {
			return true;
		}

		if (	(!document.createElement //if document.createElement is not defined
				|| navigator.userAgent.indexOf('Safari') != -1 && !(typeof(HTMLElement) != "undefined" && HTMLElement.prototype) )
				|| navigator.vendor == 'KDE'
				|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('MSIE') != -1 ) //ie for mac, not supported
				|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Netscape') != -1) // try to fix netscape for mac
		) { 
			scrollingDiv.scrollTop = scrollAmount;
		} else {
			scrollingDiv.contentScroll(false,'' + scrollAmount + '',true);
			
		};
		return false;
	};
}
	

function fleXcrollWithOptions (targetId,arrowStyle,noHorizontal) {
	//stop execution if this won't be supported
	if( !document.getElementById  //if getElementById is not defined
	    || document.getElementById(targetId) == null //or if the id entered is not in the document.
		|| !document.createElement //if document.createElement is not defined
		|| ( navigator.userAgent.indexOf('Safari') != -1 && !(typeof(HTMLElement) != "undefined" && HTMLElement.prototype) )
		|| navigator.vendor == 'KDE'
		|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('MSIE') != -1)
		|| ( navigator.platform.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Netscape') != -1) // try to fix netscape for mac
	) { //ie for mac, not supported
			return
	};
	
	if ( noHorizontal == null ) { noHorizontal = false };
	arrowsAtEnd = false;
	noArrows = false;
	
	if (arrowStyle == "" ) {
		//normal style
	} else if ( arrowStyle == "atBottom" ) {
		arrowsAtEnd = true;
	} else if ( arrowStyle == "none" ) {
		noArrows = true;
	}
	

	var scrollingDiv = document.getElementById(targetId);
	
	//stop execution if this function was already run
	if( scrollingDiv.fleXcroll ) return;
	
	scrollingDiv.fleXdata = new Object();

	var sC = scrollingDiv.fleXdata;
	
	//assign actions to various key strokes.
	sC.keyAct = {
		_37:['-1s',0], 		//left
		_38:[0,'-1s'], 		//up
		_39:['1s',0],		//right
		_40:[0,'1s'],		//down
		_33:[0,'-1p'],		//page up
		_34:[0,'1p'],		//page down
		_36:[0,'-100p'],	//home
		_35:[0,'+100p']		//end
	};
	
	sC.wheelAct = ["-2s", "2s"];
	sC.baseAct = ["-" + 10/9 + "p", 10/9 + "p"];
	sC.ArrowAct = ["-1s", "1s"];


	var theContentWrapper = createDiv('contentwrapper', true);
	var mDv = createDiv('mcontentwrapper', true);
	var theScrollBarWrapper = createDiv('scrollwrapper', true);
	var pDv = createDiv('copyholder', true);
	var iDv = createDiv('domfixdiv', true);
	var fDv = createDiv('zoomdetectdiv', true);
	

	pDv.sY.border = '1px solid blue';
	pDv.fHide();

	scrollingDiv.style.overflow = 'hidden';

	fDv.sY.fontSize = "12px";
	fDv.sY.height = "1em";
	fDv.sY.width = "1em";
	fDv.sY.position = "absolute";
	fDv.sY.zIndex = "-999";
	fDv.fHide();
	
	var brdHeight = scrollingDiv.offsetHeight;
	var brdWidth = scrollingDiv.offsetWidth;

	copyStyles(scrollingDiv, pDv,'0px', ['border-left-width', 'border-right-width', 'border-top-width', 'border-bottom-width']);
	
	var intlHeight = scrollingDiv.offsetHeight;
	var intlWidth = scrollingDiv.offsetWidth;
	var brdWidthLoss = brdWidth - intlWidth;
	var brdHeightLoss = brdHeight - intlHeight;
	var oScrollY = (scrollingDiv.scrollTop)
					? scrollingDiv.scrollTop
					: 0;
	var oScrollX = (scrollingDiv.scrollLeft)
					? scrollingDiv.scrollLeft
					: 0;
	var focusProtectList = ['textarea', 'input', 'select'];
	
	sC.scroller = [];
	sC.forcedBar = [];
	sC.containerSize = sC.cntRSize = [];
	sC.contentSize = sC.cntSize = [];
	sC.edge = [false, false];
	sC.reqS = [];
	sC.barSpace = [0, 0];
	sC.forcedHide = [];
	sC.forcedPos = [];
	sC.paddings = [];
	
	while(scrollingDiv.firstChild){
		theContentWrapper.appendChild(scrollingDiv.firstChild)
	};
	
	theContentWrapper.appendChild(iDv);
	scrollingDiv.appendChild(mDv);
	scrollingDiv.appendChild(pDv);
	
	if( getStyle(scrollingDiv, 'position') != 'absolute' ) {
		scrollingDiv.style.position = "relative"
	};
	
	mDv.sY.width = "100px";
	mDv.sY.height = "100px";
	mDv.sY.top = "0px";
	mDv.sY.left = "0px";
	
	copyStyles(scrollingDiv, pDv, "0px", ['padding-left', 'padding-top', 'padding-right', 'padding-bottom']);
	var postWidth = scrollingDiv.offsetWidth;
	var postHeight = scrollingDiv.offsetHeight

		//stdMode is a check to see if the border contributes to the height/width of a div, if so, we need to compensate for it
	stdMode = false;

	var mHeight = mDv.offsetHeight;
	mDv.sY.borderBottom = "2px solid black";
	//if the offsetHeight changes with the insertion of a border, then we need to set stdMode = true
	if ( mDv.offsetHeight > mHeight ) {
		stdMode = true
	};
	
	mDv.sY.borderBottomWidth = "0px";
	copyStyles(pDv, scrollingDiv, false, ['padding-left', 'padding-top', 'padding-right', 'padding-bottom']);
	
	findPos(mDv);
	findPos(scrollingDiv);
	
	sC.paddings[0] = mDv.yPos - scrollingDiv.yPos;
	sC.paddings[2] = mDv.xPos - scrollingDiv.xPos;
	
	scrollingDiv.style.paddingTop = getStyle(scrollingDiv, "padding-bottom");
	scrollingDiv.style.paddingLeft = getStyle(scrollingDiv, "padding-right");
	
	findPos(mDv);
	findPos(scrollingDiv);
	
	sC.paddings[1] = mDv.yPos - scrollingDiv.yPos;
	sC.paddings[3] = mDv.xPos - scrollingDiv.xPos;
	scrollingDiv.style.paddingTop = getStyle(pDv,"padding-top");
	scrollingDiv.style.paddingLeft = getStyle(pDv,"padding-left");
	
	var padWidthComp = sC.paddings[2] + sC.paddings[3];
	var padHeightComp = sC.paddings[0] + sC.paddings[1];
	copyStyles( scrollingDiv, mDv,false,['padding-left','padding-right','padding-top','padding-bottom']);

	theScrollBarWrapper.sY.width=scrollingDiv.offsetWidth+'px';
	theScrollBarWrapper.sY.height=scrollingDiv.offsetHeight+'px';
	
	mDv.sY.width=postWidth+'px';
	mDv.sY.height=postHeight+'px';
	
	theScrollBarWrapper.sY.position='absolute';
	theScrollBarWrapper.sY.top='0px';
	theScrollBarWrapper.sY.left='0px';
	theScrollBarWrapper.fHide();
	
	mDv.appendChild(theContentWrapper);
	scrollingDiv.appendChild(theScrollBarWrapper);
	theScrollBarWrapper.appendChild(fDv);
	theContentWrapper.sY.position='relative';
	mDv.sY.position='relative';
	theContentWrapper.sY.top="0";
	theContentWrapper.sY.width="100%";
	mDv.sY.overflow='hidden';
	mDv.sY.left="-"+sC.paddings[2]+"px";
	mDv.sY.top="-"+sC.paddings[0]+"px";
	sC.zTHeight=fDv.offsetHeight;

	sC.getContentWidth = function(){
		var cChilds = theContentWrapper.childNodes;
		var maxCWidth = compPad = 0;
		for(var i=0; i < cChilds.length; i++) {
			if(cChilds[i].offsetWidth){
				maxCWidth = Math.max(cChilds[i].offsetWidth,maxCWidth)
			}		
		};

		//if there's a scroll bar then show add the offsetW
		sC.cntRSize[0] = ((sC.reqS[1] && !sC.forcedHide[1])
							|| sC.forcedBar[1])
								? scrollingDiv.offsetWidth - sC.barSpace[0]
								: scrollingDiv.offsetWidth;
		sC.cntSize[0] = maxCWidth + padWidthComp;
		return sC.cntSize[0]
	};
	
	sC.getContentHeight = function(){
		sC.cntRSize[1] = ((sC.reqS[0] && !sC.forcedHide[0]) || sC.forcedBar[0]) ? scrollingDiv.offsetHeight - sC.barSpace[1] : scrollingDiv.offsetHeight;
		sC.cntSize[1] = theContentWrapper.offsetHeight + padHeightComp - 2;
		return sC.cntSize[1]
	};
	sC.fixIEDispBug = function(){
		theContentWrapper.sY.display='none';
		theContentWrapper.sY.display='block'
	};


	sC.setWidth = function(){
		//stdMode is a check to see if the border contributes to the height/width of a div, if so, we need to compensate for it
		mDv.sY.width = (stdMode) ? (sC.cntRSize[0] - padWidthComp - brdWidthLoss) + 'px' : sC.cntRSize[0] + 'px'
	};
	
	sC.setHeight = function(){
		//stdMode is a check to see if the border contributes to the height/width of a div, if so, we need to compensate for it		
		mDv.sY.height = (stdMode) ? (sC.cntRSize[1] - padHeightComp - brdHeightLoss) + 'px' : sC.cntRSize[1] + 'px'
	};
	
	sC.createScrollBars = function(){
		sC.getContentWidth();
		sC.getContentHeight();
		theScrollBarWrapper.vrt = new Array();
		var vrT = theScrollBarWrapper.vrt;
		createTheScrollBars(vrT, 'vscroller');
		vrT.barPadding = [ parseInt(getStyle(vrT.theBar, 'padding-top')), parseInt(getStyle(vrT.theBar, 'padding-bottom'))];
		if ( arrowsAtEnd ) {
			vrT.barPadding[1] += vrT.barPadding[0];
			vrT.barPadding[0] = 0;
		};
		vrT.theBar.sY.padding = '0px';
		vrT.theBar.curPos = 0;
		vrT.theBar.vertical = true;
		vrT.theBar.indx = 1;
		theContentWrapper.vBar = vrT.theBar;
		prepareScroll(vrT, 0);
		sC.barSpace[0] = vrT.theBase.offsetWidth;
		sC.setWidth();
		theScrollBarWrapper.hrz = new Array();
		var hrZ = theScrollBarWrapper.hrz;
		createTheScrollBars(hrZ,'hscroller');
		hrZ.barPadding = [parseInt(getStyle(hrZ.theBar, 'padding-left')), parseInt(getStyle(hrZ.theBar, 'padding-right'))];
		if ( arrowsAtEnd ) {
			hrZ.barPadding[1] += hrZ.barPadding[0];
			hrZ.barPadding[0] = 0;
		};
		hrZ.theBar.sY.padding = '0px';
		hrZ.theBar.curPos = 0;
		hrZ.theBar.vertical = false;
		hrZ.theBar.indx = 0;
		theContentWrapper.hBar = hrZ.theBar;
		if(window.opera)hrZ.theBar.sY.position = 'relative';
		prepareScroll(hrZ,0);
		sC.barSpace[1] = hrZ.theBase.offsetHeight;
		sC.setHeight();
		theScrollBarWrapper.sY.height = scrollingDiv.offsetHeight+'px';
		hrZ.jBox = createDiv('scrollerjogbox');
		theScrollBarWrapper.appendChild(hrZ.jBox);
		hrZ.jBox.onmousedown =
			function(){
				hrZ.theBar.scrollBoth = true;
				sC.goScroll = hrZ.theBar;
				hrZ.theBar.clicked = true;
				hrZ.theBar.moved = false;
				theScrollBarWrapper.vrt.theBar.moved = false;
				addTrggr(document,'selectstart',retFalse);
				addTrggr(document,'mousemove',mMoveBar);
				addTrggr(document,'mouseup',mMouseUp);
				return false
			}
	};
	
	sC.goScroll=null;
	sC.createScrollBars();
	theContentWrapper.removeChild(iDv);
	if(!addChckTrggr(scrollingDiv,'mousewheel',mWheelProc)||!addChckTrggr(scrollingDiv,'DOMMouseScroll',mWheelProc)){
		scrollingDiv.onmousewheel=mWheelProc
	};
	
	scrollingDiv.setAttribute('tabIndex','0');
	
	addTrggr(scrollingDiv,'keydown',
		function(e){
			if(scrollingDiv.focusProtect)return;
			if(!e){
				var e=window.event
			};
			var pK = e.keyCode;
			sC.pkeY = pK;			
			if(sC.keyAct['_' + pK] && !window.opera) {
				scrollingDiv.contentScroll(sC.keyAct['_' + pK][0], sC.keyAct['_' + pK][1], true);
				if(e.preventDefault) e.preventDefault();
				return false
			}		
		}
	);
	
	addTrggr( scrollingDiv, 'keypress',
		function(e){
			if(scrollingDiv.focusProtect) return;
			if(!e) {
				var e = window.event
			};
			var pK = e.keyCode;
			if( sC.keyAct['_' + pK] ) {
				scrollingDiv.contentScroll(sC.keyAct['_' + pK][0], sC.keyAct['_' + pK][1], true);
				if(e.preventDefault) e.preventDefault();
				return false
			}			
		}
	);	
	
	addTrggr(scrollingDiv, 'keyup', function(){	sC.pkeY = false	} );
	
	addTrggr(document,'mouseup',intClear);
	
	addTrggr(scrollingDiv,'mousedown',function(e){
			if(!e) e = window.event;
			var cTrgt = (e.target)
							? e.target
							: (e.srcElement)
								? e.srcElement
								: false;
			
			if( !cTrgt || (cTrgt.className && cTrgt.className.match(RegExp("\\bscrollgeneric\\b")))) return;
			sC.inMposX = e.clientX;
			sC.inMposY = e.clientY;
			pageScrolled();
			findPos(scrollingDiv);
			intClear();
			addTrggr(document, 'mousemove', tSelectMouse);
			sC.mTBox=[scrollingDiv.xPos + 10,
					  scrollingDiv.xPos + sC.cntRSize[0] - 10,
					  scrollingDiv.yPos + 10,
					  scrollingDiv.yPos + sC.cntRSize[1] - 10]
		}
	);
	
	
	function tSelectMouse(e){
		if(!e) e = window.event;
		var mX = e.clientX;
		var mY = e.clientY;
		var mdX = mX + sC.xScrld;
		var mdY = mY + sC.yScrld;
		sC.mOnXEdge = (mdX < sC.mTBox[0] || mdX > sC.mTBox[1])? 1 : 0;
		sC.mOnYEdge = (mdY < sC.mTBox[2] || mdY > sC.mTBox[3])? 1 : 0;
		sC.xAw = mX - sC.inMposX;
		sC.yAw = mY - sC.inMposY;
		sC.sXdir = (sC.xAw > 40) ? 1
						: (sC.xAw < -40) ? -1 : 0;
		sC.sYdir = (sC.yAw > 40) ? 1
						: (sC.yAw < -40) ? -1 : 0;
						
		if ( (sC.sXdir != 0 || sC.sYdir != 0) && !sC.tSelectFunc) {
			sC.tSelectFunc = window.setInterval (
				function() {
					if(sC.sXdir == 0 && sC.sYdir == 0){
						window.clearInterval(sC.tSelectFunc);
						sC.tSelectFunc = false;
						return
					};
					pageScrolled();
					if (sC.mOnXEdge == 1 || sC.mOnYEdge == 1)
						scrollingDiv.contentScroll((sC.sXdir * sC.mOnXEdge) + "s", (sC.sYdir * sC.mOnYEdge) + "s", true)
				}
			,45)
		}
	}
	
	function intClear() {
		remTrggr(document, 'mousemove', tSelectMouse);
		if(sC.tSelectFunc) window.clearInterval(sC.tSelectFunc);
		
		sC.tSelectFunc = false;
		if(sC.barClickRetard) window.clearTimeout(sC.barClickRetard);
		if(sC.barClickScroll) window.clearInterval(sC.barClickScroll)
	}
	
	function pageScrolled() {
		sC.xScrld = (window.pageXOffset)
						?window.pageXOffset
						:(document.documentElement && document.documentElement.scrollLeft )
							? document.documentElement.scrollLeft
							: 0;
		sC.yScrld = (window.pageYOffset)
						? window.pageYOffset
						: (document.documentElement && document.documentElement.scrollTop)
							? document.documentElement.scrollTop
							: 0
	}
	
	scrollingDiv.scrollUpdate = function(recurse){
		if(theScrollBarWrapper.getSize[1]() === 0 || theScrollBarWrapper.getSize[0]() === 0)return;
		theContentWrapper.sY.padding = '1px';
		var reqH = sC.reqS[0];
		var reqV = sC.reqS[1];
		
		var vBr = theScrollBarWrapper.vrt;
		var hBr = theScrollBarWrapper.hrz;
		
		var vUpReq;
		var hUpReq;
		var cPSize = [];
		theScrollBarWrapper.sY.width = scrollingDiv.offsetWidth - brdWidthLoss + 'px';
		theScrollBarWrapper.sY.height = scrollingDiv.offsetHeight - brdHeightLoss + 'px';
		cPSize[0] = sC.cntRSize[0];
		cPSize[1] = sC.cntRSize[1];
		sC.reqS[0] = sC.getContentWidth() > sC.cntRSize[0];
		sC.reqS[1] = sC.getContentHeight() > sC.cntRSize[1];
		
		
		var stateChange = (reqH != sC.reqS[0] 
							   || reqV != sC.reqS[1]
							   || cPSize[0] != sC.cntRSize[0] 
							   || cPSize[1] != sC.cntRSize[1]
							) ? true:false;
		
		vBr.theBase.setVisibility(sC.reqS[1]);
		hBr.theBase.setVisibility(sC.reqS[0]);			

		vUpReq = (sC.reqS[1]||sC.forcedBar[1]);
		hUpReq = (sC.reqS[0]||sC.forcedBar[0]);
		sC.getContentWidth();
		sC.getContentHeight();
		sC.setHeight();
		sC.setWidth();
		
		if(!sC.reqS[0] || !sC.reqS[1] || sC.forcedHide[0] || sC.forcedHide[1]) hBr.jBox.fHide();
		else hBr.jBox.fShow();
		
		if(vUpReq) updateScroll(vBr, (hUpReq && !sC.forcedHide[0]) ? sC.barSpace[1] : 0);
		else theContentWrapper.sY.top = "0";
		
		if(hUpReq) updateScroll(hBr, (vUpReq && !sC.forcedHide[1]) ? sC.barSpace[0] : 0);
		else theContentWrapper.sY.left = "0";
		
		if(stateChange&&!recurse)scrollingDiv.scrollUpdate(true);
		theContentWrapper.sY.padding='0px'
	};
	
	scrollingDiv.commitScroll = scrollingDiv.contentScroll =
		function(xPos, yPos, relative){
			var reT = [[false, false],[false, false]];
			var Bar;
			
			//the horizontal scrolling
			if((xPos || xPos === 0) && sC.scroller[0]) {
				xPos = calcCScrollVal(xPos, 0);
				Bar = theScrollBarWrapper.hrz.theBar;
				Bar.trgtScrll = (relative) ? Math.min(Math.max(Bar.mxScroll, Bar.trgtScrll - xPos), 0) : -xPos;
				Bar.contentScrollPos();
				reT[0] = [-Bar.trgtScrll, -Bar.mxScroll]
			}
			
			//the vertical scrolling
			if((yPos || yPos === 0) && sC.scroller[1]){
				yPos = calcCScrollVal(yPos, 1);
				Bar = theScrollBarWrapper.vrt.theBar;
				Bar.trgtScrll = (relative) ? Math.min(Math.max(Bar.mxScroll, Bar.trgtScrll - yPos), 0) : -yPos;
				Bar.contentScrollPos();
				reT[1] = [-Bar.trgtScrll, -Bar.mxScroll]
			}
			
			return reT
		};
		
	copyStyles(pDv,scrollingDiv,'0px',['border-left-width','border-right-width','border-top-width','border-bottom-width']);
	scrollingDiv.removeChild(pDv);
	scrollingDiv.fleXcroll=true;
	scrollingDiv.scrollUpdate();
	scrollingDiv.contentScroll(oScrollX, oScrollY, true);
	theScrollBarWrapper.fShow();
	sC.sizeChangeDetect=window.setInterval(function(){
		var n=fDv.offsetHeight;
		if(n!=sC.zTHeight){
			scrollingDiv.scrollUpdate();
			sC.zTHeight=n
		}		
	}
	,2500);
	function calcCScrollVal(v,i){
		var stR=v.toString();
		v=parseFloat(stR);
		return parseInt ((stR.match(/p$/))
							? v * sC.cntRSize[i] * 0.9
							: (stR.match(/s$/))
								? v * sC.cntRSize[i] * 0.1
								: v )
	}
	function camelConv(spL){
		var spL=spL.split('-'),reT=spL[0],i;
		for(i=1; parT=spL[i]; i++){
			reT+=parT.charAt(0).toUpperCase()+parT.substr(1)
		}
		return reT
	}
	function getStyle(elem,style){
		if (window.getComputedStyle) return window.getComputedStyle(elem,null).getPropertyValue(style);
		
		if (elem.currentStyle) return elem.currentStyle[camelConv(style)];
		
		return false
	};
	
	function copyStyles(src,dest,replaceStr,sList){
		var camelList=new Array();
		for(var i=0;
		i<sList.length;
		i++){
			camelList[i]=camelConv(sList[i]);
			dest.style[camelList[i]]=getStyle(src,sList[i],camelList[i]);
			if(replaceStr)src.style[camelList[i]]=replaceStr
		}
		
	};
	
	function createDiv(typeName, noGenericClass) {
		var nDiv = document.createElement('div');
		nDiv.id = targetId + '_' + typeName;
		nDiv.className= (noGenericClass) ? typeName : typeName + ' scrollgeneric';
		nDiv.getSize = [
			function(){ return nDiv.offsetWidth }
			,function(){ return nDiv.offsetHeight }
		];
		nDiv.setSize = [
			function(sVal){ nDiv.sY.width = sVal }
			,function(sVal){ nDiv.sY.height = sVal }
		];
		nDiv.getPos = [
			function(){	return getStyle(nDiv,"left") }
			,function(){ return getStyle(nDiv,"top") }
		];
		nDiv.setPos = [
			function(sVal){ nDiv.sY.left = sVal }
			,function(sVal){ nDiv.sY.top = sVal }
		];
		nDiv.fHide=function(){ nDiv.sY.visibility="hidden" };
		nDiv.fShow=function(){ nDiv.sY.visibility="visible" };
		
		nDiv.sY=nDiv.style;
		return nDiv
	};
	
	function createTheScrollBars(ary,bse){
		ary.theBase = createDiv(bse + 'base');
		if (!noArrows) {
			ary.theBaseBeg = createDiv(bse + 'basebeg');
			ary.theBaseEnd = createDiv(bse + 'baseend');
		} else {
			ary.theBaseBeg = createDiv('basebeg');
			ary.theBaseEnd = createDiv('baseend');
		}
		ary.theBar = createDiv(bse + 'bar');
		ary.theBarBeg = createDiv(bse + 'barbeg');
		ary.theBarEnd = createDiv(bse + 'barend');
		
		theScrollBarWrapper.appendChild(ary.theBase);
		ary.theBase.appendChild(ary.theBar);
		ary.theBase.appendChild(ary.theBaseBeg);
		ary.theBase.appendChild(ary.theBaseEnd);
		ary.theBar.appendChild(ary.theBarBeg);
		ary.theBar.appendChild(ary.theBarEnd)
	};
	
	function prepareScroll(bAr,reqSpace){
		var theBase = bAr.theBase;
		var theBar = bAr.theBar;
		var i = theBar.indx;
		
		theBar.minPos = bAr.barPadding[0];
		theBar.ofstParent = theBase;
		theBar.mDv = mDv;
		theBar.scrlTrgt = theContentWrapper;
		theBar.targetSkew = 0;
		updateScroll(bAr, reqSpace, true);
		
		theBar.doScrollPos =
			function(){
				theBar.curPos = (Math.min(Math.max(theBar.curPos, 0), theBar.maxPos));
				theBar.trgtScrll = parseInt((theBar.curPos / theBar.sRange) * theBar.mxScroll);
				theBar.targetSkew = (theBar.curPos == 0) ? 0 : ( theBar.curPos == theBar.maxPos) ? 0 : theBar.targetSkew;
				theBar.setPos[i](theBar.curPos + theBar.minPos + "px");
				theContentWrapper.setPos[i](theBar.trgtScrll + theBar.targetSkew + "px")
			};
			
		theBar.contentScrollPos =
			function(){
				theBar.curPos = parseInt( (theBar.trgtScrll * theBar.sRange ) / theBar.mxScroll);
				theBar.targetSkew = theBar.trgtScrll - parseInt((theBar.curPos / theBar.sRange) * theBar.mxScroll);
				theBar.curPos = (Math.min(Math.max(theBar.curPos, 0), theBar.maxPos));
				theBar.setPos[i](theBar.curPos + theBar.minPos + "px");
				theBar.setPos[i](theBar.curPos + theBar.minPos + "px");
				theContentWrapper.setPos[i](theBar.trgtScrll + "px")
			};
			
		sC.barZ = getStyle(theBar, 'z-index');
		theBar.sY.zIndex = (sC.barZ == "auto" || sC.barZ == "0") ? 2 : sC.barZ;
		mDv.sY.zIndex = getStyle(theBar, 'z-index');
		
		theBar.onmousedown =
			function(){
				theBar.clicked = true;
				sC.goScroll = theBar;
				theBar.scrollBoth = false;
				theBar.moved = false;
				addTrggr(document, 'selectstart', retFalse);
				addTrggr(document, 'mousemove', mMoveBar);
				addTrggr(document, 'mouseup', mMouseUp);
				return false
			};
		
		theBar.onmouseover = intClear;

		theBase.onmousedown = theBase.ondblclick = function(e){
			if(!e){
				var e = window.event
			}
			
			if ( e.target && (e.target == bAr.theBarBeg
							  || e.target == bAr.theBarEnd
							  || e.target == bAr.theBar  )) return;
			if ( e.srcElement && (e.srcElement == bAr.theBarBeg
								  || e.srcElement == bAr.theBarEnd 
								  || e.srcElement == bAr.theBar )) return;
			
			var relPos;
			var mV=[];
			pageScrolled();
			theBar.mDv.scrollTop=0;
			theBar.mDv.scrollLeft=0;
			findPos(theBar);

			//relPos gets the click position plus Scrld (which is windowpageYOffSet) - the position of the bar
			relPos = (theBar.vertical)
					? e.clientY + sC.yScrld - theBar.yPos  //vertical scrollbar
					: e.clientX + sC.xScrld - theBar.xPos; //horizontal scrollbar
			mV[theBar.indx] = (relPos < 0) ? sC.baseAct[0] : sC.baseAct[1];
			mV[1-theBar.indx]=0;

			if ( (e.target && e.target == bAr.theBaseBeg) || (e.srcElement && e.srcElement == bAr.theBaseBeg) ) {
				mV[theBar.indx] = sC.ArrowAct[0];			
			}
			if ( (e.target && e.target == bAr.theBaseEnd) || (e.srcElement && e.srcElement == bAr.theBaseEnd) ) {
				mV[theBar.indx] = sC.ArrowAct[1];			
			}

			scrollingDiv.contentScroll(mV[0],mV[1],true);
			intClear();
			
			sC.barClickRetard = window.setTimeout(
				function(){
					sC.barClickScroll = window.setInterval(
						function(){
							scrollingDiv.contentScroll(mV[0], mV[1], true)
						}
					,80)
				}
			,425);
			
			return false
		};
		
		theBase.setVisibility = function(r) {
			if ( r ) {
				theBase.fShow();
				sC.forcedHide[i] = (getStyle(theBase, "visibility") == "hidden") ? true : false;
				
				if ( !sC.forcedHide[i] ) theBar.fShow();
				else theBar.fHide();
				sC.scroller[i]=true;
				classChange(theBase,"","flexinactive")
			} else {
				theBase.fHide();
				theBar.fHide();
				sC.forcedBar[i] = (getStyle(theBase, "visibility") != "hidden") ? true : false;
				sC.scroller[i] = false;
				theBar.curPos = 0;
				theContentWrapper.setPos[i]('0px');
				classChange(theBase,"flexinactive","")
			}			
			mDv.setPos[1-i] ( (sC.forcedPos[i] && (r || sC.forcedBar[i]) && !sC.forcedHide[i])
							? sC.barSpace[1 - i] - sC.paddings[i * 2] + "px"
							: "-" + sC.paddings[i * 2] + "px")
		};
		
		theBase.onmouseclick=retFalse
	};
	
	function updateScroll(bAr, reqSpace, firstRun){
		var theBase = bAr.theBase;
		var theBar = bAr.theBar;
		var theBaseBeg = bAr.theBaseBeg;
		var theBarBeg = bAr.theBarBeg;
		var theBaseEnd = bAr.theBaseEnd;
		var theBarEnd = bAr.theBarEnd;
		var i = theBar.indx;
		
		theBase.setSize[i](theScrollBarWrapper.getSize[i]() - reqSpace + 'px');
		theBase.setPos[1 - i](theScrollBarWrapper.getSize[1 - i]() - theBase.getSize[1 - i]() + 'px');		
		sC.forcedPos[i] = (parseInt(theBase.getPos[1 - i]()) === 0) ? true : false;
		
		bAr.padLoss = bAr.barPadding[0] + bAr.barPadding[1];
		bAr.baseProp = parseInt((theBase.getSize[i]() - bAr.padLoss) * 0.75);
		
		theBar.aSize = Math.min(Math.max(Math.min(parseInt(sC.cntRSize[i] / sC.cntSize[i] * theBase.getSize[i]()), bAr.baseProp), 45), bAr.baseProp);
		theBar.setSize[i](theBar.aSize + 'px');
		theBar.maxPos = theBase.getSize[i]()- theBar.getSize[i]()- bAr.padLoss;
		theBar.curPos = Math.min(Math.max(0, theBar.curPos), theBar.maxPos);
		theBar.setPos[i](theBar.curPos + theBar.minPos + 'px');
		theBar.mxScroll = mDv.getSize[i]() - sC.cntSize[i];
		
		theBar.sRange = theBar.maxPos;
		
		theBaseBeg.setSize[i](theBase.getSize[i]() - theBaseEnd.getSize[i]() + 'px');

		theBarBeg.setSize[i](theBar.getSize[i]() - theBarEnd.getSize[i]() + 'px');
		theBarEnd.setPos[i](theBar.getSize[i]() - theBarEnd.getSize[i]() + 'px');
		theBaseEnd.setPos[i](theBase.getSize[i]() - theBaseEnd.getSize[i]() + 'px');
		
		if ( arrowsAtEnd ) {
			theBaseBeg.setPos[i](theBase.getSize[i]() - theBaseEnd.getSize[i]() - theBaseBeg.getSize[i]() + 'px')
		};

		if( !firstRun ) theBar.doScrollPos();
		sC.fixIEDispBug()
	};
	
	addTrggr(window,'load',function(){
			if( scrollingDiv.fleXcroll ) scrollingDiv.scrollUpdate()
		}
	);
	
	addTrggr(window,'resize',function(){
			if (scrollingDiv.refreshTimeout) window.clearTimeout( scrollingDiv.refreshTimeout );
			scrollingDiv.refreshTimeout = window.setTimeout(function(){
					if( scrollingDiv.fleXcroll ) scrollingDiv.scrollUpdate()
				}
			,80)
		}
	);
	
	for(var j=0, inputName; inputName = focusProtectList[j] ; j++){
		var inputList = scrollingDiv.getElementsByTagName(inputName);
		for(var i=0, formItem; formItem = inputList[i] ; i++){
			addTrggr(formItem, 'focus',
				function(){
					scrollingDiv.focusProtect = true
				}
			);
			addTrggr(formItem, 'blur', onblur =
				function(){
					scrollingDiv.focusProtect = false
				}
			)
		}		
	};
	
	function retFalse(){
		return false
	};
	
	function mMoveBar(e) {
		if(!e){
			var e=window.event
		};
		var FCBar = sC.goScroll;
		var movBr;
		var maxx;
		var xScroll;
		var yScroll;
		if(FCBar == null) return;
		maxx = (FCBar.scrollBoth) ? 2 : 1;
		for(var i = 0; i < maxx; i++){
			movBr = (i == 1) ? FCBar.scrlTrgt.vBar : FCBar;
			if(FCBar.clicked){
				if(!movBr.moved){
					movBr.mDv.scrollTop = 0;
					movBr.mDv.scrollLeft = 0;
					findPos(movBr);
					findPos(movBr.ofstParent);
					movBr.pointerOffsetY = e.clientY - movBr.yPos;
					movBr.pointerOffsetX = e.clientX - movBr.xPos;
					movBr.inCurPos = movBr.curPos;
					movBr.moved = true
				};
				movBr.curPos = (movBr.vertical)
									? e.clientY - movBr.pointerOffsetY - movBr.ofstParent.yPos - movBr.minPos
									: e.clientX - movBr.pointerOffsetX - movBr.ofstParent.xPos - movBr.minPos;
									
				if ( FCBar.scrollBoth ) movBr.curPos = movBr.curPos + (movBr.curPos - movBr.inCurPos);
				movBr.doScrollPos()
			}
			else movBr.moved = false
		}
		
	};
	
	function mMouseUp() {
		if(sC.goScroll != null){
			sC.goScroll.clicked = false
		}
		sC.goScroll = null;
		remTrggr(document, 'selectstart', retFalse);
		remTrggr(document, 'mousemove', mMoveBar);
		remTrggr(document, 'mouseup', mMouseUp)
	};
	
	function mWheelProc(e){
		if(!e) e = window.event;
		if( !this.fleXcroll ) return;
		var scrDv = this;
		var vEdge;
		var hEdge;
		var hoverH = false;
		var delta = 0;
		var iNDx;
		
		hElem = (e.target) 
					? e.target
					: (e.srcElement)
						? e.srcElement
						: this;
						
		if (hElem.id && hElem.id.match(/_hscroller/)) hoverH = true;		
		if (e.wheelDelta) delta = -e.wheelDelta;		
		if (e.detail) delta = e.detail;
		

		delta = (delta < 0) ? -1 : +1;
		iNDx = (delta < 0) ? 0 : 1;
		
		sC.edge[1 - iNDx] = false;
		
		if( (sC.edge[iNDx] && !hoverH) || (!sC.scroller[0] && !sC.scroller[1]))
			return;		
		if( sC.scroller[1] && !hoverH )
			scrollState = scrollingDiv.contentScroll(false, sC.wheelAct[iNDx], true);
			
		vEdge = !sC.scroller[1] 
				|| hoverH 
				|| (sC.scroller[1]
						&& ((scrollState[1][0] == scrollState[1][1] && delta > 0)
							||(scrollState[1][0]==0&&delta<0)));
				
		if (sC.scroller[0] && (!sC.scroller[1] || hoverH))
			scrollState = scrollingDiv.contentScroll(sC.wheelAct[iNDx], false, true);
			
		hEdge = !sC.scroller[0]
				|| (sC.scroller[0] && sC.scroller[1] && vEdge && !hoverH) 
				|| (sC.scroller[0]
						&& ((scrollState[0][0] == scrollState[0][1] && delta>0)
							||(scrollState[0][0]==0 && delta<0)));
				
		if (vEdge && hEdge && !hoverH) sC.edge[iNDx] = true;	
		else sC.edge[iNDx] = false;
		
		if(e.preventDefault) e.preventDefault();
		return false
	};
	
	function addTrggr(elm, eventname, func){
		if(!addChckTrggr(elm, eventname, func) && elm.attachEvent){
			elm.attachEvent('on' + eventname,func)
		}
		
	};
	
	function addChckTrggr(elm, eventname, func){
		if(elm.addEventListener){
			elm.addEventListener(eventname, func, false);
			window.addEventListener("unload",
				function(){
					remTrggr(elm, eventname, func)
				}
			, false);
			return true
		}
		else return false
	};
	
	function remTrggr(elm,eventname,func){
		if(!remChckTrggr(elm,eventname,func)&&elm.detachEvent)elm.detachEvent('on'+eventname,func)
	};
	
	function remChckTrggr(elm,eventname,func){
		if(elm.removeEventListener){
			elm.removeEventListener(eventname,func,false);
			return true
		}
		else return false
	};
	
	function findPos(elem){
		var obj=elem,curleft=curtop=0;
		if(obj.offsetParent){
			while(obj){
				curleft+=obj.offsetLeft;
				curtop+=obj.offsetTop;
				obj=obj.offsetParent
			}		
		} else if(obj.x){
			curleft+=obj.x;
			curtop+=obj.y
		}
		elem.xPos=curleft;
		elem.yPos=curtop
	};
	
	function classChange(elem,addClass,remClass){
		if(!elem.className)elem.className='';
		var clsnm=elem.className;
		if(addClass&&!clsnm.match(RegExp("\\b"+addClass+"\\b")))clsnm=clsnm.replace(/(\S$)/,'$1 ')+addClass;
		if(remClass)clsnm=clsnm.replace(RegExp("(\\s*\\b"+remClass+"\\b(\\s*))*","g"),'$2');
		elem.className=clsnm	
	}
	return scrollingDiv;

};

