/*
	======================================================================
	BASIC VARIABLES STUFF
	======================================================================
*/
var dhtmlCapable = (document.getElementById || document.all || document.layers);
var hasCookiesOn = document.cookie;
var cssCachedStyles = new Array ();	// Used as a temporary lookup table to boost performance
var preloadCache = new Array ();	// Used by preloadImg
var sectionStatus = new Array();	// Used on some pages
var helpScreenVisible = false;

/*
	======================================================================
	IMAGE BASED FUNCTIONS
	======================================================================
*/
function preloadCore (filename, filenameClean)
{
	// Clean our timeout entry completely so it can be repurposed
	clearTimeout(preloadCache[filenameClean]);
	delete(preloadCache[filenameClean]);

	preloadCache[filenameClean] = new Image(1, 1);
	preloadCache[filenameClean].src = filename;
}

//	------------------------------------------------------------------------------------------
function preloadImg (filename, fullPath, suppressSkinPath)
{
	if (typeof(fullPath) == 'undefined') {
		if (skinPath && typeof(suppressSkinPath) != 'undefined') {
			fullPath = skinPath +"images/";
			
		} else {
			pageURL = parseURL();
			fullPath = pageURL['path'];
		}
	}

	if (fullPath.charAt(fullPath.length - 1) != '/')
		fullPath = fullPath +"/";
	
	filenameClean = stripFilename(filename);
	
	// Set a timeout which is later repurposed for the proper filename set
	preloadCache[filenameClean] = setTimeout('preloadCore("'+ fullPath + filename +'", "'+ filenameClean +'")', 100);
}

//	------------------------------------------------------------------------------------------
function preloadImgState (fileName, preloadType, fullPath)
{
	if (!preloadType || typeof(preloadType) != 'object')
		preloadType = new Array('n');

	if (!fullPath) {
		pageURL = parseURL();
		fullPath = pageURL['path'];
	}
	
	fileSplit = extractImgState(fileName);
	
	for (var element in preloadType) {
		preloadImg(fileSplit['leading'] + preloadType[element] + fileSplit['trailing'], fullPath);
	}
}

//	------------------------------------------------------------------------------------------
function findStyleRule (styleName)
{
	// If no stylesheets exist, return! This also denies Opera any usability until they implement this property
	if (!document.styleSheets) {
		return false;
	}

	// Check if the CSS style has already been cached (or has been searched for and explicitly set to false)
	if (cssCachedStyles[styleName] || cssCachedStyles[styleName] === false) {
		return cssCachedStyles[styleName];
	}
	
	// If the style has not been cached, continue	
	var theRules = new Array();
	
	// We need to count backwards, so that the last defined CSS takes precedence over the first
  	for (i = document.styleSheets.length - 1; i >= 0; i--) { 
    	// Mozilla/IE W3C compatibility
		if (document.styleSheets[i].cssRules)
			theRules = document.styleSheets[i].cssRules;
  		else if (document.styleSheets[i].rules)
			theRules = document.styleSheets[i].rules;
		
		for (j = 0; j < theRules.length; j++) {
			if (theRules[j].selectorText == styleName) {
				// Add the style to our CSS cache and then return
				cssCachedStyles[styleName] = new Array();
				cssCachedStyles[styleName]['stylesheet'] = i;
				cssCachedStyles[styleName]['element'] = j;
				cssCachedStyles[styleName]['css'] = theRules[j];
				
				return cssCachedStyles[styleName];
			}
		}
    }
	
	// Report to our cache that the style could not be found, then return false
	cssCachedStyles[styleName] = false;
	
	return false;
}

//	------------------------------------------------------------------------------------------
function getObjectRef (objectName)
{
	if (typeof(objectName) == 'object')
	{
		return objectName;
	}
	else if (document.getElementById && document.getElementById(objectName))  
	{
		return document.getElementById(objectName);
	}
	else if (document.all && document.all[objectName])
	{
		return document.all[objectName];
	}
	else if (document.layers && document.layers[objectName])
	{
		return document.layers[objectName];
	}
	
	return false;
}

//	------------------------------------------------------------------------------------------
function setStyle (objectName, styleName, value)
{
	var object = getObjectRef(objectName);
    object.style[styleName] = value;
}

//  ------------------------------------------------------------------------------------------

//	------------------------------------------------------------------------------------------
function swapImg (imageSource, mode)
{
	if (typeof(imageSource) == 'object')
		imageID = imageSource.id;
	else
		imageID = imageSource;

	if (document.images[imageID]) {
		// Use the faster document.images array as a first preference
		fileSplit = extractImgState(document.images[imageID].src);
		
		if (mode == 'over')
			insertChar = fileSplit['middle'] +'o';
		else if (mode == 'out')
			insertChar = fileSplit['middle'].charAt(0);
		else if (mode == 'press')
			insertChar = 'p';
		
		document.images[imageID].src = fileSplit['leading'] + insertChar + fileSplit['trailing'];
		return true;
		
	} else if (curImg = new GetObject(imageID)) {
		// If we do not have a document.images entry, test for an object (eg. form submit buttons of type image)
		fileSplit = extractImgState(curImg.object.src);
		
		if (mode == 'over')
			insertChar = fileSplit['middle'] +'o';
		else if (mode == 'out')
			insertChar = fileSplit['middle'][0];
		else if (mode == 'press')
			insertChar = 'p';
		
		curImg.object.src = fileSplit['leading'] + insertChar + fileSplit['trailing'];
		return true;
		
	} else {
		return false;
	}
}

//  ------------------------------------------------------------------------------------------
function findNode(startingNode, tagName)
{
  // on Firefox, the <td> node might not be the firstChild node of the <tr> node
  myElement=startingNode;
  var i=0;
  while (myElement && 
    (!myElement.tagName || (myElement.tagName && myElement.tagName!=tagName)))
  {
    myElement=startingNode.childNodes[i++];
  } 
  if (myElement && myElement.tagName && myElement.tagName==tagName)
  {
    return myElement;
  }
  // On Internet Explorer, the <tr> node might be the firstChild node of the <tr> node 
  else if (startingNode.firstChild)
    return findNode(startingNode.firstChild, tagName);
  return 0;
}
//  ------------------------------------------------------------------------------------------
function swapHighlightRow (objectName, polarity)
{
  if (!objectName)
    return;

  // The following code traverses every <td> within the <tr> and highlights it
  // by changing its style[backgroundColor] property
  if (objectName)
  {
    var tableRow=objectName;

    var tableCell=findNode(objectName, "TD"); 

    i=0;
    // Loop through every sibling.  Theoretically, a sibling of a <td> should be 
    //  another <td>, but this is not always the case on certain browsers, 
    //  so we need to check the tagName to be sure and skip to the next 
    //  sibling if the sibling is not a <td>)
    // We then highlight every siblings
    while (tableCell)
    {
      // Make sure it's actually a cell (a <td>)
      if (tableCell.tagName=="TD")
      {
        // If no style has been assigned, assign it, otherwise Netscape will 
        // behave weird.
        if (!tableCell.style)
        {
          tableCell.style={};
        }

		var colObjectName = getObjectRef(tableCell);
        
		// Attempt to just change the BG colour; if it fails, ignore
		switch (polarity)
		{
			case 'over':
				var changeStyle = findStyleRule('.'+ colObjectName.className +'over');
				if (changeStyle != false)
				{
					setStyle(colObjectName, 'backgroundColor', changeStyle.backgroundColor);
				}
				break;
			case 'out':
				var changeStyle = findStyleRule('.'+ colObjectName.className);
				if (changeStyle != false)
				{
					setStyle(colObjectName, 'backgroundColor', changeStyle.backgroundColor);
				}
				break;
		}

        i++;
      }
      // Go to the next cell in the row
      tableCell=tableCell.nextSibling;
    }
  }
}

//	------------------------------------------------------------------------------------------
function swapHighlight (objectName, polarity)
{	
	var objectName = getObjectRef(objectName);

	// Attempt to just change the BG colour; if it fails, ignore
	switch (polarity)
	{
		case 'over':
			var changeStyle = findStyleRule('.'+ objectName.className +'over');
			if (changeStyle != false)
			{
				setStyle(objectName, 'backgroundColor', changeStyle.backgroundColor);
			}
			break;
		case 'out':
			var changeStyle = findStyleRule('.'+ objectName.className);
			if (changeStyle != false)
			{
				setStyle(objectName, 'backgroundColor', changeStyle.backgroundColor);
			}
			break;
	}
}

//	------------------------------------------------------------------------------------------
function extractImgState (filename, includeServer)
{
	fileSplit = new Array();
	
	leadExtract = filename.lastIndexOf('-') + 1;
	trailExtract = filename.lastIndexOf('.');
	
	fileSplit['leading'] = filename.substr(0, leadExtract);
	
	// Rip out the server prepend, as this often interferes with mouseOver sources
	if (!includeServer && fileSplit['leading'].indexOf('://') != -1)
		// The indexOf '/' here starts at the 9th character in, which is pretty safe for a URL
		fileSplit['leading'] = fileSplit['leading'].substr(fileSplit['leading'].indexOf('/', 9));

	fileSplit['middle'] = filename.substring(leadExtract, trailExtract);
	fileSplit['trailing'] = filename.substr(trailExtract);
	
	return fileSplit;
}

/*
	======================================================================
	ALERT FUNCTIONS
	======================================================================
*/
function confirmEvent (eventType, eventItem, extendedError, joinItem)
{
	if (!extendedError)
		extendedError = '';
	else
		extendedError = ' '+ extendedError;
	
	if (!joinItem)
		joinItem = 'this';
	
	return confirm('Are you sure you want to '+ eventType +' '+ joinItem +' '+ eventItem +'?'+ extendedError);
}

/*
	======================================================================
	CORE DHTML FUNCTIONS
	======================================================================
*/
// Get a reference to an object based on what references are available to the browser
function GetObject (objectName)
{
	if (document.getElementById && document.getElementById(objectName)) {
		this.object = document.getElementById(objectName);
		
		if (document.getElementById(objectName).style)
			this.style = document.getElementById(objectName).style;
	
	} else if (document.all && document.all[objectName]) {
		this.object = document.all[objectName];
		
		if (document.all[objectName].style)
			this.style = document.all[objectName].style;
	
	} else if (document.layers && document.layers[objectName]) {
		this.object = document.layers[objectName];
		this.style = document.layers[objectName];
		
	} else {
		return false;
	}
}

//	------------------------------------------------------------------------------------------
function hook ()
{
	// This function deliberately left blank (-;
}

/*
	======================================================================
	CSS FUNCTIONS
	======================================================================
*/
function swapTableBg (referenceSource, mode, multiple)
{
	if (typeof(referenceSource) == 'object')
		referenceObj = referenceSource.id;
   else
		referenceObj = referenceSource;
	
	if (mode == 'over') {
		// Back up the old colour
		if (multiple >= 2) {
			for (var i = 1; i <= multiple; i++) {
				// First pull out our style
				tableColour = new GetObject(referenceObj +'_'+ i);
				
				// Although we could just swap the entire class, the responsiveness is crap, so we just set one property
				if (tableColour.style) {
					tableClassOld = tableColour.object.className;
					rulesObject = findStyleRule('.'+ tableClassOld +'over');
					
					if (rulesObject !== false) {
						tableColour.style.backgroundColor = rulesObject.css.style.backgroundColor;
					}
				}
			}
		} else {
			tableColour = new GetObject(referenceObj);
	
			// Although we could just swap the entire class, the responsiveness is crap, so we just set one property
			if (tableColour.style) {
				tableClassOld = tableColour.object.className;
				rulesObject = findStyleRule('.'+ tableClassOld +'over');
				
				if (rulesObject !== false) {
					tableColour.style.backgroundColor = rulesObject.css.style.backgroundColor;
				}
			}
		}
		
	} else if (mode == 'out') {
		// Restore
		if (tableColour.style) {
			rulesObject = findStyleRule('.'+ tableClassOld);
			
			if (rulesObject !== false) {
				if (multiple >= 2) {
					for (var i = 1; i <= multiple; i++) {
						tableColour = new GetObject(referenceObj +'_'+ i);
						tableColour.style.backgroundColor = rulesObject.css.style.backgroundColor;
					}
				} else {
					tableColour.style.backgroundColor = rulesObject.css.style.backgroundColor;
				}
			} else {
				tableColour.style.backgroundColor = '';
			}
		}
	}
}

function openWindow (url, windowName, width, height, xpos, ypos, resizable, scrollbars, locationbar, toolbar, menubar, statusbar)
{
	width = (!width) ? 512 : width;
	height =  (!height) ? 384 : height;
	
	xpos = (xpos == 'center') ? xpos = (screen.width / 2) - (width / 2) : xpos;
	ypos = (ypos == 'center') ? (screen.height / 2) - (height / 2) : ypos;
	
	// Options for the popup window
	resizable = (resizable) ? 'yes' : 'no';
	scrollbars = (scrollbars) ? 'yes' : 'no';
	locationbar = (locationbar) ? 'yes' : 'no';
	toolbar = (toolbar) ? 'yes' : 'no';
	menubar = (menubar) ? 'yes' : 'no';
	statusbar = (statusbar) ? 'yes' : 'no';
		
	return window.open(url, windowName, 'width='+ width +', height='+ height +', left='+ xpos +', top='+ ypos +', resizable='+ resizable +', scrollbars='+ scrollbars +', location='+ locationbar +', toolbar='+ toolbar +', status='+ statusbar +', menubar='+ menubar);
}

function launchXeUCC (currencyAmount, currencyFrom)
{
	CurrencyWindow = window.open ('', 'CurrencyWindow', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=150,width=575');
	CurrencyWindow.focus();
	CurrencyWindow.location.href = 'http://www.xe.com/pca/input.cgi?AmountSet='+ currencyAmount +'&From='+ currencyFrom +'&ToSelect=USD'
}

/*
------------========================------------
FEEDBACK FUNCTIONS
------------========================------------
*/

// Requires a setHit to be executed first
function disableObject (formName, objectID, newText) {
	// If we're doing a form post, check the appropriate variables
	if (document.forms[formName][formName +"[action_hit]"]) {
		document.forms[formName][formName +"[action_hit]"].value = objectID.substring(formName.length + 1, objectID.length - 1);
	}

	// Pull out an object reference
	theObject = new GetObject(objectID);

	if (theObject.object) {
		theObject.object.disabled = true;
		
		if (newText) {
			theObject.object.value = newText;
		}
	}
}

// ------------========================------------
// Sets up a hit object, to be used by disableObject on form submit
function setHit (objectID, hitMessage) {
	formHit = new Array();
	formHit['id'] = objectID;
	formHit['message'] = hitMessage;
}

/*
------------------------------------------------------------------------------------------
*/

function collapseSect (sectID, polarity, imgName, imgState)
{
	var changeImg = getObjectRef(imgName);
	var changeImgTo;
	
	switch (polarity)
	{
		case 'show':
			swapClass(sectID +'_off', 'hideitem', 'showitem');
			swapClass(sectID +'_on', 'showitem', 'hideitem');
			(changeImg !== false) ? changeImgTo = imgState[0] : null;
			break;
		case 'hide':
			swapClass(sectID +'_off', 'showitem', 'hideitem');
			swapClass(sectID +'_on', 'hideitem', 'showitem');
			(changeImg !== false) ? changeImgTo = imgState[1] : null;
			break;
		case 'toggle':
			var sectRef = getObjectRef(sectID);
			
			if (sectRef.className == 'hideitem')
			{
				swapClass(sectRef, 'showitem', 'hideitem');
				(changeImg !== false) ? changeImgTo = imgState[0] : null;
			}
			else
			{
				swapClass(sectRef, 'hideitem', 'showitem');
				(changeImg !== false) ? changeImgTo = imgState[1] : null;
			}
			
			break;
		case 'on':
			swapClass(sectID, 'showitem', 'hideitem');
			(changeImg !== false) ? changeImgTo = imgState[0] : null;
			break;
		case 'off':
			swapClass(sectID, 'hideitem', 'showitem');
			(changeImg !== false) ? changeImgTo = imgState[1] : null;
			break;
		default:
			return;
	}
	
	if (changeImg !== false)
	{
		var imgSplit = extractImgState(changeImg.src);
		changeImg.src = imgSplit['leading'] + changeImgTo + imgSplit['trailing'];
	}
}

/*
------------------------------------------------------------------------------------------
*/

function collapseSectGroup (selectedValue, elementSuffix, elementPrefix)
{
	var count = (typeof elementSuffix == 'number') ? elementSuffix : elementSuffix.length - 1;
	var elementPrefix = (typeof elementPrefix == 'undefined') ? '' : elementPrefix;

	for (var i = 0; i <= count; i++)
	{
		var currentValue = (typeof elementSuffix == 'number') ? i : elementSuffix[i];
		
		if (selectedValue !== '' && selectedValue == currentValue)
		{
			collapseSect(elementPrefix + currentValue, 'on');
		}
		else
		{
			collapseSect(elementPrefix + currentValue, 'off');
		}
	}
}

function collapseSectGroupCheck (selectedValue, divName)
{
	if(selectedValue.checked == true) 
	{
		collapseSect(divName, 'on');
	}
	else
	{
		collapseSect(divName, 'off');
	}
}

/*
-------------------------------------------------------------------------------------------
*/

function swapClass (objectName, newClass, oldClass)
{
	// Get the object based on whether we've passed an ID name or an explicit reference
	var object = getObjectRef(objectName);
	var classPrepend = '', classAppend = '', classPosition, finalClass;
	
	// Swap the class
	if (object.className)
	{
		// Rip out the old class if necessary
		if (typeof oldClass == 'string' && oldClass != '')
		{
			var classPosition = object.className.indexOf(oldClass);
			
			if (classPosition >= 0)
			{
				// We've found an old class that needs to be replaced with the new
				classPrepend = object.className.substring(0, classPosition);
				classAppend = object.className.substr(classPosition + oldClass.length);
				finalClass = classPrepend + newClass + classAppend;
				
				if (object.className != finalClass)
				{
					// Replace old with new and return
					object.className = finalClass;
					return object.className;
				}
			}
			else
			{
				// No change necessary
				return object.className;
			}
		}
		else
		{
			// Replace the class outright
			object.className = newClass;
			return object.className;
		}
	}
	else
	{
		return false;
	}
}

/*
---------------------------------------------------------------------------
toggleForm

- will toggle any select elements in a div that you pass it from disabled
  to enabled
---------------------------------------------------------------------------
*/
function toggleForm(which) {
	local_elements = document.getElementById(which).getElementsByTagName('select');
	for(i = 0; i < local_elements.length; i ++) {
		local_elements[i].disabled = !(local_elements[i].disabled);
	}
	return true;
}

/*
---------------------------------------------------------------------------
sfHover

- allows IE 6.0 to understand the :hover pseudoclass on list items
---------------------------------------------------------------------------
*/
function sfHover(){
	if (document.getElementById("nav")){
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (document.getElementById("user-number-list")){
		var sfEls = document.getElementById("user-number-list").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	if (document.getElementById("lhn")){
		var sfElhn = document.getElementById("lhn").getElementsByTagName("DIV");
		for (var i=0; i<sfElhn.length; i++) {
			sfElhn[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfElhn[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/*
	======================================================================
	ANIMATION FUNCTIONS
	======================================================================
*/

// Slide show function for stepping through slides
function SlideSection(targ, slideArea, offset)
{
	// Store the last slide, update the current on
	if (currentSlide == targ) {
		return;
	}
	lastSlide = currentSlide;
	currentSlide = targ;
    
	// Get the element we want to move, get it's position for moving to	
	theSlide = document.getElementById(slideArea);
	pos = findElementPos(document.getElementById(targ));
	
	// Get the position of the offset div - the one furthest to the left	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		pos[0] = pos[0] - offsetPos[0];
	}
	
	slideStart(theSlide, theSlide.scrollLeft, pos[0], "x");

}

// Set up a button to move the slideArea

function SlideButton(direction, slideParent, slideArea, offset) {

	slideElement = document.getElementById(slideParent);
	slideArray = new Array();    
    
	if (slideElement.hasChildNodes())
	{
		var children = slideElement.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (slideElement.childNodes[i].className == "diagram") {
				slideArray.push(slideElement.childNodes[i].id.split("-")[0]);
			}
		}
	}

	// Iterate through the number of slides
	for (var i = 0; i < slideArray.length; i++) {
		if (slideArray[i] == currentSlide.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoSlide = slideArray[slideArray.length - 1];
				} else {
					gotoSlide = slideArray[i - 1];
				}
			} else {
				if ((i + 1) > (slideArray.length - 1)) {
					gotoSlide = slideArray[0];
				} else {
					gotoSlide = slideArray[i + 1];
				}
			}
		}
	}
	
	SlideSection(gotoSlide+slideRef, slideArea, offset);

}

// Animation functions

var slideanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function slideStart(elem, start, end, direction)
{
	if (slideanim.timer != null) {
		clearInterval(slideanim.timer);
		slideanim.timer = null;
	}
	slideanim.time = 0;
	slideanim.begin = start;
	slideanim.change = end - start;
	slideanim.duration = 50;
	slideanim.element = elem;
	
	if (direction == "x") {
		slideanim.timer = setInterval("slideX();", 15);
	}
	else {
		slideanim.timer = setInterval("slideY();", 15);
	}
}
function slideY()
{
	if (slideanim.time > slideanim.duration) {
		clearInterval(slideanim.timer);
		slideanim.timer = null;
	}
	else {
		move = linear(slideanim.time, slideanim.begin, slideanim.change, slideanim.duration);
		slideanim.element.scrollTop = move; 
		slideanim.time++;
	}
}

function slideX()
{
	if (slideanim.time > slideanim.duration) {
		clearInterval(slideanim.timer);
		slideanim.timer = null;
	}
	else {
		move = cubicInOut(slideanim.time, slideanim.begin, slideanim.change, slideanim.duration);
		slideanim.element.scrollLeft = move;
		slideanim.time++;
	}
}
function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}

// Motion functions

function linear(t, b, c, d)
{
	return c*t/d + b;
}

function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}

function cubicIn(t, b, c, d) {
	return c*(t/=d)*t*t + b;
}

function cubicOut(t, b, c, d) {
	return c*((t=t/d-1)*t*t + 1) + b;
}

function cubicInOut(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
}

function bounceOut(t, b, c, d)
{
	if ((t/=d) < (1/2.75)){
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)){
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)){
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	}
}