/************************************************************************* 
	Justin Schroeder Copyright 2008. No Rights Reserved. (On My Edits)
	Panic Copyright (c) 2008. No Rights Reserved. (On Remaining Origianal Code)
	Requires: Panic's and Cabel Sasser FancyZoom.js
	
	
	Thanks for reading my js, it shows you care. Like what you see?
	Lets Talk. Shoot me a line, you've earned the right:
	justin (at) jpschroeder (dot) com

**************************************************************************/


var currentSection = "missouri-pane";
var currentBlog = "missouri-pane";
var currentPortfolio = "missouri-pane";
var tabTag = "-tab";
var paneTag = "-pane";

function ScrollSection(link, scrollArea, offset)
{

	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}
	if(getCurrentTab() == "blog"){
		currentBlog = link;
	}else{
		currentPortfolio = link;
	}
	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
}


function ScrollArrow(direction, panesDiv, scrollArea, offset) {
	
	// Get the names all the panes to scroll from the div named "panes" this can be filled in from php.
	// The syntax should be: panename-pane
	
	var panes = document.getElementById(panesDiv).innerHTML.split(" ");
	for (var i = 0; i < panes.length; i++) {
		if (panes[i] == currentSection) {
			if (direction == "left") {
				if (i - 1 < 0) {
					nextPane = panes[panes.length - 1];
				} else {
					nextPane = panes[i - 1];
				}
			} else {
				if ((i + 1) > (panes.length - 1)) {
					nextPane = panes[0];
				} else {
					nextPane = panes[i + 1];
				}
			}
		}
	}
	ScrollSection(nextPane, scrollArea, offset);

}

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

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++;
	}
}

var moveanim = {time:0, beginX:0, changeX:0.0, beginY:0, changeY:0, duration:0.0, element:null, timer:null};

function moveStart(elem, startX, endX, startY, endY, duration)
{
	if (moveanim.timer != null) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}
	moveanim.time = 0;
	moveanim.beginX = startX;
	moveanim.changeX = endX - startX;
	moveanim.beginY = startY;
	moveanim.changeY = endY - startY;
	moveanim.duration = duration;
	moveanim.element = elem;

	moveanim.timer = setInterval("moveAnimDo();", 15);
}

function moveAnimDo()
{
	if (moveanim.time > moveanim.duration) {
		clearInterval(moveanim.timer);
		moveanim.timer = null;
	}
	else {
		moveX = cubicOut(moveanim.time, moveanim.beginX, moveanim.changeX, moveanim.duration);
		moveY = cubicOut(moveanim.time, moveanim.beginY, moveanim.changeY, moveanim.duration);
		moveanim.element.style.left = moveX + "px";
		moveanim.element.style.top = moveY + "px";
		moveanim.time++;
	}
}
