var photoList = new Array();
var nameList = new Array();
var eventNumList = new Array();
var photoArr = new Array();
var descripList = new Array();
var currentPhoto = 0;
curColor = 0;
popUpSize = 75;
splashWidth = 525;
splashHeight = 300;
cTitleHeight = 0;


/* gets the list of photos to use for the splash screen */
function getSplashPhotos()
{
	// XMLHttpRequest object
	var oXmlHttp = createXMLHttp();

	// open method for XMLHttpRequest object
	oXmlHttp.open( "POST", "script/getSplashPhotos.asp", true );
		
	// Request header for POST data
	oXmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );

	// onreadystatechange listener, for response from server
	oXmlHttp.onreadystatechange = function() 
	{	
		// if the response is received
		if ( oXmlHttp.readyState == 4 ) 
		{
			// if the response is 'OK'
			if ( oXmlHttp.status == 200 )
			{
			
				var response = oXmlHttp.responseText;	// response text
				
				events = response.split( "&&" );
				for ( var i = 0; i < events.length; i++ )
				{
					eventInfo = events[i].split( "||" );
					photoList.push( eventInfo[0] );
					nameList.push( eventInfo[1] );
					eventNumList.push( eventInfo[2] );
					descripList.push( eventInfo[3] );
				}
				
				preloadImages();
				runSplashScreen();
			}
		}
	}; // end onreadystatechange listener
	
	// send the data to the server
	oXmlHttp.send( "" );
	
} /* end getSplashPhotos function */

function preloadImages()
{
	for ( var i = 0; i < photoList.length; i++ )
	{
		photoArr[i] = new Image();
		photoArr[i].src = "eventImages/" + photoList[i];
	}
}


function runSplashScreen()
{
	
	var splashDiv = document.getElementById( "frontSplashOut" );
	var imgDiv1 = document.createElement( "div" );
	imgDiv1.id = "imageContainer1";
	splashDiv.appendChild( imgDiv1 );
	
	a = document.createElement( "a" );
	a.setAttribute( "href", "listing.html?eventNum=" + eventNumList[ currentPhoto ] );
	img = document.createElement( "img" );
	img.setAttribute( "border", "0" );
	img.src = photoArr[ currentPhoto ].src;
	img.style.width = splashWidth + 'px';
	img.style.height = splashHeight + 'px';
	imgDiv1.style.top = eval( findPosY( splashDiv ) ) + 'px';
	imgDiv1.style.left = eval( findPosX( splashDiv ) ) + 'px';
	a.appendChild( img );
	imgDiv1.appendChild( a );
	img.style.display = "block";
	img.xOpacity = 1;
	setOpacity( img );
	splashDiv.xOpacity = 1;
	setOpacity( splashDiv );
	
	fadeInPhoto();

}

function fadeInPhoto()
{

	splashDiv = document.getElementById( "frontSplashOut" );
	cOpacity = splashDiv.xOpacity;
	cOpacity += .1;
	splashDiv.xOpacity = cOpacity;
	setOpacity( splashDiv );
	
	img = document.getElementById( "imageContainer1" ).getElementsByTagName( "img" )[0];
	cOpacity2 = img.xOpacity;
	cOpacity2 += .1; 
	img.xOpacity = cOpacity2;
	setOpacity( img ); 
	
	if( cOpacity >= 1 ) 
	{
	
		splashDiv = document.getElementById( "frontSplashOut" );
		imgDiv = document.getElementById( "imageContainer1" );
		titleDiv = document.createElement( "div" );
		titleDiv.id = "textContainer";
		
		splashDiv.appendChild( titleDiv );
		
		cTitleHeight = 0;
		titleDiv.style.height = cTitleHeight + 'px';
		titleDiv.style.width = splashWidth + 'px';
		
		titleDiv.style.top = eval( findPosY( imgDiv ) + splashHeight ) + 'px';
		titleDiv.style.left = eval( findPosX( imgDiv ) ) + 'px';

		setTimeout( popOutBox, 1000 );
		
	} else {
	
		setTimeout( fadeInPhoto, 10 );
		
	}

}

function popOutBox()
{

	titleDiv = document.getElementById( "textContainer" );

	cTitleHeight += 2;
	titleDiv.style.top = eval( findPosY( titleDiv ) - 2 ) + 'px';
	titleDiv.style.height =  cTitleHeight + 'px';

	if ( cTitleHeight >= popUpSize )
	{
	
		div = document.createElement( "div" );
		div.id = "showInfo";
		
		a = document.createElement( "a" );
		a.setAttribute( "href", "listing.html?eventNum=" + eventNumList[ currentPhoto ] );
		span = document.createElement( "span" );
		span.className = "title";
		span.innerHTML = nameList[ currentPhoto ];
		a.appendChild( span );
		span.style.display = "block";
		curColor = 238;
		span.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
		div.appendChild( a );
		
		a = document.createElement( "a" );
		a.setAttribute( "href", "listing.html?eventNum=" + eventNumList[ currentPhoto ] );
		p = document.createElement( "p" );
		p.innerHTML = descripList[ currentPhoto ];
		a.appendChild( p );
		p.style.display = "block";
		p.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
		div.appendChild( a );
		
		titleDiv.appendChild( div );
		
		fadeInTitle();
		
	}
	else
	{
		setTimeout( popOutBox, 10 );
	} 	

}

function fadeInTitle()
{

	titleSpan = document.getElementById( "textContainer" ).getElementsByTagName( "span" )[0];
	curColor -= 12;
	titleSpan.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
	
	p = document.getElementById( "textContainer" ).getElementsByTagName( "p" )[0];
	p.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
	
	if ( curColor < 0 )
		setTimeout( fadeOutScreen, 4000 );
	else
		setTimeout( fadeInTitle, 10 );
}

function fadeOutScreen()
{

	splashDiv = document.getElementById( "frontSplashOut" );
	cOpacity = splashDiv.xOpacity;
	cOpacity -= .1;
	splashDiv.xOpacity = cOpacity;
	setOpacity( splashDiv );
	
	titleSpan = document.getElementById( "textContainer" ).getElementsByTagName( "span" )[0];
	curColor += 26;
	titleSpan.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
	
	p = document.getElementById( "textContainer" ).getElementsByTagName( "p" )[0];
	p.style.color = "rgb(" + curColor + "," + curColor + "," + curColor + ")";
	
	img = document.getElementById( "imageContainer1" ).getElementsByTagName( "img" )[0];
	cOpacity2 = img.xOpacity;
	cOpacity2 -= .1; 
	img.xOpacity = cOpacity2;
	setOpacity( img ); 
	
	if ( cOpacity <= 0 )
	{
	
		currentPhoto = ( photoArr[ currentPhoto + 1 ] ) ? currentPhoto + 1 : 0;
	
		var splashDiv = document.getElementById( "frontSplashOut" );
		splashDiv.innerHTML = "";
		var imgDiv1 = document.createElement( "div" );
		imgDiv1.id = "imageContainer1";
		splashDiv.appendChild( imgDiv1 );
	
		a = document.createElement( "a" );
		a.setAttribute( "href", "listing.html?eventNum=" + eventNumList[ currentPhoto ] );
		img = document.createElement( "img" );
		img.setAttribute( "border", "0" );
		img.src = photoArr[ currentPhoto ].src;
		img.style.width = splashWidth + 'px';
		img.style.height = splashHeight + 'px';
		imgDiv1.style.top = eval( findPosY( splashDiv ) ) + 'px';
		imgDiv1.style.left = eval( findPosX( splashDiv ) ) + 'px';
		a.appendChild( img );
		imgDiv1.appendChild( a );
		img.style.display = "block";
		img.xOpacity = 0;
		setOpacity( img );
		splashDiv.xOpacity = 0;
		setOpacity( splashDiv );
	
		fadeInPhoto();
	
	}
	else
		setTimeout( fadeOutScreen, 3 );

}

function setOpacity(obj) 
{
		if( obj.xOpacity >= 1 ) 
		{
			obj.xOpacity = 1;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}