// *********************************************
// *  Dynamic Scrolling Functions
// *  
// *  Author: Steve Sagwitz
// *  Copyright 01/31/2008
// *  LiquidPixelDesigns, LLC
// *********************************************

var scrollTimer = null;
var scrollSpeed = 4;
var divElement = null;
var clipElement = null;
var divStyle = "";
var currPos = 0;
var newValue = 0;
var dimension = "";

function marquee(clip, element, dir, step) {
	divElement = document.getElementById(element);
	clipElement = document.getElementById(clip);

	if (dir == "V") { divStyle = (isIE)? "pixelTop": "top"; }
	if (dir == "H") { divStyle = (isIE)? "pixelLeft": "left"; }

	dimension = (dir == "V")? "height": "width";

	// both clipSize and divSize must be defined in the inline style tags on the rendered page
	clipSize = trimValue(eval("clipElement.style." + dimension));
	divSize = trimValue(eval("divElement.style." + dimension));

	scrollMin = clipSize - divSize;
	scrollMax = 0;

	if (isIE) {
		currPos = divElement.style.getAttribute(divStyle);
	} else {
		posTest = divElement.style.getPropertyValue(divStyle);
		currPos = (!posTest)? currPos = 0: trimValue(posTest);
	}

	newValue = currPos + (scrollSpeed * step);
	if (newValue < scrollMin) { newValue = scrollMin; }
	if (newValue > scrollMax) { newValue = scrollMax; }

	if (isIE) {
		divElement.style.setAttribute(divStyle, newValue);
	} else {
		divElement.style.setProperty(divStyle, (newValue + "px"), null);
	}
}

function trimValue(styleValue) {
	var trimmedValue = 0;
	trimmedValue = parseInt(styleValue.substr(0, (styleValue.length - 2)));
	return trimmedValue;
}

function leftScroll(clip, element) {
	scrollTimer = setInterval(function() { marquee(clip, element, 'H', -1) }, 70);
}

function rightScroll(clip, element) {
	scrollTimer = setInterval(function() { marquee(clip, element, 'H', +1) }, 70);
}

function upScroll(clip, element) {
	scrollTimer = setInterval(function() { marquee(clip, element, 'V', -1) }, 70);
}

function downScroll(clip, element) {
	scrollTimer = setInterval(function() { marquee(clip, element, 'V', +1) }, 70);
}

function stopScroll() {
	clearInterval(scrollTimer);
}

function increaseSpeed() {
	scrollSpeed += 1;
}

function decreaseSpeed() {
	scrollSpeed -= 1;
	if (scrollSpeed < 1) { scrollSpeed = 1; }
}



