if (myPage=="home")
{
// slideshow stuff
var Pix = new Array("images/videothumbnails/flow_vid_thumb.jpg","images/videothumbnails/strength_vid_thumb.jpg","images/videothumbnails/power_vid_thumb.jpg"
,"images/videothumbnails/flow_vid_thumb2.png","images/videothumbnails/strength_vid_thumb3.jpg","images/videothumbnails/power_vid_thumb3.jpg"
,"images/videothumbnails/flow_vid_thumb3.jpg","images/videothumbnails/strength_vid_thumb2.png","images/videothumbnails/power_vid_thumb4.jpg"
,"images/videothumbnails/flow_vid_thumb4.jpg","images/videothumbnails/strength_vid_thumb4.jpg","images/videothumbnails/power_vid_thumb2.png"
,"images/videothumbnails/flow_vid_thumb5.jpg","images/videothumbnails/strength_vid_thumb5.jpg","images/videothumbnails/power_vid_thumb5.jpg"
);
var slide_delay = 3500;
var myText = "";
var videoLink1 = "";
var videoLink2 = "";
var howMany = Pix.length;
var PicCurrentNum = 0;
var PicCurrent = new Image();
PicCurrent.src = Pix[PicCurrentNum];
var mediaCycle;

// typewriter stuff
var current_char = 1;
var keystroke_delay = 50;
var destination = "";
var text = "";
var type_active = false;
var cursorBlink;
var cursorDelay;
var myCursor = document.createElement("span");
myCursor.appendChild(document.createTextNode("_"));
var keyDelay;
var trail = "";
}

// crossfade stuff
var current_div = 0;
var previous_div = 0;
var div_length = 0;
var fade_delay = 0;
var div_delay = 0;
var divs = new Array();
var opacity_level = 0;
var opacity_increment = 0;
var opacity_level2 = 100;
var active = false;
var fade_loop;
var my_date;
var exit = false;


function crossfade (the_divs, the_increment, the_fade_delay, the_div_delay)
{

	// initialize variables/opacity and hide all divs

	divs=the_divs;
	opacity_increment = the_increment;
	fade_delay = the_fade_delay
	div_delay = the_div_delay;

	current_div = 0;
	div_length = divs.length;
	previous_div = div_length - 1;

	for (the_div=0;the_div<div_length;the_div++)
	{
		document.getElementById(divs[the_div]).style.opacity = 0;
		document.getElementById(divs[the_div]).style.position = "absolute";
		document.getElementById(divs[the_div]).style.filter = "alpha(opacity=0)";
		document.getElementById(divs[the_div]).style.visibility = "hidden";
	}


	// begin fade process
	startCrossfade();
}

function startCrossfade()
{
	active = true;

	if (myPage == "home")
	{

		clearInterval(cursorBlink);

			// stop slideshow for div0
		if (current_div == 1)
		{
			clearInterval(mediaCycle);
		}
	}

	// show current div
	document.getElementById(divs[current_div]).style.visibility = "visible";
	
	// fade in & out current and previous div by increment
	fade_loop = setInterval("fadeInout();",fade_delay);
}

function fadeInout()
{
	/* fade in current div */
	opacity_level += opacity_increment;
	if (opacity_level > 100)
	{
	opacity_level = 100;
	opacity_level_float = .1;
	opacity_level2 = 0;
	opacity_level2_float = 0;
	exit = true;
	}
	opacity_level_float = opacity_level / 100;

	// for mozilla
	document.getElementById(divs[current_div]).style.opacity = opacity_level_float;
	// for IE (eww!!)
	document.getElementById(divs[current_div]).style.filter = "alpha(opacity="+opacity_level+")";
	
	/* Fade out previous div */
	opacity_level2 -= opacity_increment;
	opacity_level_float2 = opacity_level2 / 100;

	// for mozilla
	document.getElementById(divs[previous_div]).style.opacity = opacity_level_float2;
	// for IE (eww!!)
	document.getElementById(divs[previous_div]).style.filter = "alpha(opacity="+opacity_level2+")";

	if (exit)
	{
		exit = false;
		fadeComplete();
	}

}

function fadeComplete()
{

	// stop incrementing fade
	clearInterval(fade_loop);
	active = false;
	
	if (myPage=="home")
	{

		// begin slideshow and typewriter effect in divs
		if (current_div == 0)
		{
			slideShow();
			mediaCycle = setInterval("slideShow();",slide_delay);
		}
		else if (current_div == 1)
		{
		   startTyping(myPHP1, keystroke_delay, "TextDestination2");
		}
		else if (current_div == 2)
		{
			startTyping(myPHP2, keystroke_delay, "TextDestination3");
	   }	
		else if (current_div == 3)
		{
			startTyping(myPHP3, keystroke_delay, "TextDestination4");
		}	
	}

	// reset values and hide previous div
	opacity_level = 0;
	opacity_level2 = 100;
	document.getElementById(divs[previous_div]).style.visibility = "hidden";

	// get next div
	previous_div = current_div;

	if (current_div == (div_length - 1))
	{
		current_div=0;
	}
	else 
	{
		current_div++;
	}

	// repeat process
	setTimeout("startCrossfade();",div_delay);
}

function slideShow() {
	PicCurrentNum++;
	if (PicCurrentNum == howMany) {
		PicCurrentNum = 0;
	}
	if (PicCurrentNum == 0 || PicCurrentNum == 3 || PicCurrentNum == 6 || PicCurrentNum == 9 || PicCurrentNum == 12)
	{
		myText = "Flow and Flexibility";
		videoLink1 = "videogallery.php?format=qtw=360&amp;h=240&amp;title=Flow%20and%20Flexibility%20DVD%20Promo&amp;file=video/flow_ad.mov";
		videoLink2 = "videogallery.php?format=wmvw=360&amp;h=240&amp;title=Flow%20and%20Flexibility%20DVD%20Promo&amp;file=video/flow_ad.wmv";
	}
	else if (PicCurrentNum == 1 || PicCurrentNum == 4 || PicCurrentNum == 7 || PicCurrentNum == 10 || PicCurrentNum == 13)
	{
		myText = "Strength and Balance";
		videoLink1 = "videogallery.php?format=qtw=360&amp;h=240&amp;title=Strength%20and%20Balance%20DVD%20Promo&amp;file=video/strength_ad.mov";
		videoLink2 = "videogallery.php?format=wmvw=360&amp;h=240&amp;title=Strength%20and%20Balance%20DVD%20Promo&amp;file=video/strength_ad.wmv";
	}
	else
	{
		myText = "Power and Agility";
		videoLink1 = "videogallery.php?format=qtw=360&amp;h=240&amp;title=Power%20and%20Agility%20DVD%20Promo&amp;file=video/power_ad.mov";
		videoLink2 = "videogallery.php?format=wmvw=360&amp;h=240&amp;title=Power%20and%20Agility%20DVD%20Promo&amp;file=video/power_ad.wmv";
	}

	document.getElementById('videolink1').href = videoLink1;
	document.getElementById('videolink2').href = videoLink2;
	document.getElementById('changingpix').src = Pix[PicCurrentNum];
	startTyping(myText, keystroke_delay, "TextDestination");
}

function typeWriter()
{
	type_active = true;
	typetext = text.substr(0, current_char);
	destination.firstChild.nodeValue = typetext;
	destination.appendChild(myCursor);
	current_char++;
	if (current_char > text.length)
	{
		clearTyping();
	}
}

function startTyping(the_text, the_keystroke_delay, the_destination)
{
	clearInterval(cursorBlink);
	clearTimeout(cursorDelay);
	trail = "";
	current_char = 1;
	text = the_text;
	keystroke_delay = the_keystroke_delay;
	destination = document.getElementById(the_destination);
	if (type_active)
	{
		clearTyping();
	}
	if (!active)
	{
		cursorStartBlink();
		cursorBlink = setInterval("cursorStartBlink();",200);
		keyDelay = setInterval("typeWriter();",keystroke_delay);
	}
	else
	{
		clearInterval(keyDelay);
	}
}

function clearTyping()
{
	clearInterval(keyDelay);
	type_active = false;
}

function cursorStartBlink()
{
	myCursor.style.color='white';
	cursorDelay = setTimeout("myCursor.style.color='transparent';",100);
}
