//====================== variabels bepalen - max, min en gemiddelde (100%) tekstgrootte
var mingrootte = 1;
var midgrootte = 3;
var maxgrootte = 5;
 
//====================== zoeken binnen document naar tekstgrootte controls 
function tekstGrootte()	{

	if (!document.createElement) {
		return false;
	}

	// toevoegen aan DOM
	var tg = document.createElement('ul');
	tg.id = 'tekstgr';

	var li1 = document.createElement('li');
	var label = document.createElement('label');
	if (document.body.className.indexOf('engels')>-1)
		var lbl = 'Enlarge text';
	else
		var lbl = 'Tekstgrootte';
	label.appendChild(document.createTextNode(lbl));
	li1.appendChild(label);

	var li2 = document.createElement('li');
	var a2 = document.createElement('a');
	a2.id = 'tekstmin';
	a2.setAttribute('href','#');
	a2.setAttribute('title','kleinere');
	a2.appendChild(document.createTextNode('-'));
	li2.appendChild(a2);

	var li3 = document.createElement('li');
	var a3 = document.createElement('a');
	a3.id = 'tekstplu';
	a3.setAttribute('href','#');
	a3.setAttribute('title','grotere');
	a3.appendChild(document.createTextNode('+'));
	li3.appendChild(a3);

	tg.appendChild(li1);
	tg.appendChild(li2);
	tg.appendChild(li3);

	var tm = document.getElementById('voet-zone').getElementsByTagName('ul')[0];
	if (!tm) {
		return false;
	}
	else {
		tm.appendChild(li1);
		tm.appendChild(li2);
		tm.appendChild(li3);
	}
	// ===


	this.tekstControls = new Array();
	// bestaat tekstgrootte op deze pagina?
	var tc = document.getElementById('tekstmin');
	if (!tc) {
		return false;
	}
	else {
		this.plus = document.getElementById('tekstplu');
		this.tekstControls[this.tekstControls.length] = new controlObjs(this,plus);
		this.minus = document.getElementById('tekstmin');
		this.tekstControls[this.tekstControls.length] = new controlObjs(this,minus);
		// lees cookie en set tekstgrootte
		if(!(getCookieVal('OCWFontSize') == '') && getCookieVal('OCWFontSize') != null){
			fontWissel(getCookieVal('OCWFontSize'));
			var maat = getCookieVal('OCWFontSize');
			var huidigeGrootte = maat.charAt(4);
			if (huidigeGrootte > 0 && huidigeGrootte < 6) {
				this.grootte = huidigeGrootte;
			} else {
				this.grootte = midgrootte;
			}
			//check voor max of min tekstgrootte
			checkOnactief(this.plus,this.minus,this.grootte);
		}
		// als er geen cookie is, set tekstgrootte naar gemiddeld (3)
		else {
			this.grootte = midgrootte;
		}
		this.ss = 'maat' + this.grootte;
	}
}

//====================== object collectie en klik-functie
var controlObjs = function(tekstGrootte,control) {
	this.tekstGrootte = tekstGrootte;
	this.control = control;
	this.richting = this.control.id;
	this.richting.controlObjs = this;
	this.control.controlObjs = this;
	this.control.onclick = function () {
		this.controlObjs.tekstControl();
        return false;
    }
}

//====================== deze functie checkt dat de tekstgrootte is niet minder dan 1 en niet groter dan 5
controlObjs.prototype.checkControl = function () {
	//alert(this.tekstGrootte.grootte);
	if ((this.control.id == 'tekstmin') && (this.tekstGrootte.grootte < mingrootte)) {
		this.tekstGrootte.grootte ++;
		return false;
	}
	else if ((this.control.id == 'tekstplu') &&(this.tekstGrootte.grootte > maxgrootte)) {
		this.tekstGrootte.grootte --;
		return false;
	}
	else {
		return true;
	}
}

//====================== links wordt onactief als de grootste of de kleinste tekstgrootte is al in gebruik
var checkOnactief = function (plus,minus,grootte) {
	this.plus = plus;
	this.minus = minus;
	this.grootte = grootte;
	// reset styles
	this.plus.className = '';
	this.minus.className = '';
	if (this.grootte == mingrootte) {
		this.minus.className = 'onactief';
	}
	else if (this.grootte == maxgrootte) {
		this.plus.className = 'onactief';
	}
	return false;
}

//====================== fontWissel roepen als de font niet al te groot of te klein is
controlObjs.prototype.tekstControl = function () {
	if (this.richting == 'tekstplu') {
		this.tekstGrootte.grootte ++;
	}
	else {
		this.tekstGrootte.grootte --;
	}
	if (this.checkControl()) {
		checkOnactief(this.tekstGrootte.plus,this.tekstGrootte.minus,this.tekstGrootte.grootte);
		this.tekstGrootte.ss = 'maat' + this.tekstGrootte.grootte;
		fontWissel(this.tekstGrootte.ss);		
	}
}

//====================== zoeken naar stylesheet link elementen met een 'title' attribute 
//====================== wissel van stylesheet 
function fontWissel(titel) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == titel) a.disabled = false;
		}
	}
	setCookie("OCWFontSize", titel);
	if(document.getElementById('t1')){ adjustFontImages(titel) };
}



// -- COOKIE FUNCTIONS:

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path)    ? "; path=" + path : "") +
		((domain)  ? "; domain=" + domain : "") +
		((secure)  ? "; secure" : "");
	return true;
}

function getCookieVal(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function getExpireDate(){
	var expires = new Date();
	expires.setTime((new Date().getTime()) + 60*60);
	return expires;
}


if(!(getCookieVal('OCWFontSize') == '')){
	fontWissel(getCookieVal('OCWFontSize'));
}

