/* variabels bepalen - max, min en gemiddelde (100%) textsize */
var minsize = 1;
var midsize = 3;
var maxsize = 5;

/* zoeken binnen document naar textsize controls */ 
function textSize()	{
  
	this.textControls = new Array();
	// bestaat textsize op deze pagina?
	var tc = document.getElementById('resize_plus');
	if (!tc) {
		return false;
	}
	else {
		this.plus = document.getElementById('resize_plus');
		this.textControls[this.textControls.length] = new controlObjs(this,plus);
		this.minus = document.getElementById('resize_minus');
		this.textControls[this.textControls.length] = new controlObjs(this,minus);
		// lees cookie en set textsize
		if(!(getCookieVal('MinBuzaFontSize') == '')){
			//fontWissel(getCookieVal('MinBuzaFontSize'));
			sizeFont = getCookieVal('MinBuzaFontSize');
			this.size = sizeFont.charAt(4);
			//check voor max of min textsize
			checkOnactief(this.plus,this.minus,this.size);
		}
		// als er geen cookie is, set textsize naar gemiddeld (3)
		else {
			this.size = midsize;
		}
		this.ss = 'size' + this.size;
		fontWissel(this.ss);	
	}
}

//====================== object collectie en klik-functie
controlObjs = function(textSize,control) {
	this.textSize = textSize;
	this.control = control;
	this.richting = this.control.id;
	this.richting.controlObjs = this;
	this.control.controlObjs = this;
	this.control.onclick = function () {
		this.controlObjs.textControl();
        return false;
    }
}

/* links wordt inactive als de grootste of de kleinste textsize is al in gebruik */
checkOnactief = function (plus,minus,size) {
	this.plus = plus;
	this.minus = minus;
	this.size = size;
	// reset styles
	this.plus.className = '';
	this.minus.className = '';
	if (this.size == minsize) {
		this.minus.className = 'inactive';
	}
	else if (this.size == maxsize) {
		this.plus.className = 'inactive';
	}
	return false;
}

//====================== deze functie checkt dat de textsize is niet minder dan 1 en niet groter dan 5
controlObjs.prototype.checkControl = function () {
	if ((this.control.id == 'resize_minus') && (this.textSize.size < minsize)) {
		this.textSize.size ++;
		return false;
	}
	else if ((this.control.id == 'resize_plus') &&(this.textSize.size > maxsize)) {
		this.textSize.size --;
		return false;
	}
	else {
		return true;
	}
}

/* fontWissel roepen als de font niet al te groot of te klein is */
controlObjs.prototype.textControl = function () {
	if (this.richting == 'resize_plus') {
		this.textSize.size ++;		
	}
	else {
		this.textSize.size --;
	}
	if (this.checkControl()) {
		checkOnactief(this.textSize.plus,this.textSize.minus,this.textSize.size);
		this.textSize.ss = 'size' + this.textSize.size;
		fontWissel(this.textSize.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("MinBuzaFontSize", titel);
	if(document.getElementById('t1')){ adjustFontImages(titel) };
}

// -- COOKIE FUNCTIONS:

function getCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) 
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function setCookie (name, value) {  
	var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	
	//var path = (argc > 3) ? argv[3] : null;
	var path = (argc > 3) ? argv[3] : document.location.pathname;
	
	//var domain = (argc > 4) ? argv[4] : null;  
	var domain = (argc > 4) ? argv[4] : document.domain; 

	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {

	var endstr = document.cookie.indexOf("MinBuzaFontSize=size");
	//alert("document.cookie---> "+document.cookie);
	if (endstr == -1){
	  return unescape("");
	}
	else{
	  return unescape("size"+document.cookie.substring(endstr+20, endstr+21));
	}
	/*
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset.length+1, endstr));
	*/
}

if(!(getCookieVal('MinBuzaFontSize') == '')){
	fontWissel(getCookieVal('MinBuzaFontSize'));
}
