// Globals - don't edit
var browserWidth = 0, browserHeight = 0;
var scrollOffsetY, scrollOffsetX;
var splashImage = new Array();
var splashText  = new Array();
var leftmostImagePointer;
var splashVideoImages = new Array();
var imagesLoaded=false;
	
// YOU *CAN* EDIT THIS SECTION IF YOU WANT TO CHANGE THE SPLASH PAGE VIDEOS
// Arrays should begin at 0 and be in order, but otherwise just add/delete at will... 
splashText[0] = 'Seph Rodney reading Plath, "Nick and the Candlestick"';
splashImage[0]= 'Images/rodney.jpg'; 

splashText[1] = 'Pov Chin reading Hughes, "Minstrel Man"';
splashImage[1]= 'Images/chin.jpg'; 

splashText[2] = 'John Doherty reading Whitman, from "Song of Myself"';
splashImage[2]= 'Images/doherty.jpg'; 

splashText[3] = 'John Ulrich reading Brooks, "We Real Cool"';
splashImage[3]= 'Images/ulrich.jpg'; 

splashText[4] = 'Katherine Mechling ("a fifth grader") reading Roethke, "The Sloth"';
splashImage[4]= 'Images/mechling.jpg'; 

splashText[5] = 'Glaisma Perez-Silva reading de Burgos, "Ay, Ay, Ay de la Grifa Negra"';
splashImage[5]= 'Images/perez-silva.jpg'; 

splashText[6] = 'Daniel McCall reading Shakespeare, "Sonnet 29"';
splashImage[6]= 'Images/mccall.jpg'; 

splashText[7] = 'Donna Bickel reading Kunitz, "Hornworm: Autumn Lamentation"';
splashImage[7]= 'Images/bickel.jpg'; 

splashText[8] = 'Steve Conteaguero reading Yeats, "Politics"';
splashImage[8]= 'Images/conteaguero.jpg'; 

splashText[9] = 'Richard Samuel reading O'+"'"+'Hara, "POEM"';
splashImage[9]= 'Images/rsamuel.jpg'; 

splashText[10] = 'Rev. Michael Haynes reading Longfellow "A Psalm of Life"';
splashImage[10]= 'Images/haynes.jpg'; 

splashText[11] = 'Nancy Nersessian reading Akhmatova, "The Sentence"';
splashImage[11]= 'Images/nersessian.jpg'; 

for(x=0;x<splashImage.length;x++){
	splashVideoImages[x] = newImage(220,220);
	splashVideoImages[x].src = splashImage[x];
	if (x == (splashImage.length-1)){imagesLoaded=true;}
}

//poll for images to be loaded
img_timer = setInterval('checkForImageLoad()', 250);
function checkForImageLoad() 
{
	if (imagesLoaded) {
		clearInterval(img_timer);
		if ($('splash_loading')){
			$('splash_loading').style.display="none";
			$('splash_videos').style.display="block";
		}
	}
} 


////////////////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT below this line
////////////////////////////////////////////////////////////////////////////////////////////

// cross browser browser width detector
function browserWindowSize() {
	var browserWinWidth, browserWinHeight;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		browserWinWidth = window.innerWidth;
		browserWinHeight = window.innerHeight;
		scrollOffsetY = window.pageYOffset;
		scrollOffsetX = window.pageXOffset;
	
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in ’standards compliant mode’
		browserWinWidth = document.documentElement.clientWidth;
		browserWinHeight = document.documentElement.clientHeight;
		scrollOffsetY = document.body.scrollTop;
		scrollOffsetX = document.body.scrollLeft;
	
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		browserWinWidth = document.body.clientWidth;
		browserWinHeight = document.body.clientHeight;
		scrollOffsetY = document.body.scrollTop;
		scrollOffsetX = document.body.scrollLeft;
	}
	
	browserWidth=browserWinWidth;
	browserHeight=browserWinHeight;
}

// Initialize images to random position, called on load	
function splash_initialize(){	
	vp_initialize();
	leftmostImagePointer = Math.floor(Math.random()*splashImage.length);
	//leftmostImagePointer = 1;
	splash_rotateImages('left');

}

function vp_initialize(){
	vp_positionVideoPlayer();
}

// Rotates the images
function splash_rotateImages(direction){
	// All these ifs are a bit brute force... should rewrite for elegance
	vp_closeVideo();
	var arrayIndex;
	
	if (direction == 'right'){arrayIndex=leftmostImagePointer-1;}else{arrayIndex=leftmostImagePointer+1;}
	if (arrayIndex < 0){arrayIndex = splashImage.length-1}
	if (arrayIndex >= splashImage.length){arrayIndex=0}
	$('splashImageLeft').src=splashImage[arrayIndex];	
	//$('splashImageLeft').src=splashVideoImages[arrayIndex].src;
	leftmostImagePointer=arrayIndex;

	arrayIndex++;
	if (arrayIndex < 0){arrayIndex = splashImage.length-1}
	if (arrayIndex >= splashImage.length){arrayIndex=0}
	$('splashImageMid').src=splashImage[arrayIndex];	
	$('splash_text').firstChild.data=splashText[arrayIndex];
	
	arrayIndex++;
	if (arrayIndex < 0){arrayIndex = splashImage.length-1}
	if (arrayIndex >= splashImage.length){arrayIndex=0}
	$('splashImageRight').src=splashImage[arrayIndex];	
}

function vp_positionVideoPlayer(){
	browserWindowSize();
	var topPos = (browserHeight/2)-300+scrollOffsetY;
	if(topPos < 80){topPos=80;}
	if(leftPos < 0){leftPos=0;}
	var leftPos = (browserWidth/2)-270;
	$('videoPlayer').style.left=leftPos+'px';
	$('videoPlayer').style.top=topPos+'px';
}

// Launch the video belonging to the central image
function splash_launchVideo(){
	var videoIndex=$('splashImageMid').src;
	videoIndex=videoIndex.split("/")[(videoIndex.split("/").length-1)];
	videoIndex=videoIndex.split(".")[0];
	vp_launchVideo(videoIndex);
}

function vp_launchVideo(videoIndex){
	videoIndex='FlashVideo/'+videoIndex+'.html';
	$('videoPlayerFrame').src=videoIndex;
	$('videoPlayer').style.display='block';
}

function vp_closeVideo(){
	//new Effect.Fade($('videoPlayer'));
	$('videoPlayer').style.display='none';
	$('videoPlayerFrame').src='FlashVideo/nothing.html';

}
