// JavaScript Document

// <![CDATA[

// to add new panels to promotion area, adjust style sheet to fit width of all desired panels
// scrollerContainer - multiples of scroller width

var cpl = 0;

var left = 0;
var cp = 0; // current position
var width =  500;

// panel positions
var ctr = 0;
var pos = new Array();


function prepPromotion() {
	// this function will return user to previously viewed panel if query string is in place
	FadeIn('scrollerContainer');
}

function goScroll(sec) {

	var element = document.getElementById("containerPromotion");

	var dir = 1;
	if (cpl < sec) { dir = 1 } else { dir = -1 } // forwards / backwards
	
	var step = 1;
	var speed = 2;
	
	cp = element.scrollLeft; // current position
	
	var animate = window.setInterval(
		function() {

			//speed = speed + 1;

			if (dir == -1) {
				cp = cp - step;
				step = step + speed;
				if (cp < (sec*width)) { cp = (sec*width) } // this is so the window doesn't spill over
				element.scrollLeft = cp; // move element
				if (cp <= (sec*width)) window.clearInterval(animate);
			} else {
				cp = cp + step;
				step = step + speed;
				if (cp > (sec*width)) { cp = (sec*width) } // this is so the window doesn't spill over
				element.scrollLeft = cp; // move element
				if (cp >= (sec*width)) window.clearInterval(animate);
			}

		}, 5
	)

	cpl = sec; // set requested panel as current;
}

function moveItem() {
}


// Function used to show/hide the target div
function ToggleDiv($WhichDiv) {
	if (document.getElementById($WhichDiv).style.display == "none") {
		setOpac($WhichDiv,100); // set it to opaque (just in case)
		document.getElementById($WhichDiv).style.display = "block";
	} else {
		document.getElementById($WhichDiv).style.display = "none";
	}
}

// Function used to show/hide the target div utilizing fade effects below
function FadeToggleDiv($WhichDiv) {
	if (document.getElementById($WhichDiv).style.display == "none") {
		FadeIn($WhichDiv);
	} else {
		FadeOut($WhichDiv);
	}
}

// Function used to fade "in" a div
function FadeIn($WhichDiv) {
	setOpac($WhichDiv,0); // set it to transparent
	document.getElementById($WhichDiv).style.display = "block"; // display as block just in case
	for( var i = 0 ; i <= 100 ; i++ ) {
		   setTimeout( 'setOpac(\''+$WhichDiv+'\',' + i + ')' , 8 * i );
	}
}

// Function used to fade "out" a div
function FadeOut($WhichDiv) {
	for( var i = 0 ; i <= 100 ; i++ ) {
		   setTimeout( 'setOpac(\''+$WhichDiv+'\',' + (100 - i) + ')' , 8 * i );
	}
	setTimeout('ToggleDiv(\''+$WhichDiv+'\')', 8 * i);
	setOpac($WhichDiv,100); // set it to opaque (just in case)
}

// Function used to set the opacity of a div (from 0 to 10)
function setOpac( $WhichDiv, value ) {
	document.getElementById($WhichDiv).style.opacity = value / 100;
	document.getElementById($WhichDiv).style.filter = 'alpha(opacity=' + value + ')';
}


// Function used to shrink/grow a div vertically
function ToggleVert($WhichDiv, $MinHeight, $MaxHeight) {
	var $CurrHeight = parseInt(document.getElementById($WhichDiv).style.height);
	if ($CurrHeight < ($MaxHeight - 10)) {
		VertScale($WhichDiv,$MaxHeight);
	} else {
		VertScale($WhichDiv,$MinHeight);
	}
}

// Function used to animate the scaling of a div vertically
function VertScale($WhichDiv, $EndHeight) {
	var $StartHeight = parseInt(document.getElementById($WhichDiv).style.height);
	document.getElementById($WhichDiv).style.display = "block"; // display as block just in case
	document.getElementById($WhichDiv).style.overflow = 'hidden'; // set the overflow to hidden
	for( var i = 0 ; i <= 50 ; i++ ) {
		   $CurrHeight = ($StartHeight - ((($StartHeight - $EndHeight) / 50) * (i-1)));
		   setTimeout( 'setHeight(\''+$WhichDiv+'\',' + $CurrHeight + ')' , 8 * i );
	}
	if ($EndHeight == 0) {
		setTimeout('ToggleDiv(\''+$WhichDiv+'\')', 8 * i);
	}
}

// Function used to set the height of a div
function setHeight( $WhichDiv, value ) {
	document.getElementById($WhichDiv).style.height = parseInt(value) + "px";
}

//window.onload = FadeIn('scrollerContainer');

// ]]>
