
var RTI;
if(!RTI) RTI = {};


window.addEvent('domready', function() { 
	RTI.videoPlayer = new videoPlayer();
}); // end domready


// -------------------------------------------------------------------------------------------------
// Create the functionality for the video switching buttons
// -------------------------------------------------------------------------------------------------
function videoSelector() {

	
	// Create a div element if it doesn't already exist
	
	$('video-info').empty();
	$('video-info').setStyles({
		'background-color':'#ffffff'
	});
	
	
	//var vids = ['1I8J6NRCfFE', 'seWNz5B9Wh8', '9l2yU8YMBPk', '7YR3IqDwXEs', 'Mm8lbtKicKU'];
	var vids = ['', 'q2Q7A8j0z24', 'bUO4jtIvsQs', 'xXqvx_86gcA', '2t7J-Fj66Ms'];
	var captions = ['', 'From the Get Go', 'Deep Things', 'God Nods', 'Resurrected Bodies'];
	
	// assign the individual array items to the elements
	for(var i=0;i< $$('.vb').length;i++) {
		$$('.vb')[i].vid = vids[i];
		$$('.vb')[i].caption = captions[i];
	}
	
	
	
	// assign the mouse events
	$$('.vb')
 		.addEvent('mouseover', function() {
 			$('video-info').set('html', this.caption);
 		})
 		.addEvent('mouseout', function() {
 			;
 		})
		.addEvent('click', function() {
			playVid(this.vid);
		});	

}

var videoPlayer = new Class({
	initialize: function(options) {
		this.btns = $$('.vb');
		this.vids = ['TK8B0jZCF1I', 'd3SNa4Txsqc', 'V_aQhS2r7yQ', 'm8DE_qBTm_o'];
		this.captions = ["What to do when you're in the pit (2 of 3)", "What to do when you're in the pit (3 of 3)", '2 Cor. 4:16-18', 'Steve & Sarah&rsquo;s Introduction'];
		
		/*this.vids = ['V_aQhS2r7yQ', 'm8DE_qBTm_o', 'q2Q7A8j0z24', '6dmX3WtnTQs'];
		this.captions = ['2 Cor. 4:16-18', 'Steve & Sarah&rsquo;s Introduction', 'From the Get-Go', 'Don&rsquo;t Lose Heart', 'Deep Things'];*/
		
		this.tip = $('video-info');
		
		/* Colors */
		this.startBGColor = '#f0eee6';
		
		this.btns.setStyle('cursor','pointer');
		
		this.tip.setStyles({
			'text-align':'center',
			'padding':'5px 0px',
			'font-family':"'trebuchet ms', verdana, arial, sans-serif"
		});
		
		this.tipFx = new Fx.Morph(this.tip, {duration:'300'
		
		});
		
		this.btns.set('opacity', 0.8);
		
		this.btns.addEvent('mouseover', function(e) { 
		  //console.log(this.captions);
		  this.tipFx.start({
			  'background-color':['#f0eee6','#61a5d4'],
				'color':['#6b6a35', '#ffffff']
		  
		  }).chain(
				function() {
					this.start({
						'background-color':['#61a5d4','#f0eee6'],
						'color':['#ffffff', '#6b6a35']
					});
				}
			);
		  var i = this.btns.indexOf(e.target);
		  
		  var myFx = new Fx.Morph(e.target, {});
		  myFx.start({
				'opacity':['.5','1']
			});
			this.tip.set('html', this.captions[i]);
			
		}.bind(this));
		
		this.btns.addEvent('mouseout', function(e) { 
		  //console.log(this.captions);
		  var myFx = new Fx.Morph(e.target, {});
		  e.target.set('opacity', '.8');
		  // this.btnFx.start({
// 				'background-color':['#f88a40','#f3f1e9'],
// 				'color':['#ffffff','#5f6462']
// 			});
			this.tipFx.cancel();
			this.tip.setStyles({
				'background-color':'#f0eee6',
				'color':'#6b6a35'
			});
			
			
			
		}.bind(this));

		this.btns.addEvent('click', function(e) {				
		  var i = this.btns.indexOf(e.target);
		  this.playVid(this.vids[i]);
		}.bind(this));	
		
		this.embedStartingVid();
	},
	playVid: function(vid) {
		
		var so = new SWFObject('http://www.youtube.com/v/' + vid + '&autoplay=1&rel=0', "sotester", "298", "192", "8", "#000000");
		//so.addVariable("flashVarText", "this is passed in via FlashVars for example only"); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.write("yt");
	},
	embedStartingVid: function() {
		var so = new SWFObject('http://www.youtube.com/v/Q_Upn9sgCsI&rel=0', "sotester", "298", "192", "8", "#000000");
		so.write("yt");
	}
	
	
});


// -------------------------------------------------------------------------------------------------
// Play the selected video clip
// -------------------------------------------------------------------------------------------------
function playVid(id) {
	//var tag = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' + id + '&autoplay=1"></param><embed src="http://www.youtube.com/v/' + id + '&autoplay=1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>';
	
	//var tag = '<h2>test</h2>';
	
	//$('yt').innerHTML = tag;
	//document.getElementById('yt').innerHTML = tag;
	//e('now playing...');
	
	var so = new SWFObject('http://www.youtube.com/v/' + id + '&autoplay=1', "sotester", "298", "192", "8", "#000000");
		//so.addVariable("flashVarText", "this is passed in via FlashVars for example only"); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.write("yt");
		
	
}

// -------------------------------------------------------------------------------------------------
// Embed an initial video clip in the playback area
// -------------------------------------------------------------------------------------------------
function embedStartingVid() {
	var so = new SWFObject('http://www.youtube.com/v/m8DE_qBTm_o', "sotester", "298", "192", "8", "#000000");
	so.write("yt");
}




