window.onload = loadData;

var radioWin = null;
var songWindow = null;
var reflectWindow = null;
var requestWindow=null;
var thisPrayer=-1;
var timerID = null;
var timerID3=null;
var prayerList=null;
var thisPsalm1=0;
var thisStatement=1;


var psalmArray = new Array(
"Happy are those whose delight is in the law of the Lord",
"Happy are those who take refuge in God",
"I cry aloud to the Lord, and He answers me from His holy hill",
"You alone, O Lord, make me lie down in safety",
"Let all who take refuge in God rejoice",
"The Lord accepts my prayer",
"I will sing praise to the name of the Lord, the Most high",
"O Lord, how majestic is your name in all the earth",
"I will sing praise to your name, O Most High",
"O Lord, you will do justice for the oppressed",
"The Lord is righteous - the upright shall behold His face",
"You, O Lord, will protect us",
"Consider and answer me, O Lord my God",
"The Lord looks down from heaven on humankind",
"Walk blamelessly, and do what is right, and speak truth from your heart",
"Protect me, O God, for in you I take refuge",
"I call upon you, O God, incline your ear to me, hear my prayer",
"I love you, O Lord, my strength - my rock, my fortress, and my deliverer",
"The heavens are telling the glory of God",
"May God grant you your heart's desire, and fulfill all your plans",
"Be exalted, O Lord - we will sing and praise your power",
"All the ends of the earth shall remember and turn to the Lord",
"The Lord is my shepherd, I shall not want",
"Lift up your heads, O gates - that the King of Glory may come in",
"Be mindful of your mercy, O Lord, and of your steadfast love",
"God's steadfast love is before my eyes, and I walk in faithfulness to Him",
"The Lord is my light and my salvation; whom shall I fear?",
"To you, O Lord, I call; my rock, do not refuse to hear me",
"Ascribe to the Lord the glory of His name; worship the Lord in holy splendor",
"O Lord my God, I cried to you for help, and you have healed me",
"In you, O Lord, I take refuge",
"Let all who are faithful offer prayer to God",
"Sing to God a new song; play skillfully on the strings, with loud shouts",
"O magnify the Lord with me, and let us exalt His name together",
"Great is the Lord, who delights in the welfare of His servant",
"O continue your steadfast love to those who know you - to the upright of heart",
"Be still before the Lord, and wait patiently for Him",
"O my God - make haste to help me, O Lord, my salvation",
"Hear my prayer, O Lord, and give ear to my cry",
"You are my help and my deliverer; do not delay, O my God.",
"Blessed be the Lord, the God of Israel, from everlasting to everlasting",
"As the deer longs for water, so my soul longs for you, O God",
"Hope in God; for I shall again praise Him, my help and my God",
"Rise up, come to our help.  Redeem us for the sake of your steadfast love", 
"Your throne, O God, endures forever and ever",
"God is our refuge and strength, a very present help in trouble",
"Clap your hands, all you peoples; shout to God with loud songs of joy",
"We ponder your steadfast love, O God, in the midst of your temple",
"Hear this, all you peoples - the mediatation of my heart shall be understanding",
"Our God comes and does not keep silence",
"Have mercy on me, O God, according to your steadfast love",
"I trust in the steadfast love of God forever and ever",
"Fools say in their hearts there is no God",
"Hear my prayer, O God, give ear to the words of my mouth",
"Cast your burden on the Lord and He will sustain you",
"O Most High, when I am afraid, I put my trust in you",
"Be merciful to me, O God, for in you my soul takes refuge",
"Surely there is a reward for the righteous",
"O my strength, I will watch for you; for you, O God, are my fortress",
"With God we shall do valiantly",
"Hear my cry, O God, listen to my prayer",
"God alone is my rock and my salvation, my fortess; I shall never be shaken",
"O God, you are my God - my soul thirst for you as in a dry and thirsty land",
"Let the righteous rejoice in the Lord and take refuge in Him",
"O you who answers prayer!  To you all flesh shall come",
"Bless our God, O peoples, let the sound of His praise be heard",
"Let the peoples praise you, O God, let all the peoples praise you",
"Lift up a song to God who rides upon a cloud - His name is the Lord",
"Answer me, O Lord, for your steadfast love is good",
"Be pleased, O God, to deliver me.  O Lord, make haste to help me",
"I will praise you with the harp for your faithfulness, O my God",
"Blessed be the Lord, the God of Israel, who alone does wondrous things.",
"God is the strength of my heart and my portion forever",
"Yet God, my King, is from of old, working salvation in the earth",
"We give thanks to you, O God - people tell of your wondrous deeds",
"Make vows to the Lord your God, and perform them",
"I will call to mind the deeds of the Lord; I will remember your wonders of old",
"God commanded the skies above, He rained down on them manna to eat",
"Help us, O God of our salvation, for the glory of your name",
"Restore us, O God, let your face shine, that we may be saved",
"Sing aloud to God our strength; shout for joy to the God of Jacob",
"Give justice to the weak and the orphan; maintain the right of the lowly and destitute",
"O God, do not keep silence; do not hold your peace or be still, O God",
"How lovely is your dwelling place, O Lord of hosts",
"The Lord will give what is good, and our land will yield its increase",
"Incline your ear, O Lord, and answer me, for I am poor and needy",
"Singers and dancers alike say all my springs are in God.",
"O God, let my prayer come before you; incline your ear to my cry",
"I will sing of your steadfast love, O Lord, forever",
"Let the favor of the Lord our God be upon us",
"My refuge and my fortress; my God in whom I trust",
"It is good to give thanks to the Lord, to sing praises to His name",
"More majestic than thunders of mighty waters, majestic on high is the Lord",
"The Lord has become my stronghold, and my God the rock of my refuge",
"Let us worship and bow down, let us kneel before the Lord, our Maker",
"O sing to the Lord a new song; sing to the Lord all the earth",
"Rejoice in the Lord, O you righteous, and give thanks to His holy name",
"Make a joyful noise to the Lord, all the earth, break forth into joyous song",
"Extol the Lord our God; worship at His footstool.  Holy is He",
"Enter God's gates with thanksgiving, and His courts with praise",
"I will sing of loyalty and of justice; to you, O Lord, I will sing",
"Hear my prayer, O Lord; let my cry come to you",
"Bless the Lord, O my soul, and all that is within me, bless His holy name",
"May the glory of the Lord endure forever; may the Lord rejoice in His works",
"Let the hearts of those who seek the Lord rejoice",
"O give thanks to the Lord, for He is good; His steadfast love endures forever",
"God raises up the needy out of distress, and makes their families like flocks",
"I will give thanks to you, O Lord, among the people",
"Do not be silent, O God of my praise",
"The Lord is at your right hand",
"The fear of the Lord is the beginning of wisdom",
"Happy are those who fear the Lord, who greatly delight in His commandments",
"Blessed be the name of the Lord from this time on and forevermore",
"Tremble, O earth, at the presence of the Lord . . .  who turns the rock in to a pool of water",
"The Lord has been mindful of us; He will bless us",
"I love the Lord, because He has heard my voice and my supplications",
"Praise the Lord, all you nations!  Extol Him, all you peoples",
"O give thanks to the Lord, for He is good",
"I long for your salvation, O Lord, and your Law is my delight",
"In my distress I cry to the Lord, that He may answer me",
"My help comes from the Lord, who made heaven and earth",
"I was glad when they said to me let us go to the house of the Lord.",
"To you I lift up my eyes, O you who are enthroned in the heavens",
"Our help is in the name of the Lord, who made heaven and earth",
"Those who trust in the Lord are like Mount Zion, which cannot be moved",
"The Lord has done great things for us, and we rejoiced",
"Unless the Lord builds the house, those who build it labor in vain",
"Happy is every one who fears the Lord, who walks in His ways",
"The blessing of the Lord be upon you.  We bless you in the name of the Lord",
"Out of the depths I cry to you, O Lord.  Lord, hear my voice",
"Hope in the Lord from this time on and forevermore",
"Let us go to God's dwelling place; let us worship at His footstool",
"In Zion the Lord ordained His blessing, life forevermore",
"The Lord, maker of heaven and earth, bless you from Zion",
"Praise the Lord, for the Lord is good; sing to His name, for He is gracious",
"O give thanks to the God of heaven, for His steadfast love endures forever",
"Let my tongue cling to the roof of my mouth, if I do not remember God",
"I give thanks to you, O Lord, with my whole heart",
"Search me, O God, and know my heart; test me and know my thoughts",
"You are my God; give ear to the voice of my supplications.",
"Let my prayer be counted to you as incense before God",
"I cry to you, O Lord; You are my refuge, my portion in the land of the living.",
"Hear my prayer, O Lord; give ear to my supplications in your faithfulness",
"Blessed be the Lord, my rock; my rock and my fortress, my stronghold and my deliverer",
"The Lord is gracious amd merciful, slow to anger and abounding in steadfast love",
"The Lord lifts up those who are bowed down; the Lord loves the righteous",
"How good it is to sing praises to our God; for He is gracious",
"Praise the Lord from the heavens; praise Him, all His host",
"Sing to the Lord a new song, His praise in the assembly of the faithful",
"Let everything that has breath praise the Lord!  PRAISE THE LORD!"
);

var statements = new Array(
"Seeking to share God's healing light and the transforming love of Jesus",
"Magnifying God's call to be the hands and feet of Christ by serving the needs of our community and congregation in an ever changing world"
);

function loadData() {
	loadPrayers(prayerNew, "newp");
	loadPsalms1();
	loadStatements();
}

function loadStatements() {
	if(thisStatement == 0)
		thisStatement = 1;
	else
		thisStatement = 0;
	
	var result = statements[thisStatement];
	document.getElementById("stateThis").innerHTML=result;

	timerID3=setTimeout("loadStatements()", 8*1000);
}

function loadPsalms1() {
	thisPsalm1= Math.floor((Math.random() * psalmArray.length));
	
	var thisPsalm = thisPsalm1 +1;
	var result = psalmArray[thisPsalm1] + "<br> - Psalm " + thisPsalm;
	document.getElementById("psalmList1").innerHTML=result;

	timerID2=setTimeout("loadPsalms1()", 8*1000);
}

function loadPrayers(thisList, listType) {
	prayerList=thisList;
	thisType=listType;
	clearTimeout(timerID);
	thisPrayer= -1;
	if(thisType=="newp") {
		document.getElementById("newp").innerHTML="Displaying New Prayers";
		document.getElementById("oldp").innerHTML=" ";
	}
	else {
		document.getElementById("oldp").innerHTML="Displaying Old Prayers";
		document.getElementById("newp").innerHTML=" ";
	}
	rotatePrayers();
}

function rotatePrayers() {
	thisPrayer++;
	if(thisPrayer==prayerList.length) {
		thisPrayer = 0;
	}
	document.getElementById("prayers").innerHTML=prayerList[thisPrayer];

	timerID=setTimeout("rotatePrayers()", 12*1000);
}

function pausePrayers() {
	clearInterval(timerID);
}

function nextPrayer() {
	if(prayerList==null){
		loadPrayers(prayerNew, "newp");
	}
	else {
	thisPrayer++;
	if(thisPrayer==prayerList.length) {
		thisPrayer = 0;
	}
	document.getElementById("prayers").innerHTML=prayerList[thisPrayer];
	clearTimeout(timerID);
	timerID=setTimeout("rotatePrayers()", 12*1000);
	}
}

function prevPrayer() {
	if(prayerList==null){
		loadPrayers(prayerNew, "newp");
	}
	else {
	thisPrayer--;
	if(thisPrayer<0) {
		thisPrayer = prayerList.length-1;
	}
	document.getElementById("prayers").innerHTML=prayerList[thisPrayer];
	clearTimeout(timerID);
	timerID=setTimeout("rotatePrayers()", 12*1000);
	}
}

function closeWin(thisWindow){
	if (thisWindow!= null){
		if(!thisWindow.closed)
			thisWindow.close();
	}
}

function prayersongRadio(url,width,height) {
	closeWin(radioWin);
	var settings="";
	settings="toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=no,"+
	"resizable=yes,left=50,top=100,width="+width+",height="+height;
	
	radioWin = window.open(url, 'radioWin', settings);
}

function openReflections(url, width, height){
	closeWin(reflectWindow);
	
	var settings="";
	settings="toolbar=no,location=yes,directories=no,"+
	"status=no,menubar=no,scrollbars=yes,"+
	"resizable=yes,left=50,top=100,width="+width+",height="+height;
	
	reflectWindow=window.open(url, 'reflectWin', settings);
	reflectWindow.focus();
}

function openPrayerRequest(url, width, height){
	
	closeWin(requestWindow);
	var settings="";
	
	var settings="";
	settings="toolbar=no,location=no,directories=no,"+
	"status=no,menubar=no,scrollbars=yes,"+
	"resizable=yes,left=377,top=150,width="+width+",height="+height;
	
	requestWindow= window.open(url, 'reflectWin', settings);
	requestWindow.focus();	
}

