//====================== variabels bepalen - max, min en gemiddelde (100%) tekstgrootte
var mingrootte = 1;
var midgrootte = 3;
var maxgrootte = 5;

 
//====================== zoeken binnen document naar tekstgrootte controls 
function writeTGControls(elementid) {
  var url = window.location.href.toLowerCase();
  var strTitle  = "";
  var larger   = "";
  var smaller = "";

  if (url.indexOf("/english/") >= 0) {
	  var strTitle  = "Text size";
	  var larger   = "larger";
	  var smaller = "smaller";
  }
  else  {
	  var strTitle  = "Tekstgrootte";
	  var larger   = "groter";
	  var smaller = "kleiner";
  }
  var el = document.getElementById(elementid);
  if(el) {
	var theHTML = "<h3>" + strTitle + "</h3>";
	theHTML += "<ul>"
	theHTML += "<li><a id=\"tekstmin\" href=\"#kleiner\" title=\"" + smaller + "\">-</a></li>";
	theHTML += "<li><a id=\"tekstplu\" href=\"#groter\" title=\""+ larger + "\">+</a></li>";
	theHTML += "</ul>";
	el.innerHTML = theHTML;
  }
}

function tekstGrootte()	{



	this.tekstControls = new Array();
	// bestaat tekstgrootte op deze pagina?
	var tc = document.getElementById('tekstgrootte');

	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('VWSFontSize') == '')){
			fontWissel(getCookieVal('VWSFontSize'));
			var maat = getCookieVal('VWSFontSize');
			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 = 'inactief';
	}
	else if (this.grootte == maxgrootte) {
		this.plus.className = 'inactief';
	}
	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("VWSFontSize", titel);
	if(document.getElementById('t1')){ adjustFontImages(titel) };
}



// -- COOKIE FUNCTIONS:

function setCookie(name, value, expires, path, domain, secure) {

	a = document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		"; 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 (getCookieVal("VWSFontSize")) {
		a = document.cookie = name + "= empty" +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT" +
			((path) ? "; path=" + path : "/") +
			((domain) ? "; domain=" + domain : "");;
	}
}

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


if(!(getCookieVal("VWSFontSize") == '')){
	fontWissel(getCookieVal('VWSFontSize'));
}