/*
 * Accepts a reference to a function we want added to the page's onload event
 *    handler and a boolean that tells the function whether we want the function
 *    to be added to the beginning or the end of the list of onload functions
 *    if there is already an onload function.  If there is no onload function,
 *    then it makes the function passed in the onload event.  If there is
 *    already a function, it creates a new composite onload function that calls
 *    the existing onload function and the function passed in, with the boolean
 *    second argument telling this function whether we want the new call to be
 *    before or after the existing onload() event.
 * Preconditions: Must pass a function reference, not a call to a function.
 *    This means you shouldn't put any parenthese on the end of the function's
 *    name when you pass it to this function - just pass the name of the
 *    function. Example - if you want to add the function "outputJonIsAwesome()"
 *    before anything currently in window.onload, you would call this function
 *    as follows:
 *       addOnLoadEvent( outputJonIsAwesome, true );
 *    not like this:
 *       addOnLoadEvent( outputJonIsAwesome(), true );
 * Parameters:
 *    1) func_IN - the function we want added to the page's onload event
 *       handler.
 *    2) addBefore_IN - tells this function where to put the call to the
 *       function passed in in relation to an existing onLoad event.  If true,
 *       puts the function passed in before the call to any existing onLoad
 *       function.  If false, places it after.
 */
function addOnLoadEvent( func_IN, addBefore_IN )
{
	// declare variables
	var oldonload = window.onload;
	var addBefore = false;

	// see if we have an existing onload function.
	if (typeof window.onload != 'function')
	{
		// no, so just add the function passed in.
		//alert ( "No onload event! Just chucking the function passed in, func_IN, into window.onload" );
		window.onload = func_IN;
	}
	else
	{
		// we have an existing function.  Place function passed in before or
		//    after?
		//alert ( "Existing onload event!" );
		if ( ( addBefore_IN != null ) && ( addBefore_IN != "" ) )
		{
			if ( ( addBefore_IN == true ) || ( addBefore_IN.toUpperCase() == "TRUE" ) )
			{
				// some type of true passed in, so set flag to true.
				addBefore = true;
			}
			else // not true, so set to false.
			{
				// not true passed in, so set flag to false.
				addBefore = false;
			}
		}
		else //-- nothing passed in... set to false --//
		{
			addBefore = false;
		}

		// now, add create the new function, placing call before or after
		//    depending on the flag passed in.
		if ( addBefore == true )
		{
			//alert ( "Adding the function passed in, func_IN, before the old window.onload" );
			// make new onload with function passed in before old function.
			window.onload = function()
			{
				func_IN();
				if (oldonload)
				{
			        oldonload();
				}
			}
		}
		else //-- not before, so after. --//
		{
			//alert ( "Adding the function passed in, func_IN, after the old window.onload" );
			// make new onload with function passed in before old function.
			window.onload = function()
			{
				if (oldonload)
				{
			        oldonload();
				}
				func_IN();
			}
		} //-- end check to see if we add before or after. --//
	} //-- end check to see if the existing onload is a function. --//
} //-- end function addOnLoadEvent() --//

/*
 * Javascript for rotating header images
 */
var bannerImg = new Array();

// Enter the names of the images below
bannerImg[ 0 ] = "/images/header/cvnc_painter.png";
bannerImg[ 1 ] = "/images/header/cvnc_actor.png";
bannerImg[ 2 ] = "/images/header/cvnc_cello.png";
bannerImg[ 3 ] = "/images/header/cvnc_dancer.png";
bannerImg[ 4 ] = "/images/header/cvnc_sax.png";
bannerImg[ 5 ] = "/images/header/cvnc_singer.png";
bannerImg[ 6 ] = "/images/header/cvnc_sitar.png";

var newBanner = 0;
var totalBan = bannerImg.length;

function cycleHeaderPics()
{

	// declare variables
	var headerPicsElement = null;
	
	newBanner++;
	if (newBanner == totalBan) {
		newBanner = 0;
	}
	
	headerPicsElement = document.getElementById( "headerPics" );
	headerPicsElement.src=bannerImg[newBanner];

	// set the time below for length of image display
	// i.e., "4*1000" is 4 seconds
	setTimeout("cycleHeaderPics()", 3.5*1000);
}

//window.onload=cycleHeaderPics;
addOnLoadEvent( cycleHeaderPics, false );
