
/**************************************************
 * Random background image generator
 * Adapted from script used by: 
 * http://www.duke.edu/APSI/index.html
 * see CONFIG and USAGE sections below.
 **************************************************/

// The random number generator.
// returns -1 if there is an error.
function rand(n) {
	var rv = -1;
	var now = new Date();
	var seed = ( now.getTime() % 0xffffffff );
	seed = (0x015a4e35 * seed) % 0x7fffffff;
	rv = (seed >> 16) % n;
	return rv;
}

function getRandom( arrayToUse ) {
	var rnd = rand( arrayToUse.length );
	// if there's an error getting the random number,
	// use 0 as the default.
	if( rnd == null || rnd == -1 ){
		debug( "error generating random number" );
	  rnd = 0;
	}
	if( arrayToUse != null ){
		bg = arrayToUse[rnd];
		if( bg != null ){
			document.write ( bg ); 
			// debug( img );
		}
		else {
			// element is null
			debug( "no element at index " + rnd + " in backgrounds array" );
		}
	}
	else {
		// array is null
		debug( "backgrounds array is null" );
	}
}

debugOn = false;
function debug( msg ){
	if( debugOn ){
		alert( msg );
	}
}

// CONFIG:
// Set up the array of image tags
backgrounds = new Array();
backgrounds[0] = '<img src="/assets/images/header_01.jpg" width="371" height="70" alt="Duke University TIP montage" id="montage"/>';
backgrounds[1] = '<img src="/assets/images/header_02.jpg" width="352" height="70" alt="Duke University TIP montage" id="montage"/>';

// USAGE:
/* insert the following where you want the randomized
   item to appear (in this case, the array we're using
   is called 'backgrounds'):
	 
	 <script type="text/javascript"><!--
	   getRandom( backgrounds );
	 //--></script>
	 <noscript>
	 	<!-- if necessary, insert content for browsers that don't have Javascript enabled -->
	 </noscript>
	 
*/

function popUp(addr){

	if((screen.width == 800)||(screen.height == 600)){		
		window.open(addr,"Window1","resizable=yes,scrollbars=yes,menubar=no,width=700,height=400,toolbar=no,screenX=0,screenY=0");
	}

	else if((screen.width == 1024)||(screen.height == 768)){		
		window.open(addr,"Window1","resizable=yes,scrollbars=yes,menubar=no,width=800,height=688,toolbar=no,screenX=0,screenY=0");
	}
	else{
		window.open(addr,"Window1","resizable=yes,scrollbars=yes,menubar=no,width=800,height=688,toolbar=no,screenX=50,screenY=20");
	}

}
