var alertString = "";

function getWeekNr() {
  /*
  This function originally from http://www.quirksmode.org/js/week.html has
  been adapted to calculate the next sunday at 6pm instead of the current iso 
  standard week number. Changes are commented. Feel free to borrow this script if
  it suits your requirements.
  
  Aaron Rowe
  */
  
  
  var THIS_YEAR = 2010;
  //this is used to alert the user if the data is not for the current year as set by their pc.
  var today = new Date();
  
  Year = takeYear(today);
	if (Year != THIS_YEAR) {alertString = "<b>This Notice is for events in "+THIS_YEAR+", however, your clock says that it is "+Year+"</b><br />";}
	
  Month = today.getMonth();
  Day = today.getDate();
  
  //AR: In order to set the threshold time to 18:00 on Sunday
  //    Hours is now used in calculations
  Hours = today.getHours();
  now = Date.UTC(Year,Month,Day,Hours,0,0);
  
  var Firstday = new Date();
  Firstday.setYear(Year);
  Firstday.setMonth(0);
  Firstday.setDate(1);
  var dow = Firstday.getDay();
  //skipdays is used as an offset to find the date of the first sunday in the year
  var skipdays = 1;
  if (dow !=0) {
    //if Jan 1st is not a Sunday, dow = (1-6 is mon-sat resp.)
    skipdays = 8 - dow;
  }
  then = Date.UTC(Year,0,skipdays,18,0,0);
  NumberOfWeek =  Math.floor((now-then)/604800000); //604800000 = number of ms in 1 week
  NumberOfWeek+=1; // +1 because days before the first sunday are negative.
  return NumberOfWeek;
}


function takeYear(theDate){
  //creates 4 digit year because older browsers do not support getFullYear()
  x = theDate.getYear();
  var y = x % 100;
  y += (y < 38) ? 2000 : 1900;
  return y;
}


function Lecture(dateString,mainSubject,sub1,sub2) {
  //object definition for Lecture
  this.dateString = dateString;
  this.mainSubject = mainSubject;
  this.sub1 = sub1;
  this.sub2 = sub2;
  this.getDateString = function() {return this.dateString;}
  this.getMainSubject = function() {return this.mainSubject; }
  this.getSub1 = function() {return this.sub1;}
  this.getSub2 = function() {return this.sub2; }
   
}


var weeks = new Array(
new Lecture( "3 Jan 2010","The Return of Jesus Christ","It will happen","Are you ready?" ),
new Lecture( "10 Jan 2010","Is Christianity relevant?","","" ),
new Lecture( "17 Jan 2010","Bible teachings - Baptism","What must we do to be saved?","A new life" ),
new Lecture( "24 Jan 2010","The many rewards of being a Christian","Today","In the future" ),
new Lecture( "31 Jan 2010","Does it matter what we believe?","","" ),
new Lecture( "7 Feb 2010","The miracle of the Bible","Origin","Meaning" ),
new Lecture( "14 Feb 2010","There is a greater love","For the world","For you" ),
new Lecture( "21 Feb 2010","Bible teachings","Hell","Heaven" ),
new Lecture( "28 Feb 2010","A law ahead of its time","","" ),
new Lecture( "7 Mar 2010","Jerusalem - whose capital?","","" ),
new Lecture( "14 Mar 2010","Teachings of Jesus","","" ),
new Lecture( "21 Mar 2010","Integrity in a cynical world","","" ),
new Lecture( "28 Mar 2010","Continuation of youth weekend","","" ),
new Lecture( "4 Apr 2010","The resurrection. A fact","","" ),
new Lecture( "11 Apr 2010","World government coming - without our vote!","","" ),
new Lecture( "18 Apr 2010","The Gospel and loneliness","","" ),
new Lecture( "25 Apr 2010","What happens when we die?","","" ),
new Lecture( "2 May 2010","The government of God","Now","Future" ),
new Lecture( "9 May 2010","When Jesus comes back to the earth","","" ),
new Lecture( "16 May 2010","Bible teachings","Death","Immortality" ),
new Lecture( "23 May 2010","What's so special about the Bible?","","" ),
new Lecture( "30 May 2010","God's people - Israel","History","Future" ),
new Lecture( "6 Jun 2010","Can we be good without God","Being good","Being Godly" ),
new Lecture( "13 Jun 2010","The controversies with Jesus","","" ),
new Lecture( "20 Jun 2010","Bible teachings","The good","The bad" ),
new Lecture( "27 Jun 2010","Bible misunderstandings","","" ),
new Lecture( "4 Jul 2010","Baptism: Questions and Answers","","" ),
new Lecture( "11 Jul 2010","Evidence that God exists","","" ),
new Lecture( "18 Jul 2010","The Holy Spirit - the power of God","","" ),
new Lecture( "25 Jul 2010","What Jesus said about love","Love your neighbour","Love God" ),
new Lecture( "1 Aug 2010","What Jesus said about the Kingdom of God","When?","Where?" ),
new Lecture( "8 Aug 2010","The Bible in recent news","","" ),
new Lecture( "15 Aug 2010","Why it matters what you believe","About God","About Christ" ),
new Lecture( "22 Aug 2010","Bible teachings - Prophecy","Recently fulfilled","Near future" ),
new Lecture( "29 Aug 2010","Does God hear prayer?","","" ),
new Lecture( "5 Sep 2010","Mankind's problems, God's answers","","" ),
new Lecture( "12 Sep 2010","God's DNA","","" ),
new Lecture( "19 Sep 2010","About the Christadelphians","","" ),
new Lecture( "26 Sep 2010","Jesus - The Son of God","","" ),
new Lecture( "3 Oct 2010","We ignore God's prophets at our peril","","" ),
new Lecture( "10 Oct 2010","The problem of suffering","","" ),
new Lecture( "17 Oct 2010","In the beginning... order or chaos?","","" ),
new Lecture( "24 Oct 2010","Why do men fight wars?","","" ),
new Lecture( "31 Oct 2010","What is treasure in heaven ?","","" ),
new Lecture( "7 Nov 2010","Jesus, Son of God not God the Son","Man's creed","God's truth" ),
new Lecture( "14 Nov 2010","The greatest sacrifice of all","Why Christ died","Why Christ rose" ),
new Lecture( "21 Nov 2010","The devil in the mirror","","" ),
new Lecture( "28 Nov 2010","Bible teachings - grace","","" ),
new Lecture( "5 Dec 2010","Jesus and the old testament","","" ),
new Lecture( "12 Dec 2010","Finding peace in a stressful world","","" ),
new Lecture( "19 Dec 2010","Family Carol Service","","" ),
new Lecture( "26 Dec 2010","No lecture","","" ));

   
  
   // if week 53 exists it will cause an error if not stored here.
function writeLecture() { 
    var weekNr = getWeekNr();
    var dateString = weeks[weekNr].getDateString();
    var mainSubject = weeks[weekNr].getMainSubject();
    var sub1 = weeks[weekNr].getSub1();
    var sub2 = weeks[weekNr].getSub2();
    document.write("<p>"+alertString+"<span class=\"lecure_title\">"+mainSubject+"</span>");
    document.write("<br />");
    if (sub1 != "") {
	    document.write("<span class=\"lecture_subtitle\">"+sub1+"</span>");
	    if (sub2 != "") {
	        document.write("<br />");
            document.write("<span class=\"lecture_subtitle\">"+sub2+"</span>");
        }
        document.write("<br />");
    }
    document.write("</p>Sunday ",dateString, " at 6:00 pm");
}