window.addEvent('domready', function(){
	
    /******************************************************
    the scrolling carousel functionality
    ******************************************************/

	// get a list of all carousel items
	var carouselItems = $$('#ysc #video-list li');
	// define how many carousel items are in each set
	var itemsPerSet = 3;
	
	// set the currently displayed set of items
	var currItem = 1;
	
	// set the max that currItem can be
	var currItemMax = carouselItems.length-itemsPerSet;

    /******************************************************
    add the video player and link the carousel to it
    ******************************************************/

	// use UFO to add the <object> tag to the DOM
	var VP = { movie:"/media/swf/vplayer.swf", width:"264", height:"235", majorversion:"8", build:"0", name:"flashvid", id:"flashvid", allowscriptaccess:"sameDomain" };
	UFO.create(VP, "video-player");
	
	// 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 = $('flashvid');
		
		// 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 callSetContent(url) {
				flashVideoPlayer.setContent(url);
			}
			
			// function to play the video
			function callPlayVideo() {
				flashVideoPlayer.playVideo();
			}
			
		    // function to send a list of videos to Flash
		    function callGetVideos(urls) {
		        flashVideoPlayer.getVideoList(urls);
		    }
			
			// get all of the <li> and <a> tags within the carousel
			var aTags = $$('#ysc #video-list a.video-link');

			// function to disable all of the carousel <li>s
			function removeCurrentClass() {
    			carouselItems.each(function(carouselItem, index){
    			    carouselItem.removeClass('current');
    			});
			}
			
			// 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 videoURLs to an array
			    videoURLs[index] = aTag.href;
			    
			    // add the click event
				aTag.addEvent('click', function(e){
					e = new Event(e);
					e.preventDefault();
					e.stopPropagation();
					// set the video to this <a> tag's href attribute
					callSetContent(this.href);
					// remove the class="current" from all <li> tags
					removeCurrentClass();
					// add it to this <li> tag
					this.getParent().addClass('current');
				});
			});
			
			// send the video URLs to Flash
			callGetVideos(videoURLs);
			
			// set overflow for list to auto - adds scrollbar
			function addOverflow() {
				// get reference to video list
				var vidList = $$('#video-list ul');
				// change overflow property
				vidList.setStyle('overflow', 'auto');
			};

			// set overflow for list to hidden - removes scrollbar
			function removeOverflow() {
				// get reference to video list
				var vidList = $$('#video-list ul');
				// change overflow property
				vidList.setStyle('overflow', 'hidden');
			};
			
			
			// set the options for shadowbox
			var options = {
							onOpen: removeOverflow,
							onClose: addOverflow
            };

            // initialize shadowbox with options
            Shadowbox.init(options);
		}
	} // end checkPlayerInDOM()
	
	// invoke the checkPlayerInDOM function
	id = setInterval(checkPlayerInDOM, 500);
	
});