// Programme.js
// Scripts for highlighting programme events using CSS styles
// Steve Wilbur August 2004
// Updated 17/9/04 to work with NN6 and IE6
// NB. The page's local stylesheet must be the second in the document and the first few rules
// must be: .exhibition, .digital, .weekly and .away in that order.

function setRuleProperty(sheetNo, ruleNo, propertyName, value) {
	// only works for background colour on IE6!!!
	if (document.styleSheets[1].cssRules) 
		document.styleSheets[sheetNo].cssRules[ruleNo].style.setProperty(propertyName, value, "");	//NN6
	else
		document.styleSheets[sheetNo].rules[ruleNo].style.backgroundColor= value;  //IE6
}

function showExh(){
	hideDig();
	hideWeek();
	hideAway();
	//alert(document.styleSheets[1].cssRules[0].style.backgroundColor);
	//alert(document.styleSheets[1].cssRules[0].selectorText);
	setRuleProperty(1, 0, "background-color", "#BBBBFF");
}

function hideExh(){
	setRuleProperty(1, 0, "background-color", "#FFFFFF");
}

function showDig(){
	hideExh();
	hideWeek();
	hideAway();
	setRuleProperty(1, 1, "background-color", "#99CCFF");
}

function hideDig(){
	setRuleProperty(1, 1, "background-color", "#FFFFFF");
}

function showWeek(){
	hideDig();
	hideExh();
	hideAway();
	setRuleProperty(1, 2, "background-color", "#FFBBBB");
}

function hideWeek(){
	setRuleProperty(1, 2, "background-color", "#FFFFFF");
}

function showAway(){
	hideDig();
	hideWeek();
	hideExh();
	setRuleProperty(1, 3, "background-color", "#BBFFBB");
}

function hideAway(){
	setRuleProperty(1, 3, "background-color", "#FFFFFF");
}

function hideAll(){
	hideDig();
	hideAway();
	hideWeek();
	hideExh();
}

function findScrollLeft() { 
	if (window.pageXOffset != null) {
		return window.pageXOffset;
	}
	if (document.body.scrollWidth != null) {
		if (document.documentElement.scrollLeft) {  //may be 0 because that is result or because not impl'd
			return document.documentElement.scrollLeft;
		} else {
			return document.body.scrollLeft;
		}
	}
	return null;
}

function popup(evt, object){
// SRW 20/8/2004
	DOMStyle = findDOM(object, 1);
	if (DOMStyle.visibility == "visible") {	
		DOMStyle.visibility = "hidden";
	}
	else {	
		evt = (window.event)? window.event: evt;
		if (evt) {
			DOMStyle.top = (getMouseY(evt)+20) + 'px';
			DOMStyle.left = (getMouseX(evt)-20) + 'px';
		}
		DOMStyle.visibility="visible";
	}
}
/*
		Extracted from: dw_util.js
		version date: August 2002
		
		functions for getting window dimensions and scroll amount
		from http://13thparallel.com/?issue=2002.06&title=viewport
				
		This code is from Dynamic Web Coding 
    www.dyn-web.com 
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code 
    as long as this entire notice is included.		
*/

// returns amount of vertical scroll
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}

// returns amount of horizontal scroll
function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}

// functions to get page coordinates of mouse event
function getMouseX(evt) {
	return (evt.pageX)? evt.pageX: evt.clientX + getScrollX();
}

function getMouseY(evt) {
	return (evt.pageY)? evt.pageY: evt.clientY + getScrollY();
}