/* JavaScript Functions */



// DATA FOR AUTO-ROTATING TESTIMONIES
//note: the programming is set up to play the 2nd quote in the list first. oh well.
var rotating_content = [
	{"name":"Tim",		"q":"Thank you for this devotional. It was very clear and precise and meaningful for one who desires to follow Christ."},
	{"name":"Isaac",	"q":"I started using these devotions last year in college and they were a great way for me to get my focus on where it should be."},
	{"name":"Nina", 	"q":"If I want to be a \"light\" to others, I know I have to make sure that my \"flame\" stays bright, and your Devotionals are a big part of that process."},
	{"name":"Mat",		"q":"Thanks for your wonderful and relevant ministry. God has definitely used your ministry to speak directly to me."},
	{"name":"Tony",		"q":"What an incredible message. I love the daily devotion that are sent out every day because it helps me get my day started off right."},
	{"name":"Ray",		"q":"Thank you very much for continuing to send these daily devotions out to my wife and I everyday. "},
	{"name":"Susan",	"q":"Thank you, Bryant, for these awesome daily devotions. I print a lot of them out for the guys in our shop."},
	{"name":"Kathi",	"q":"Rev. Wright's Daily Devotion is comforting and helps me stay focused on God's plan and on what He wants me to do."},
	{"name":"Alice",	"q":"I listen to your radio spot on the drive to work. I am going through a storm in my life right now, but I am so thankful for the blessed assurance that God is there with me."},
	{"name":"Becky",	"q":"These email devotions have quickly become the highlight of my day, but today it had an incredible impact."},
	{"name":"Greg",		"q":"With the flood of mail and messages we all get these days, the RFTH devotionals cut through the clutter and are a joy to read."},
	{"name":"Anonymous","q":"I start each day with the RFTH devotional. It gets my day off to a  good start."},
	{"name":"Joe",		"q":"Please know that your emails have helped my family. Our faith is stronger because of your good works."},
	{"name":"Taylor",	"q":"You have stirred a deeper godly happiness for His sake since reading The Daily Devotion!"},
	{"name":"Jenny",	"q":"I thank you for this ministry, it has changed my life, especially  my prayer life."},
	{"name":"Anonymous","q":"Your devotions have blessed me so many mornings when I come in to  work.  It seems to be directed right at me so many times!"},
	{"name":"Joan",		"q":"What a wonderful source for comforting others and receiving comfort from loving, caring Christians. Thank you most sincerely for this venue."},
	{"name":"Molly",	"q":"Wow! These devotions really help! My relationship with God has really improved because of these. Thanks."},
	{"name":"Anonymous","q":"It's not much but may this small contribution help you to continue sending the daily  devotions to many."},
	{"name":"Anonymous","q":"Thank you for your ministry. Your messages on 750 AM are inspirational and I appreciate the courage it take to broadcast those messages."},
	{"name":"Alice",	"q":"It would be so easy for 1-minute devotionals to be easy and pleasant; and yet you take on the most difficult questions."}

];

var itemcount = rotating_content.length;
var randomnumber = Math.floor(Math.random() * itemcount);
var itemno = randomnumber;
var rotate_speed = 8000; // 1000 = 1 second

$(document).ready(function(){ 
	
//INITIATE AUTO-ROTATING TESTIMONIES
	auto_rotatecontent();
	
	//INITIATE USER-ROTATING TESTIMONIES
	
	$('#leftcontrol').click(function(){
		if(itemno==0) itemno = itemcount-1;
		else itemno = itemno-1;
		window.clearTimeout(timeout); 
		user_rotatecontent(itemno);
	});
	$('#rightcontrol').click(function(){
		if(itemno == itemcount-1) itemno = 0; 
		else itemno = itemno+1;
		window.clearTimeout(timeout);
		user_rotatecontent(itemno); 
	});
	
	
	// INITIATE SEARCH AND MENU POP-UPS
	
	$('#link_search').click(function() {
		$('#what').hide();
		$('#who').hide();
		$('#link_what').removeClass('selected');
		$('#link_who').removeClass('selected');
		$('#search').fadeIn();
		return false;
	});
	
	$('#link_who').click(function(){
		$(this).addClass('selected');
		$('#link_what').removeClass('selected');
		$('#what').hide();
		$('#search').hide();
		$('#who').fadeIn();
		return false;
	});
	$('#link_what').click(function(){
		$(this).addClass('selected');
		$('#link_who').removeClass('selected');
		$('#who').hide();
		$('#search').hide();
		$('#what').fadeIn();
		return false;
	});
	
	$('#close_who').click(function(){
		$('#who').hide();
		$('#link_who').removeClass('selected');
		return false;
	});
	$('#close_what').click(function(){
		$('#what').hide();
		$('#link_what').removeClass('selected');
		return false;
	});
	$('#close_search').click(function(){
		$('#search').hide();
		return false;
	});
	
});


// AUTO-ROTATING TESTIMONIES

function auto_rotatecontent() {
	//alert(itemno);
	if(itemno == itemcount-1) itemno = 0; 
	 else itemno = itemno+1;
	$('#quote').html('<span class="dquo dark">&#8220;</span>' + rotating_content[itemno].q + ' <span class="quiet small"> - '  + rotating_content[itemno].name + '</span>');
	timeout = setTimeout("auto_rotatecontent();",rotate_speed); 
}
// USER-ROTATING TESTIMONIES

function user_rotatecontent(itemno){
	$('#quote').html('<span class="dquo dark">&#8220;</span>' + rotating_content[itemno].q + ' <span class="quiet small"> - '  + rotating_content[itemno].name + '</span>');
	timeout = setTimeout("auto_rotatecontent();",rotate_speed);  
 }


//	PLAY RADIO SPOTS
function Play( title, file ){
		window.open( "player.php?title=" + title + "&file=" + file, "player", "resizable=yes,scrollbars=yes,width=850,height=400" );
		return false;
	}
// PLAY TV SPOTS
function Playvideo(id, title, file ){
	window.open( "/player.php?id="+id+"&title=" + title + "&file=" + file, "player", "resizable=yes,scrollbars=yes,width=850,height=400" );
	return false;
}
