window.onload = loadData;

var thisCalendar=0;
var thisEvent=0;
var calendarList=null;
var timerID = null;
var eventTimer=null;
var reflectWindow = null;

function loadData() {
	loadCalendar(calendarNew);
	loadEvents();
	choosePic();
}

function loadCalendar(thisList) {
	calendarList=thisList;
	clearTimeout(timerID);
	thisCalendar= -1;
	
	rotateCalendar();
}

function pauseCalendar() {
	clearInterval(timerID);
}

function pauseEvents() {
	clearInterval(eventTimer);
}

function rotateCalendar() {
	thisCalendar++;
	if(thisCalendar==calendarNew.length) {
		thisCalendar = 0;
	}
	document.getElementById("calendar").innerHTML=calendarNew[thisCalendar];

	timerID=setTimeout("rotateCalendar()", 8*1000);
}

function nextCalendar() {
	if(calendarList==null){
		loadCalendar(calendarNew);
	}
	else {
	thisCalendar++;
	if(thisCalendar==calendarNew.length) {
		thisCalendar = 0;
	}
	document.getElementById("calendar").innerHTML=calendarNew[thisCalendar];
	clearTimeout(timerID);
	timerID=setTimeout("rotateCalendar()", 8*1000);
	}
}

function prevCalendar() {
	if(calendarList==null){
		loadCalendar(calendarNew);
	}
	else {
	thisCalendar--;
	if(thisCalendar<0) {
		thisCalendar = calendarNew.length-1;
	}
	document.getElementById("calendar").innerHTML=calendarNew[thisCalendar];
	clearTimeout(timerID);
	timerID=setTimeout("rotateCalendar()", 8*1000);
	}
}

function loadEvents() {
	clearTimeout(eventTimer);
	thisEvent= -1;
	
	rotateEvent();
}

function rotateEvent() {
	thisEvent++;
	if(thisEvent==specialEvents.length) {
		thisEvent = 0;
	}
	document.getElementById("events").innerHTML=specialEvents[thisEvent];

	eventTimer=setTimeout("rotateEvent()", 7*1000);
}

function nextEvent() {
	thisEvent++;
	if(thisEvent==specialEvents.length) {
		thisEvent = 0;
	}
	document.getElementById("events").innerHTML=specialEvents[thisEvent];
	clearTimeout(eventTimer);
	eventTimer=setTimeout("rotateEvent()", 7*1000);
}

function prevEvent() {
	thisEvent--;
	if(thisEvent<0) {
		thisEvent = specialEvents.length-1;
	}
	document.getElementById("events").innerHTML=specialEvents[thisEvent];
	clearTimeout(eventTimer);
	eventTimer=setTimeout("rotateEvent()", 7*1000);
}

function closeWin(thisWindow){
	if (thisWindow!= null){
		if(!thisWindow.closed)
			thisWindow.close();
	}
}

function openReflections(url, width, height){
	closeWin(reflectWindow);

	var settings="";
	settings="toolbar=yes,location=yes,directories=yes,"+
	"status=no,menubar=yes,scrollbars=yes,"+
	"resizable=yes,left=50,top=100,width="+width+",height="+height;
	
	reflectWindow=window.open(url, 'reflectWin', settings);
	reflectWindow.focus();
}



