window.addEvent('domready', function(){
    
    // create a var to hold the setInterval() ID
	var id = null;
	
    // function to see if the UFO <object> has been added to the DOM
	function checkPlayerInDOM() {
	    // get a reference to the flash vid player
		var flashVideoPlayer = $('vidplayer');

		// see if the flash vid player is in the DOM
		if(flashVideoPlayer != null) {
		    // if it is, clear the timeout
			window.clearTimeout(id);

			// function to set the video 
			function callPauseVideo() {
				flashVideoPlayer.pauseVideo();
			}

			// function to play the video
			function callPlayVideo() {
				flashVideoPlayer.playVideo();
			}

			// get all of the <li> and <a> tags within the carousel
			var aTags = $$('#nav a');

			// create an array to hold the video locations
			var videoURLs = [];

			// loop through each of the <a> tags and tell
			// them what to do when clicked
			aTags.each(function(aTag, index){
			    // add the click event
				aTag.addEvent('click', function(e){
					e = new Event(e).preventDefault();
					// set the video to this <a> tag's href attribute
					callPauseVideo();
				});
			});
			
			// set the options for shadowbox
			var options = {
                onClose: callPlayVideo
            };

            // initialize shadowbox with options
            Shadowbox.init(options);

		}
	} // end checkPlayerInDOM()

	// invoke the checkPlayerInDOM function
	id = setInterval(checkPlayerInDOM, 500);    
    
});