jQuery(document).ready(
	function()
	{
		do_player();
		
		// #2 set up the jquery cylce slideshow
		jQuery('#slideshow').cycle(
			{
				fx			: 'fade',
				speed		: 'slow',
				before	: function(currSlide, nextSlide, opts)
				{
					var index = jQuery(this).parent().children().index(this);
					
					// Image Slides
					opts.timeout = 3000;
					
					// Video Slides
					if(index == 0)
					{
						do_player();

						opts.timeout = 5000;
					}
				} 
			}
		)

		// #5 Play the video if the play video button is clicked
		jQuery('#play-video').click(
			function()
			{
				jQuery('#slideshow')
		    	// Pause the slideshow
		    	.cycle('pause')
		    	// Move to the video slide
		    	.cycle(3);
		    	
				// play the video
				jwplayer("player-container").play(true);		    
		    			 
		    return false; 
			}
		);
	}
);

function do_player()
{
	// #1 Set up the video player
	jwplayer("player-container").setup(
		{ 
			autostart: false,
			flashplayer: "BVModules/Themes/happilyeverafterwords/video/player.swf",
			controlbar: "none",
			file: "http://www.happilyeverafterwords.com/BVModules/Themes/happilyeverafterwords/video/anniversary_box_teaser.m4v",
			//file: "http://colabdevelopment.com/anniversary-box/video/anniversary_box_teaser_9.17.10.m4v",
			image: "images/new-img/video-ph.jpg",
			backcolor: "d6caab",
			wmode: 'transparent',
			height: 261, 
			width: 464,
			skin: "BVModules/Themes/happilyeverafterwords/scripts/anniversarybox.zip"
		}
	);
	
	// #3 What to do while the video is playing
	jwplayer("player-container").onPlay(
		function()
		{
			// Pause the slideshow
			jQuery('#slideshow').cycle('pause');
		}
	);
	
	// #4 What to do while the video is buffering
	jwplayer("player-container").onBuffer(
		function()
		{
			// Pause the slideshow
			jQuery('#slideshow').cycle('pause');
		}
	);
	
	// #5 What to do when the video is finished
	jwplayer("player-container").onComplete(
		function()
		{			
	    // Pause the slideshow
	    jQuery('#slideshow').cycle('resume');
		}
	);
}
