if(!Array.prototype.indexOf){
    Array.prototype.indexOf=function(obj,start){
        for(var i=(start||0),j=this.length;i<j;i++){
            if(this[i]==obj){return i;}
        }
        return -1;
    }
}

hg.graphicsDir = 'highslide/graphics/';
hg.outlineType = 'rounded-white';
hg.wrapperClassName = 'draggable-header';


function popitup(url) {
	newwindow=window.open(url,'name','height=200,width=800,scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}

var galleryNumber = 10;
var d=new Date();
var urlEnd = d.getTime();
var todaysDate;
var indexNo = 0; //resets the array index back to zero
var currentTime = new Date(); //gets the current date in full detail
var month = currentTime.getMonth() + 1; //gets the month value and corrects for real time.
if (month < 10){
month = "0" + month;
}
var day = currentTime.getDate(); //gets the day value
if (day < 10){
day = "0" + day;
}
var year = currentTime.getFullYear(); //gets the four digit year value
//var todaysDate = day + "/" + month + "/" + year; //combines all values into dd/mm/yyyy format, same as arrays containing dates.
var todaysDateString = year + "" + month + "" + day;
var numberEntriesDisplayed = 5; //Set this to the number of upcoming events you wish to display in the list.
//No need to touch anything below, all automated using variables above
todaysDate = eval(todaysDateString);

if (!Array.prototype.filter)
{
  Array.prototype.filter = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var res = new Array();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
      {
        var val = this[i]; // in case fun mutates this
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }

    return res;
  };
}

function todayOrGreater(element, index, array) {
return (element >= todaysDate)
}
var newDateArray = date.filter(todayOrGreater);
var dateToUse = newDateArray[0];
function findIndex () {
indexNo = date.indexOf(dateToUse);
testIndex();
}

function findNewIndex(newIndex)
{
indexNo = newIndex;
testIndex();
}

function findRemainingIndex() {
var entryCount = 1;
	for (var i=(indexNo+1); i<date.length; i++) {
		indexNo = indexNo + 1;
		if(entryCount < numberEntriesDisplayed) {
			if (events[indexNo] == "")
				{
				}
			else
				{
				dateindexNo = date[indexNo] + "/";
				dateyear = dateindexNo.substring(0,4);
				datemonth = dateindexNo.substring(4,6);
				dateday = dateindexNo.substring(6,8);
				eventList += dateday + "/" + datemonth + "/" + dateyear + "<br><a onclick=\"return hg.htmlExpand(this, { objectType: 'iframe' } )\" href=\"events/" + link[indexNo] + ".html?date="+ urlEnd +"\">" + events[indexNo] + "</a><br><br>";
				entryCount = entryCount + 1;
				}
		}
	}

}
findIndex();
var dateindexNo = date[indexNo] + "/";
var dateyear = dateindexNo.substring(0,4);
var datemonth = dateindexNo.substring(4,6);
var dateday = dateindexNo.substring(6,8);
var eventList;
if(indexNo != -1){
eventList = dateday + "/" + datemonth + "/" + dateyear + "<br><a onclick=\"return hg.htmlExpand(this, { objectType: 'iframe' } )\" href=\"events/" + link[indexNo] + ".html?date="+ urlEnd +"\">" + events[indexNo] + "</a><br><br>";
findRemainingIndex();
}
function testIndex()
{
if (indexNo == -1)
{
eventList = "There are currently no future events scheduled at this time.<br><br>";
}
}
document.writeln(eventList);
