var isIE = navigator.appName.toLowerCase().indexOf('internet explorer')+1;
var isMac= navigator.appVersion.toLowerCase().indexOf('mac')+1;
function SoundManager(container) {  // DHTML-controlled sound via Flash
  var self=this; this.movies=[]; this.container=container; this.unsupported=0; this.defaultName='default';
  this.FlashObject = function(url) { var me = this; this.o = null; this.loaded = false;
    this.isLoaded= function(){if(me.loaded){return true} if(!me.o) {return false}
      me.loaded= ((typeof(me.o.readyState)!='undefined' && me.o.readyState == 4) || (typeof(me.o.PercentLoaded)!='undefined' && me.o.PercentLoaded() == 100));
      return me.loaded;}
    this.mC= document.createElement('div'); this.mC.className= 'movieContainer';
    this.CSS=this.mC.style;  this.CSS.position='absolute'; this.CSS.left='-3333px';this.CSS.top='-3333px';
    this.CSS.width='64px'; this.CSS.height='64px';
    var html = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"><param name="movie" value="'+url+'"><param name="quality" value="high"></object>','<embed src="'+url+'" width="1" height="1" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'];
    if (navigator.appName.toLowerCase().indexOf('microsoft')+1) {
          this.mC.innerHTML=html[0]; this.o=this.mC.getElementsByTagName('object')[0];}
		else{ this.mC.innerHTML=html[1]; this.o=this.mC.getElementsByTagName('embed')[0];}
    document.getElementsByTagName('div')[0].appendChild(this.mC);
  }
	this.addMovie = function(movieName,url){ self.movies[movieName]= new self.FlashObject(url); }
  this.checkMovie = function(movieName){ movieName= movieName||self.defaultName;
    if (!self.movies[movieName]){self.errorHandler('checkMovie','Exception: Could not find movie',arguments);return false;}
		else{return (self.movies[movieName].isLoaded())?self.movies[movieName]:false;}
  }
  this.errorHandler = function(methodName,message,oArguments,e) {
    //writeDebug('<div class="error">soundManager.'+methodName+'('+self.getArgs(oArguments)+'): '+message+(e?' ('+e.name+' - '+(e.message||e.description||'no description'):'')+'.'+(e?')':'')+'</div>');
  }
  this.play = function(soundID,loopCount,noDebug,movieName) {
    if (self.unsupported) return false;
    movie = self.checkMovie(movieName); if (!movie) return false;
    if (typeof(movie.o.TCallLabel)!='undefined') {
      try { self.setVariable(soundID,'loopCount',loopCount||1,movie); movie.o.TCallLabel('/'+soundID,'start');}
      catch(e){}
    }
  }
  this.stop = function(soundID,movieName) { if (self.unsupported) {return false}
    movie = self.checkMovie(movieName); if (!movie){return false}
    try { movie.o.TCallLabel('/'+soundID,'stop');} catch(e){}
  }
  this.getArgs = function(params) {
    var x= params?params.length:0; if (!x) return '';
    var result= '';
    for (var i=0; i<x; i++) {
      result += (i&&i<x?', ':'')+(params[i].toString().toLowerCase().indexOf('object')+1?typeof(params[i]):params[i]);
    } return result
  }
  this.setVariable = function(soundID,property,value,oMovie){if (!oMovie){return false}
    try { oMovie.o.SetVariable('/'+soundID+':'+property,value);}
		catch(e) {self.errorHandler('setVariable','Failed',arguments,e);}}
  this.setVariableExec = function(soundID,fromMethodName,oMovie) {
    try { oMovie.o.TCallLabel('/'+soundID,'setVariable');}catch(e){}}
  this.callMethodExec = function(soundID,fromMethodName,oMovie) {
    try { oMovie.o.TCallLabel('/'+soundID,'callMethod');}catch(e){}  }
  this.callMethod = function(soundID,methodName,methodParam,movieName) {
    movie = self.checkMovie(movieName||self.defaultName);
    if (!movie){return false}
    self.setVariable(soundID,'jsProperty',methodName,movie);
    self.setVariable(soundID,'jsPropertyValue',methodParam,movie);
    self.callMethodExec(soundID,methodName,movie);
  }
  this.setPan = function(soundID,pan,movieName) { self.callMethod(soundID,'setPan',pan,movieName);}
  this.setVolume = function(soundID,volume,movieName) { self.callMethod(soundID,'setVolume',volume,movieName);}
  // constructor - create flash objects
  if (isIE && isMac) {this.unsupported = 1;}
  if (!this.unsupported){this.addMovie(this.defaultName,'soundcontroller.swf');}
}
function SoundManagerNull() {
  // Null object for unsupported case
  this.movies = []; // movie references
  this.container = null;
  this.unsupported = 1;
  this.FlashObject = function(url) {}
  this.addMovie = function(name,url) {}
  this.play = function(movieName,soundID) {
    return false;
  }
  this.defaultName = 'default';
}
function writeDebug(msg) { return;}
var soundManager = null;
function soundManagerInit() { soundManager = new SoundManager(); }//
//************************************Above Code by Scott Schiller, Thankyou.********
//code for index page to test scroll
//<form name="f"><input type="text" size="80" name="info" id="info" /></form>
//Welcome v1.0  
//uses self-invoking function style: 
//self invokes Pio(), then onload invokes Pio.init()

var Pio=function() {
	
	var title='Rosary.Beads', ur='http://rosary-beads.blogspot.com/', ua= navigator.userAgent.toLowerCase(), d= window.document;
  var aut="Richard Maloney", ver='1.0', year="2006", web="www.hismercy.ca";
	     if (ua.indexOf('konqueror')+1){title=0;}
	else if (ua.indexOf('safari') + 1){title=0;}
	else if (ua.indexOf('omniweb')+1){title=0;}
	else if (ua.indexOf('opera') +1){title=0;}
	else if (ua.indexOf('webtv')+1){title=0;}
	else if (ua.indexOf('icab')+1){title=0;}
  if (!title) { alert("Due to the sound features, please use either Internet Explorer or Mozilla Firefox to see and hear Rosary.Beads\n(Opera 9 will be supported next)");return}
	var Credits='\nCredits:\n-To my family: Lillian, Mary, Joeseph, Elizabeth, Emma, and Anastasia'+
							'\n-Scott Schiller all the javascript programmers out there'+
							'\n-Fred Shubert @ www.HisMercy.ca for hiring me'+
							'\n-Ruben M. Villarreal, Jr. for his voice and encouragement'+
							'\n-To my dad, www.dickmaloney.ca, who is now totally paralyzed'+
							'\n-And finally to anyone who will make use of this- God Bless you all!';
  var Copyright=title+' '+ver+'\n'+ur+'\nAuthor: '+aut+' '+year;
  var about=function(){alert(Copyright+Credits)},
		 Tempus={counter:0, timer:0, func: null,
		         quiesco:function(seconds,func){ 
						   if (seconds){//if seconds arg= timeout mode
									 Tempus.timer=seconds*10; Tempus.func=func;
									 Tempus.functus=function(){
										 Tempus.counter++;
										 if (Tempus.counter< (Tempus.timer) ){ return;}     //wait the seconds
										 else {Tempus.functus=Tempus.func;Tempus.counter=0;}//alert("func executed")//do the function
									 }
							 }  
							 else{Tempus.functus=function(){return;};}//alert("func stopped")
						 },
		         functus:function(){Tempus.quiesco()},
		           tempo:setInterval('window.Pio.Tempus.functus()',100)}; 
	  /*Tempus={ counter:0, quiesco:function(){return;},
	                functus:function(){Tempus.quiesco()},f:function(){Tempus.functus()},
                  interrogo:function(){Tempus.quiesco()},ineo:function(){Tempus.quiesco()},
									tempo:setInterval('window.Tempus.f()',128)}*/

			this.confirmExit=function (){
				if(!this.times) {this.times=0}
				times++; if(times==2){window.onbeforeunload=''}
				return 'Leaving will reset the rosary';
			}

			function exNihilo(type,obj){ var temp = d.createElement(type); 
			  for (arg in obj) { temp[arg]= obj[arg];} return temp;}
		 
			
			// create the GUI id="pio"  // var pio is Pio.Tablet 
			var pio=exNihilo('div',{id:'pio',className:'rose'}); 
			function Pio(e){pio.appendChild(e);}
			  
	    // Rose() executed 'after onload'
			function Rose() {//alert('title '+title);
				//return;
				Pio( exNihilo('span',{id:'mysteryInfo',innerHTML: title}) );
				Pio( exNihilo('span',{id:'infoBut',    innerHTML:'?',      onmouseover:function(){this.style.color='#ff0000'}, onmouseout:function(){this.style.color='#999999'}, onclick:about }) );
				//Pio( exNihilo('span',{id:'exitBut',    innerHTML:'X',      onmouseover:function(){this.style.color='#ff0000'}, onmouseout:function(){this.style.color='#999999'} }) );
				Pio( exNihilo('span',{id:'dragBar',    innerHTML:'&#8801;',onmouseover:function(){this.style.color='#00ff00'}, onmouseout:function(){this.style.color='#999999'},title:'Click to drag' }) );      
				Pio( exNihilo('span',{id:'playBut',    innerHTML:'Play&gt;',   onmouseover:function(){this.style.color='#ff0000'}, onmouseout:function(){this.style.color='#000000'}, onclick:function(){Beads.startRosary()}  }) );
				Pio( exNihilo('img', {id:'crucifix', src:'images/crucifix.gif',   onmouseover:function(){this.style.color='#ff0000'}, onmouseout:function(){this.style.color='#000000'} }) );//Tempus.quiesco( 5,function(){Beads[Beads.currentBead++].startPrayer();} ) 
				
				Pio( exNihilo('span',{id:'autoBut',    innerHTML:'&#8226;&nbsp;&nbsp;&nbsp;&nbsp;', onclick:function(){this.brother.style.color='#933';this.style.color='#0d0';Beads.isAuto=true;  } }) );
				Pio( exNihilo('span',{id:'manBut',     innerHTML:'&#8226;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', onclick:function(){this.brother.style.color='#933';this.style.color='#0d0';Beads.isAuto=false; } }) );
				
				Pio( exNihilo('span',{id:'joyBut',     innerHTML:'&#8226;', onclick:function(){} }) );
				Pio( exNihilo('span',{id:'sorBut',     innerHTML:'&#8226;', onclick:function(){} }) );
				Pio( exNihilo('span',{id:'gloBut',     innerHTML:'&#8226;', onclick:function(){} }) );
				Pio( exNihilo('span',{id:'lumBut',     innerHTML:'&#8226;', onclick:function(){} }) );
								
				Pio( exNihilo('span',{id:'pioInfo',    innerHTML:'~~'}) );
				
				Pio( exNihilo('span',{id:'Tableau',className:'Tableau-Panel',innerHTML:'web rosary<br />Pio.Beads'}) );
				d.body.appendChild(pio);
				
				// the following works out to Pio.Tablet.DragBar and Pio.Tablet.Tableau etc.
				pio.Tableau=d.getElementById("Tableau"); pio.DragBar=d.getElementById("dragBar");
				pio.pioInfo=d.getElementById("pioInfo"); pio.mysteryInfo=d.getElementById("mysteryInfo");
				pio.infoBut=d.getElementById("infoBut"); //pio.exitBut=d.getElementById("exitBut"); 
        pio.playBut=d.getElementById("playBut"); pio.crucifix=d.getElementById("crucifix");
				pio.autoBut=d.getElementById("autoBut"); pio.manBut=d.getElementById("manBut");			
				pio.autoBut.brother=pio.manBut;          pio.manBut.brother=pio.autoBut;
				pio.SM=d.getElementById("sorBut");       pio.JM=d.getElementById("joyBut");
				pio.GM=d.getElementById("gloBut");       pio.LM=d.getElementById("lumBut");
				
							
				//make Pio.Beads  Beads[n] is the html element
				this.Beads=[]; var numOfBeads=61;        
						
				//Preces markup
				var spaces='<br /><br /><br /><br /><br /><br /><br />';
				this.Beads.AC= '<div class="Preces" style="font-size:17px;text-align:center;">'+spaces+'IN the name of<br />the Father,<br />and of the Son,<br />and of the Holy Spirit. &nbsp;Amen.<br /><br /><br /></div> 	<span style="font-size:16px;line-height:25px;text-align:left;">I believe in God,<br /> the Father Almighty,<br />Creator of heaven and earth;<br />and in Jesus Christ,<br />His only Son, our Lord;<br />Who was conceived by the Holy Spirit,<br />Born of the Virgin Mary,<br />suffered under Pontius Pilate,<br />was crucified,<br />died,<br />and was buried.<br /><br />He descended into hell;<br />The third day He rose again from the dead,<br />He ascended into Heaven,<br />Sits at the right hand of God the Father Almighty;<br />From thence He shall come to judge the living and the dead.<br /><br />I believe in the Holy Spirit,<br />the Holy Catholic Church,<br />the Communion of Saints,<br />the forgiveness of sins,<br />the resurrection of the body,<br />and life everlasting.<br />Amen.';
  			this.Beads.HM= '<span class="Preces">'+spaces+'Hail Mary,<br />full of grace,<br />the Lord is with thee;<br />Blessed art thou among women, and blessed is the fruit of thy womb, Jesus.<br />Holy Mary,<br />Mother of God,<br />Pray for us sinners,<br />now and at the hour<br />of our death.<br />Amen.</span>';
				this.Beads.OF= '<span class="Preces">'+spaces+'Our Father,<br />Who art in Heaven,<br />hallowed be Thy Name.<br />Thy kingdom come,<br />Thy will be done on earth as it is in Heaven.<br />Give us this day our daily bread, and forgive us our trespasses,<br />as we forgive those who trespass against us.<br />And lead us not into temptation, but deliver us from evil.<br />Amen.</span>';
				this.Beads.HGO='<span class="Preces">'+this.Beads.HM+'<br /><br /><br />Glory be<br />to the Father,<br />and to the Son,<br />and to the Holy Spirit.<br />As it was in the beginning, is now, and ever shall be,<br />world without end.<br />Amen.   <br /><br /><br />0 my Jesus,<br />forgive us our sins,<br />save us from the fires of Hell: &nbsp;lead all souls to Heaven especially those who are most in need of Thy Mercy.<br /></span>';
				this.Beads.HHQ='<span class="Preces">'+spaces+'Hail, holy Queen,<br />Mother of Mercy;<br />our life,<br />our sweetness,<br />and our hope.<br />To thee do we cry, poor banished children of Eve;<br />to thee do we send up our sighs, mourning and weeping in this valley of tears.<br />Turn, then, most gracious advocate, thine eyes of mercy towards us;<br />and after this our exile,<br /> show unto us the blessed fruit of thy womb, Jesus.<br /><br />O clement,<br />O loving,<br />O sweet Virgin Mary.<br /><br />V. Pray for us, 0 holy Mother of God.<br />R. That we may be made worthy of the promises of Christ.<br />Amen.</span>';
        
				//mystery intermission markup
				spaces='<div class="mystery" style="font-family:arial,Verdana;font-weight:bold;font-size:26px; text-align:center;"><div style="font-size:14px; text-align:left;"><br />The<br />';
				var temp=  '<span style="font-size:12px; line-height:150%"><br /><br />';
				var temp2= 'Spiritual Fruit:<br />&#8226;&nbsp;'; var temp3='&nbsp;&#8226;</span></div>';
				this.Beads.SM=[
					['The Agony in the Garden',     spaces +'</div>AGONY<br />IN THE<br />GARDEN'    +temp +temp2 +'True Repentance'         +temp3],
					['The Scourging at the Pillar', spaces +'</div>SCOURGING<br />AT THE<br />PILLAR'+temp +temp2 +'Spirit of Mortification' +temp3],
					['The Crowning with Thorns',    spaces +'</div>CROWNING<br />WITH<br />THORNS'   +temp +temp2 +'True Repentance'         +temp3],
					['The Carrying of the Cross',   spaces +'</div>CARRYING<br />OF THE<br />CROSS'  +temp +temp2 +'Moral Courage'           +temp3],
					['The Crucifixion of Jesus',    spaces +'</div>CRUCIFIXION'                +temp +'<br /><br />' +temp2 + 'Final Perseverance' +temp3]];
				this.Beads.JM=[
					['The Annunciation of Our Lord ',     spaces +'</div><span style="font-size:21px;line-height:28px;">ANNUNCIATION<br />OF OUR<br />LORD</span>'+temp +temp2 +'True Repentance'         +temp3],
					['The Visitation ',                   spaces +'<br /></div>VISITATION'                  +temp +'<br /><br />' +temp2 +'Spirit of Mortification' +temp3],
					['The Nativity',                      spaces +'<br /></div>NATIVITY'                    +temp +'<br /><br />' +temp2 +'True Repentance'         +temp3],
					['The Presentation in the Temple',    spaces +'</div>CARRYING<br />OF THE<br />CROSS'   +temp +temp2 +'Moral Courage'           +temp3],
					['The Finding of Jesus in the Temple',spaces +'</div>FINDING<br />IN THE<br />TEMPLE'   +temp +temp2 +'Moral Courage'           +temp3]];		    
				this.Beads.GM=[
					['The Resurrection of our Lord',  spaces +'</div><span style="font-size:21px;line-height:28px;">RESURRECTION<br />OF OUR<br />LORD</span>'  +temp +temp2 +'Faith'         +temp3],
					['The Ascension into Heaven',     spaces +'</div>ASCENSION<br />INTO<br />HEAVEN'     +temp +temp2 +'Hope' +temp3],
					['The Descent of the Holy Spirit',spaces +'</div>DESCENT<br />OF THE<br />HOLY SPIRIT'+temp +temp2 +'Gifts of the Holy Spirit'         +temp3],
					['The Assumption of Mary',        spaces +'</div>ASSUMPTION<br />OF<br />MARY'        +temp +temp2 +'To Jesus through Mary'           +temp3],
					['The Coronation of Mary',        spaces +'</div>CORONATION<br />OF<br />MARY'        +temp +temp2 +'Final Perseverance'           +temp3]];				
				this.Beads.LM=[
					['The Baptism of Jesus',            spaces +'</div>BAPTISM<br />OF<br />JESUS'           +temp +temp2 +'Gratitude for the gift of Faith'         +temp3],
					['The Wedding Feast at Cana',       spaces +'</div>WEDDING<br />AT<br />CANA'            +temp +temp2 +'Fidelity' +temp3],
					['The Proclamation of the Kingdom', spaces +'</div><span style="font-size:21px;line-height:28px;">PROCLAMATION<br />OF THE<br />KINGDOM</span>'+temp +temp2 +'Desire for Holiness'         +temp3],
					['The Transfiguration',             spaces +'<br /></div><span style="font-size:21px;line-height:28px;">TRANSFIGURATION</span>'                +temp +'<br /><br />' +temp2 + 'Spiritual Courage' +temp3],
			/*		['The Institution of the Eucharist',spaces +'<br /></div><span style="font-size:21px;line-height:28px;">CRUCIFIXION</span>'                    +temp +'<br /><br />' +temp2 + 'Love of our Eucharistic Lord' +temp3]];	*/			
					['The Institution of the Eucharist',spaces +'</div>INSTITUTION<br />OF<br />the EUCHARIST' +temp +temp2 + 'Love of our Eucharistic Lord' +temp3]];				
this.Beads.LM.long='The Luminous Mysteries'; this.Beads.SM.long='The Sorrowful Mysteries';
				this.Beads.GM.long='The Glorious Mysteries'; this.Beads.JM.long='The Joyful Mysteries';
				//end mystery intermission markup
				
				this.Beads.allOff = function(){var i=60; while(i--){Beads[i].off();} }
				this.Beads.endRosary=function(){
					if (confirm('Did you pray the Rosary Beads?\nIncrease the Rosaries Prayed counter?')) {
              Beads.addOneRosary();
					}
					pio.Tableau.innerHTML=Beads.R5;
					Tempus.functus=function(){return};
					window.onbeforeunload='';
				}
				this.Beads.startRosary=function(){
					Beads.allOff(); 
					Beads[0].el.style.visibility='visible'; //show crucifix
					Beads[0].startPrayer();//use Beads[60].startPrayer(); for testing counter
					// future 
					pio.mysteryInfo.innerHTML=Beads[Beads.todaysMystery].long;
					pio.playBut.onclick=function(){Beads[Beads.currentBead].startPrayer();}	
					window.onbeforeunload=confirmExit;
				}
				this.Beads.addOneRosary=function(){
					this.done=0; 
					var s=document.createElement("script");
					s.src="http://www.basilica.org/rosary/cow/counterADD.php";
					s.type='text/javascript'; s.id='loadScript';
					document.body.appendChild(s);s=null;
					Beads.addOneRosary=function(){
							this.done++; //alert("this.done = " + this.done);
							if (this.done>15){return;} // number of setTimeout trys before forgetting it
							//try {document.getElementById('pioInfo').innerHTML=numOfRosaries();}
							//catch(er) {setTimeout('Beads.addOneRosary()',333);}
							if (numOfRosaries){ 
							   alert('Rosary Beads counter increased by one.\nThankyou.');
							   document.getElementById('pioInfo').innerHTML=numOfRosaries();}
							else {setTimeout('Beads.addOneRosary()',333);}
					}
					//alert('trying to increase');
					setTimeout('Beads.addOneRosary()',333);
				}
				this.Beads.getNumRosary=function(){//document.getElementById('pioInfo').innerHTML='bling';
					this.done=0; 
					var s=document.createElement("script");
					s.src="http://www.basilica.org/rosary/cow/counterGET.php";
					s.type='text/javascript'; s.id='loadScript';
					document.body.appendChild(s);s=null;
					Beads.getNumRosary=function(){
							this.done++; //alert("this.done = " + this.done);
							if (this.done>15){return;} // number of setTimeout trys before forgetting it
							try {document.getElementById('pioInfo').innerHTML=numOfRosaries();}
							catch(er) {setTimeout('Beads.getNumRosary()',333);}
					} 
					setTimeout('Beads.getNumRosary()',333);
				}
				this.Beads.getNumRosary();				
				this.Beads.currentBead=0;
				this.Beads.isAuto=true;
				
				var today=['GM','JM','SM','GM','LM','SM','JM',];
        this.Beads.todaysMystery=today[new Date().getDay()];
				pio[Beads.todaysMystery].style.color='#0d0';
			
				// info markup 
				spaces='<div class="Intro"><span class="center" style="background-color:#fff4f4">Instructions:<br /></span><br />';
				temp='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				this.Beads.R1= spaces+'<span class="center">Press Play > to Start</span><br />Choose Manual or Auto<br /> mode at any time.  Click Manual mode button to pause rosary. Mysteries are set by the date on your machine. &nbsp;&nbsp;&nbsp;&nbsp;<a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R2;">next&gt;&gt;</a></div>';
				this.Beads.R2= spaces+'At the end of the rosary<br /> a pop-up box will appear<br />asking if you have prayed<br />the rosary. Choose OK if you want to increase the<br />rosaries prayed counter.<br /><br /><a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R1;">&lt;&lt;prev</a>'+temp+'<a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R3;">next&gt;&gt;</a></div>';
				this.Beads.R3= spaces+'You can drag Rosary<br />Beads around the page<br />using the dragbar,<br />located in the upper<br />right corner.<br /><br /><br /><a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R2;">&lt;&lt;prev</a>'+temp+'<a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R4;">next&gt;&gt;</a></div>';
				this.Beads.R4= spaces+'Please be aware that if<br />you leave this web page,<br />it will reset your rosary.  To make a comment or suggestion visit the<br /><a href="http://rosary-beads.blogspot.com/" target="_blank">Rosary Beads Homepage</a>.<br /><br /><a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R3;">&lt;&lt;prev</a>'+temp+'<a href="#" onclick="this.parentNode.parentNode.innerHTML=Beads.R1;">next&gt;&gt;</a></div>';
				// end markup
				this.Beads.R5= '<div class="center" style="font-size:28px">Rosary finished.<br /><span style="font-size:22px"><br/>Press refresh to pray another.</span></div>';

				this.Beads.beadData=         [ 220,170,['AC'], 24,147,['OF'], 30,126,['HM'], 40,117,['HM'], 48,104,['HGO'],
					49,80,['OF'],  77,115,['HM'], 81,129,['HM'], 87,145,['HM'], 89,160,['HM'], 88,173,['HM'], 83,190,['HM'], 79,203,['HM'], 68,213,['HM'], 57,220,['HM'], 50,233,['HGO'],
				 51,257,['OF'],  68,276,['HM'], 82,281,['HM'], 99,279,['HM'],112,272,['HM'],124,268,['HM'],137,269,['HM'],151,272,['HM'],165,279,['HM'],181,278,['HM'],194,274,['HGO'],
				212,266,['OF'], 239,275,['HM'],253,281,['HM'],266,284,['HM'],282,284,['HM'],294,276,['HM'],302,265,['HM'],306,251,['HM'],305,238,['HM'],300,224,['HM'],291,212,['HGO'],
				286,187,['OF'], 288,164,['HM'],294,150,['HM'],301,139,['HM'],307,126,['HM'],310,110,['HM'],311, 96,['HM'], 305,83,['HM'],297, 71,['HM'], 285,64,['HM'], 271,63,['HGO'],
				 248,58,['OF'],  224,49,['HM'], 211,44,['HM'], 196,40,['HM'], 181,41,['HM'], 168,44,['HM'], 153,49,['HM'], 139,54,['HM'],124, 60,['HM'], 112,64,['HM'],  97,68,['HGO'],
					66,73,['HHQ']]; // ( beadData is x, y, prayer to be said on that bead )

				//make bead objects
				for(var i=0;i<numOfBeads;i++){this.Beads[i]=new bead('b'+i);} 
				
				Beads[0].el.innerHTML=''; // clear dot
				Beads[0].el=pio.crucifix; // assign our first bead dom to the crucifix
				
				
			// the beads properties and methods (Beads[n]=bead) 
			function bead(id) {
				this.index=Pio( exNihilo('span',{id:id, className:'beads',innerHTML:'&#8226;'}) );
				this.index=i;
				this.onHex ='#33ddff'; this.offHex='#070A09'; this.onHighHex ='#99f4ff';
				this.homeX=Beads.beadData[(i*3)];   //this.endPos=0;  
				this.homeY=Beads.beadData[(i*3+1)]-8;
				this.prayers=Beads.beadData[(i*3+2)]; 
				this.el=d.getElementById(id);
				this.css=this.el.style;
				this.css.left=this.homeX+'px';
				this.css.top= this.homeY+'px';
				this.css.color=this.offHex;
				this.position=0;
				
			} //methods
			bead.prototype.on       =function() {this.setColor(this.onHex);    return this;}
			bead.prototype.off      =function() {this.setColor(this.offHex);   return this;} 
			bead.prototype.onHigh   =function() {this.setColor(this.onHighHex);return this;} 
			bead.prototype.setColor =function(e){this.el.style.color=e;return this;}
			bead.prototype.nextBead =function() {return Beads[(this.index==Beads.length-1)? 0: this.index+1];}
			bead.prototype.prevBead =function() {return Beads[(this.index==0)? Beads.length-1: this.index-1];}
			bead.prototype.requietum=function() {this.onInter().prevBead().off()}
			bead.prototype.onInter  =function() {this.setColor('#9ab');return this;}
			bead.prototype.startPrayer=function() {	//alert("Beads.isAuto= "+Beads.isAuto);
			    var e=Pio.Tablet.Tableau;      
					if (this.prayers !== this.prevBead().prayers){e.innerHTML=Beads[this.prayers];}	// load this beads prayer into the tableau
					
					soundManager.play(this.prayers);
					
					Beads.currentBead=this.index;  
					Pio.Tablet.playBut.style.visibility='hidden';
					//this.endPos=e.scrollHeight-133
					e.scrollTop=this.position+=3;  this.onHigh();
					Tempus.functus=function(){Beads[Beads.currentBead].pray()};
			}
			bead.prototype.pray       =function() {
				  var e=Pio.Tablet.Tableau;
          if (this.position < e.scrollHeight-133) {
//window.document.f.info.value="Beads.currentBead= " +Beads.currentBead+ " position= " +this.position+ " e.scrollTop= " +e.scrollTop;
 							e.scrollTop = this.position+=2.5;
					}
					else {
							this.on(); e.scrollTop=0; this.position=0;
							if ((this.prayers=='HGO') && (this.index<55))  {          //mystery introductions
							    var mystNum=(this.index-4)/11;                        // find the current mystery 
									e.innerHTML=Beads[Beads.todaysMystery][mystNum][1];   // display mystery markup 
									Pio.Tablet.mysteryInfo.innerHTML=Beads[Beads.todaysMystery][mystNum][0];// display current mystery in top bar thingy
        					//alert(Beads.SM[(this.index-4)/11]); //this.endPrayer(); //Tempus.functus=function(){return};
							    Tempus.quiesco( 10, function(){Beads[Beads.currentBead].endPrayer();} )
							} 
							else {this.endPrayer();}
	        } 
			} 
			bead.prototype.endPrayer   =function() {
			    Beads.currentBead++;
					if (Beads.currentBead==61) {Beads.endRosary()}
			    else if (Beads.isAuto) { Tempus.functus=function(){Beads[Beads.currentBead].startPrayer()}; }
					else {Pio.Tablet.playBut.style.visibility='visible';Tempus.functus=function(){return}; }
			}
			// end beads properties and methods

			return [this.Beads,pio];
    }
//--------------------------------------------------------------------------------- 
    return {     Rose:Rose,              Tempus:Tempus,               about:about,  

      init : function() {
			
         var primordium = Rose();   Pio.Beads = primordium[0]; 	 Pio.Tablet= primordium[1]; 
         
				 Drag.init( Pio.Tablet, Pio.Tablet.DragBar);
				 /* At this point we have:  Pio.Tempus (the timer (setInterval) ) Pio.Preces (Prayer object) 
            Pio.Tablet (the GUI object)   Pio.Beads (array of bead objects)    Pio.about (alert about)  */
         Tempus.functus=function(){ //window.document.f.info.value="homeX= "+ (Tempus.counter++);
				     if (Tempus.counter>Beads.length-1) {Beads[Tempus.counter-1].off();Tempus.counter=6;};
						// Beads[parseInt(Math.random()*55+5)].requietum();
						 Beads[parseInt(Math.random()*55+5, 10)].requietum();
					 
						 //Beads[33].requietum();
						  }
					Pio.Tablet.Tableau.innerHTML=Pio.Beads.R1; //alert(window.Pio.Beads.SM1);
				 //Beads[0].startPrayer();
				 
				 soundManagerInit();
				 
			}                           
  };
}();
if (typeof window.onload == 'function') { 
  window.old=window.onload; window.onload=function(){old();Pio.init();}}
else {window.onload=Pio.init;}

/*--------------------------------------------------
  Drag for Pio
  --------------------------------------------------*/
var Drag = {
  obj : null, 
  init : function(panel,handle) {//window.document.f.info.value=Pio.Preces.HailMary.modus; 
    if(!window.zIndex) window.zIndex=3333; handle.root= Drag.obj= panel; 
    handle.style.cursor='move'; handle.onmousedown= Drag.start;
  }, 
  start : function(e) {
    var d=window.document; var panel= this.root; panel.style.zIndex= ++window.zIndex;
    if(!e){var e=window.event;}  if(e.pageX||e.pageY){var posx=e.pageX,posy=e.pageY;}
    else if (e.clientX||e.clientY){var posx=e.clientX+d.body.scrollLeft,posy=e.clientY+d.body.scrollTop;}// posx and posy contain the mouse position relative to the document//alert(posx+" "+posy);
    panel.oldX=posx; panel.oldY=posy;//here we have to give it style or no moving
    if (!panel.style.left) {panel.style.left='480px'; panel.style.top='160px';}
    d.onmousemove=Drag.drag; d.onmouseup=Drag.end; return false;
  }, 
   drag : function(e) {
    var panel=Drag.obj;
    if (!e) {var e=window.event;} if (e.pageX || e.pageY) {var posx=e.pageX, posy=e.pageY;}
    else if (e.clientX || e.clientY){var posx=e.clientX+document.body.scrollLeft,posy=e.clientY+document.body.scrollTop;}
    var nx=posx-panel.oldX,ny=posy-panel.oldY;panel.oldX=posx;panel.oldY=posy;
    panel.style.left=parseInt(panel.style.left, 10)+nx+"px";panel.style.top=parseInt(panel.style.top, 10)+ny+"px";
    return false;
  }, 
  end : function() { var d=window.document; d.onmousemove=null; d.onmouseup= null;}
}; //window.document.f.info.value=Drag.obj.id;
