
//
// CodaEffects.js - (C) 2007 Panic, Inc.
//
// Used to scroll our tabbed view, display our download popup, and display the giant dialog.
// Requires: Effects.js
//
// Not for redistribution.

// Scroll: Setup Scrolling Stuff

var currentCNav = "cNavPL";
var currentSection = "newshift-channel1"; // The default loaded section on the page
var currentSectionNum = 0;
var tabTag = "";
var paneTag = "-channel1";
var m, c;
var moveArrow = {start:5, end:5};

var c1sections = new Array();
c1sections[0] = "newshift-channel1";
c1sections[1] = "speakerinnovation-channel1";
c1sections[2] = "breakouts-channel1";
c1sections[3] = "experiences-channel1";
c1sections[4] = "artists-channel1";

var c1arrow = new Array();
c1arrow[0] = 10;
c1arrow[1] = 60;
c1arrow[2] = 134;
c1arrow[3] = 203;
c1arrow[4] = 263;

var currentSection2 = "boshers-channel2"; // The default loaded section on the page
var currentSectionNum2 = 0;
var tabTag2 = "";
var paneTag2 = "-channel2";
var d;
var c2sections = new Array();
c2sections[0] = "boshers-channel2";
c2sections[1] = "chan-channel2";
c2sections[2] = "holmen-channel2";
c2sections[3] = "thurman-channel2";
c2sections[4] = "kinnaman-channel2";
c2sections[5] = "matlock-channel2";
c2sections[6] = "carey-channel2";
c2sections[7] = "powell-channel2";
c2sections[8] = "hybels-channel2";
c2sections[9] = "buckingham-channel2";


// Scroll the page manually to the position of element "link", passed to us.

function ScrollSection(link, scrollArea, offset)
{

	// Store the last section, and update the current section
	if (currentSection == c1sections[link]) {
		return;
	}
	lastSection = currentSection;
	currentSection = c1sections[link];
	currentSectionNum = link;
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state


    
	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(currentSection));

	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0]);
	// return false;
}


function ScrollSection2(link, scrollArea, offset)
{

	// Store the last section, and update the current section
	if (currentSection2 == c2sections[link]) {
		return;
	}
	lastSection2 = currentSection2;
	currentSection2 = c2sections[link];
	currentSectionNum2 = link;
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state

    
	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll2 = document.getElementById(scrollArea);
	position2 = findElementPos(document.getElementById(currentSection2));

	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position2[0] = position2[0] - offsetPos[0];
	}

	scrollStartB(theScroll2, theScroll2.scrollLeft, position2[0]);
	// return false;
}



//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 50;
	scrollanim.element = elem;
	
	scrollanim.timer = setInterval("scrollHorizAnim();", 15);

}


function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}


//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanimB = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStartB(elem, start, end, direction)
{
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);

	if (scrollanimB.timer != null) {
		clearInterval(scrollanimB.timer);
		scrollanimB.timer = null;
	}
	scrollanimB.time = 0;
	scrollanimB.begin = start;
	scrollanimB.change = end - start;
	scrollanimB.duration = 50;
	scrollanimB.element = elem;
	
	scrollanimB.timer = setInterval("scrollHorizAnimB();", 15);

}


function scrollHorizAnimB()
{
	if (scrollanimB.time > scrollanimB.duration) {
		clearInterval(scrollanimB.timer);
		scrollanimB.timer = null;
	}
	else {
		moveB = sineInOut(scrollanimB.time, scrollanimB.begin, scrollanimB.change, scrollanimB.duration);
		scrollanimB.element.scrollLeft = moveB;
		scrollanimB.time++;
	}
}


// Utility: Find the Y position of an element on a page. Return Y and X as an array

function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	//console.log("Found element "+elemFind+" at "+elemY+"/"+elemX);

	return Array(elemX, elemY);
}

function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}



function MoveArrow(num) {
	clearInterval(m);
	moveArrow.end = c1arrow[num];
	if(moveArrow.end != moveArrow.start)
		m = setInterval('MoveArrowNow()', 15);
}
function MoveArrowNow() {
	if(moveArrow.start == moveArrow.end) {
		clearInterval(m);
	}
	else
	{
		var dif = moveArrow.end - moveArrow.start;
		if(dif > 0)
		{
			moveArrow.start = moveArrow.start + (dif/10 + 1);
			if(moveArrow.start > moveArrow.end)
			{
				moveArrow.start = moveArrow.end;
				clearInterval(m);
			}
		}
		else
		{
			moveArrow.start = moveArrow.start + (dif/10 - 1);
			if(moveArrow.start < moveArrow.end)
			{
				moveArrow.start = moveArrow.end;
				clearInterval(m);
			}
		}
		
		document.getElementById('screen1MenuArrow').style.left = moveArrow.start + "px";
	}
}

function cycleScreen1() {
	c = setInterval('cycleScreen1Now()', 9500);
}
function cycleScreen1Now() {
	currentSectionNum++;
	if(currentSectionNum == 5)
		currentSectionNum = 0;
	ScrollSection(currentSectionNum, "screen1", "newshift-channel1")
	MoveArrow(currentSectionNum);
}
function clearScreen1() {
	clearInterval(c);
}

function cycleScreen2() {
	d = setInterval('cycleScreen2Now()', 11300);
}
function cycleScreen2Now() {
	currentSectionNum2++;
	if(currentSectionNum2 == c2sections.length)
		currentSectionNum2 = 0;
	ScrollSection2(currentSectionNum2, "screen2", "boshers-channel2")
}
function clearScreen2() {
	clearInterval(d);
}

function channel2Next() {
	currentSectionNum2++;
	if(currentSectionNum2 == c2sections.length)
		currentSectionNum2 = 0;
	ScrollSection2(currentSectionNum2, "screen2", "boshers-channel2")
}

function channel2Prev() {
	currentSectionNum2--;
	if(currentSectionNum2 < 0)
		currentSectionNum2 = c2sections.length - 1;
	ScrollSection2(currentSectionNum2, "screen2", "boshers-channel2")
}

function changeClass(id, newClass) {
	document.getElementById(id).className = newClass;
}

function turnOn(object) {
	object.className = "on";
}

function turnOnNew(object) {
	document.getElementById(object).className = "on";
}
function turnOff(object) {
	//object.className = "";
}

function leaveOn(id) {
	if(id != currentCNav)
	{
		document.getElementById(id).className = "on";
		document.getElementById(currentCNav).className = "";
		currentCNav = id;
	}
}

function toggleBio(anchor, divID) {
	var div = document.getElementById(divID);
	if(div.className == 'hide')
	{
		div.className = 'show';
		anchor.className = 'fullBioOpen';
	}
	else
	{
		div.className = 'hide';
		anchor.className = 'fullBio';
	}
}
var currentAdNumVal = 0;
var impressionVal = 1000;	//1000 per second
var today = new Date()
var today_Hour = today.getHours()

var ImageValueArrVal 
var hrefValuesArrVal 
var impression_arrayVal

if (today_Hour >= 12)
{
	ImageValueArrVal = new Array("webimages/header_banner1.jpg","webimages/header_banner2.jpg","webimages/header_banner3.jpg","webimages/header_banner4.jpg","webimages/header_banner5.jpg"); // list separated by commas
	hrefValuesArrVal = new Array("index.asp","index.asp","index.asp","index.asp","index.asp") // list separated by commas
	impression_arrayVal =  new Array(4,4,4,4,4)
}	
else
{
	ImageValueArrVal = new Array("webimages/header_banner1.jpg","webimages/header_banner2.jpg","webimages/header_banner3.jpg","webimages/header_banner4.jpg","webimages/header_banner5.jpg"); // list separated by commas
	hrefValuesArrVal = new Array("index.asp","index.asp","index.asp","index.asp","index.asp") // list separated by commas
	impression_arrayVal =  new Array(4,4,4,4,4)
}	

function rotateBanner()
{
 	document.getElementById('adRotator_Img').src = ImageValueArrVal[currentAdNumVal];
	document.getElementById('adRotator_Href').href = hrefValuesArrVal[currentAdNumVal];
	currentAdNumVal++;
//alert(currentAdNumVal)
	if ( currentAdNumVal == hrefValuesArrVal.length)
	{
		currentAdNumVal = 0;
	}
	if ( hrefValuesArrVal.length > 1 )
		setTimeout('rotateBanner()', impression_arrayVal[currentAdNumVal] * impressionVal);
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
}