// #### populate the next steam/diesel day text & image ####

//the next day text
obj['nsd_txt'] = document.getElementById('nsd_txt');
if (obj['nsd_txt'] && txt['nsd']){
	obj['nsd_txt'].childNodes[0].nodeValue = txt['nsd'];
}
//the timetable flag
obj['nsd_img'] = document.getElementById('nsd_img');
if (obj['nsd_img'] && img['nsd']){
	obj['nsd_img'].src = img['nsd'];
	//obj['nsd_img'].src = '/img/ttb.gif';
	obj['nsd_img'].style.height = '35px';
	obj['nsd_img'].style.width = '49px';
}

// #### the left hand menu functionality ####
obj['lhm'] = new Array;
obj['lhm']['a'] = new Array;
obj['lhm']['div'] = new Array;
for (e in navigate){
	obj['lhm']['a'][e] = document.getElementById('lhm_a_' + e);
	if (navigate[e]['parent'] && !obj['lhm']['div'][navigate[e]['parent']]){
		obj['lhm']['div'][navigate[e]['parent']] = document.getElementById('lhm_div_' + navigate[e]['parent']);
	}
}

function lhm_mouseover(page_tid){
	//set the window status to the page title
	window.status = 'Avon Valley Railway: ' + navigate[page_tid]['title'];
	//set className & hidden divs stuff only for level 1 menu items
	if (navigate[page_tid]['level'] < 2){
		//set the menu item className
		for (e in navigate){
			if (obj['lhm']['a'][e]){
				var under_over = (page_tid == e)?'_over':'_under';
				obj['lhm']['a'][e].className = 'navbar_left_' + navigate[e]['level'] + under_over;
			}
		}
		//make associated div visible
		lhm_hide_all_divs();
		clearTimeout(val['lhr_timeout']);
		if (obj['lhm']['div'][page_tid]){
			obj['lhm']['div'][page_tid].style.visibility = 'visible';
			val['lhr_timeout'] = setTimeout('lhm_hide_all_divs()',5000);
		}
	}
}

function lhm_mouseout(page_tid){
	//return the window status to the generic text
	window.status = val['window_status'];
	//set the menu item className
	for (e in navigate){
		if (obj['lhm']['a'][e]){
			obj['lhm']['a'][e].className = 'navbar_left_' + navigate[e]['level'];
		}
	}
}

function lhm_hide_all_divs(){
	//hide each div that is defined
	for (e in obj['lhm']['div']){
		if (obj['lhm']['div'][e]){
			obj['lhm']['div'][e].style.visibility = 'hidden';
		}
	}
}

// #### the right hand mini-calendar functionality ####

obj['cal'] = new Array;
obj['cal']['left'] = document.getElementById('cal_l');
obj['cal']['center'] = document.getElementById('cal_c');
obj['cal']['right'] = document.getElementById('cal_r');
obj['cal']['td'] = new Array;
for (var td = 1;td <= 42;td++){
	obj['cal']['td']['td_' + td] = document.getElementById('cal_td_' + td);
}
obj['cal_dom'] = new Date(today.getFullYear(),today.getMonth(),1);

onload:cal_set_month_days();
function cal_set_month_days(){
	//set calendar month & year
	obj['cal']['center'].childNodes[0].nodeValue = mmtxts[obj['cal_dom'].getMonth()+1].substr(0,3);
	obj['cal']['center'].childNodes[2].nodeValue = obj['cal_dom'].getFullYear();
	//populate the calendar day td's with the days under the correct day of week
	var st_m = obj['cal_dom'].getMonth();
	var st_y = obj['cal_dom'].getFullYear();
	for (var td = 1;td <= 42;td++){
		obj['cal']['td']['td_' + td].childNodes[0].nodeValue = '';
		if (td > obj['cal_dom'].getDay() && st_m == obj['cal_dom'].getMonth()){
			obj['cal']['td']['td_' + td].childNodes[0].nodeValue = obj['cal_dom'].getDate();
			obj['cal']['td']['td_' + td].className = 'cal_notexist';
			cal_highlight_sched(obj['cal_dom'],td);
			obj['cal_dom'].setDate(obj['cal_dom'].getDate() + 1);
		}else{
			obj['cal']['td']['td_' + td].className = 'cal_notexist';
		}
	}
	//make bottom row of calendar cells 0px if they are empty
	if (obj['cal']['td']['td_36'].childNodes[0].nodeValue == ''){
		for (var btd = 36;btd <= 42;btd++){
			obj['cal']['td']['td_' + btd].style.height='0px';
		}
	}
	obj['cal_dom'] = new Date(st_y,st_m,1);
}

//set classes for days that have trains running
function cal_highlight_sched(date,td){
	//get string that represents the date
	var m = date.getMonth() + 1;
	var d = date.getDate();
	if (m < 10) m = String('0') + String(m);
	if (d < 10) d = String('0') + String(d);
	var yyyymmdd = date.getFullYear() + '-' + String(m) + '-' + String(d);
	//if sched array has an entry for the date string then set the class of td to cal_ + sched value
	if (sched[yyyymmdd]){
		obj['cal']['td']['td_' + td].className = 'cal_' + sched[yyyymmdd];
	}
}

//change the mini-calendar month being displayed
function cal_ch_mm(ch){
	if (ch > 0){
		obj['cal_dom'].setMonth(obj['cal_dom'].getMonth() + 1);
	}else{
		obj['cal_dom'].setMonth(obj['cal_dom'].getMonth()  - 1);
	}
	cal_set_month_days();
}
