var varHighContrast = false;
attachEventListener(window,'load',setFrames,false);

// Toggle high contrast
function toggleHighContrast(){
	varHighContrast = !varHighContrast;
	setFrames();
}

// Set the contrast of all frames
function setFrames(){
	// Link
	var topFrame = this.frames['topFrame'];
	if (topFrame) {
		var imgHighContrast = topFrame.document.getElementById('imgHighContrast');
		if (imgHighContrast) {
			imgHighContrast.style.display = 'block';
			imgHighContrast.src = varHighContrast ? 'styles/graphics/contrast_normal.gif' : 'styles/graphics/contrast_high.gif';
			imgHighContrast.alt = varHighContrast ? 'Switch to normal contrast' : 'Switch to high contrast';
		}
	}
	// Frames
	for (var i=0; i<this.frames.length; ++i) {
		setHighContrast(this.frames[i].document);
	}
}

// Set high contrast of a document
function setHighContrast(doc) {
	var cssHighContrast = doc.getElementById('cssHighContrast');
	if (cssHighContrast) {
		cssHighContrast.disabled = !varHighContrast;
	}
}

//cross browser way of attaching event listeners
function attachEventListener(target, eventType, functionRef, capture){
	if (typeof(functionRef)== 'string') {
		functionRef=eval(functionRef);
	}
	if (typeof target.addEventListener != "undefined") {
		target.addEventListener(eventType, functionRef, capture);
	} else if (typeof target.attachEvent != "undefined"){
		target.attachEvent("on" + eventType, functionRef);
	} else {
		eventType = "on" + eventType;
		if(typeof target[eventType] == "function") {
			var oldListener = target[eventType];
			target[eventType] = function() {
				oldListener();
				return functionRef();
			};
		}else{
			target[eventType] = functionRef;
		}
	}
}
