﻿//Start fleXcroll using any method you like, prefer to use external scripts to do this,
//This is for easy viewing of the method used to initialize the script.
if (document.getElementById && document.getElementsByTagName) {
if (window.addEventListener) window.addEventListener('load', initScrollBars, false);
else if (window.attachEvent) window.attachEvent('onload', initScrollBars);
}


function initScrollBars() {
CSBfleXcroll('test1');
CSBfleXcroll('test2');
CSBfleXcroll('test3');
}


//Demonstration functions for dynamic changes, not required for running fleXcroll.
function insertRemoveP(reMove) {
var targetEl = document.getElementById('dynamictest');
var scrollDiv = document.getElementById('test1');
if (targetEl == null || scrollDiv == null) return;

if (typeof(targetEl.parS) == 'undefined') targetEl.parS = new Array();
if (!reMove) {
targetEl.parS[targetEl.parS.length] = document.createElement('p');
targetEl.parS[targetEl.parS.length-1].appendChild(document.createTextNode('Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque ultrices facilisis risus. Aenean sollicitudin imperdiet justo.'));
targetEl.appendChild(targetEl.parS[targetEl.parS.length-1]);
} else if (targetEl.parS.length > 0) {
targetEl.parS[targetEl.parS.length-1].parentNode.removeChild(targetEl.parS[targetEl.parS.length-1]);
targetEl.parS.length = targetEl.parS.length - 1;
}
//Following is the method to tell fleXcrolled div to update itself.
scrollDiv.scrollUpdate();
}

function makeWideNarrow() {
var targetEl = document.getElementById('dynamictest');
var scrollDiv = document.getElementById('test1');
if (targetEl == null || scrollDiv == null) return;
if (targetEl.parentNode.className=='dynamic') targetEl.parentNode.className = 'fixedsize';
else targetEl.parentNode.className='dynamic';
scrollDiv.scrollUpdate();
}

function cleanTestDiv() {
var targetEl = document.getElementById('dynamictest');
var scrollDiv = document.getElementById('test1');
if (targetEl != null) targetEl.innerHTML = '';
if (typeof(targetEl.parS) != 'undefined') targetEl.parS = new Array();
targetEl.parentNode.className = 'dynamic';
scrollDiv.scrollUpdate();
}

//en basic example external module to control scroll from outside
//NOT required for fleXcroll to run.
function fleXcrollTo(id,x,y) {
	var scrollDiv = document.getElementById(id);
	//Return if the target is not a fleXcrolled div.
	if (scrollDiv == null || !scrollDiv.fleXcroll) return;
	scrollDiv.commitScroll(x,y,true);
	/*
	Following is the method to commit a scroll:
		element.commitScroll(x,y,relative);
	x and y values are horizontal and vertical
	and can be set to false.
	relative can be either true or false. If true,
	x and y is used as relative scrolling.
	Currently these numbers refer to scrollbar position and
	not scrolled content position. With the next updates,
	it will be possible to use units, and it will be possible
	to directly control the scrolled content position.
	*/

}