var perc = 10;
var times = 0;
var max_up = 6;
var max_down = 3;
var l_sign = "";

function fontsizeup(homepage) {
	if (homepage) {
		setChangeFont("box_about","+",perc,false);
		setChangeFont("rightmain","+",perc,false);
	}
	else {
		setChangeFont("textinside","+",perc,false);
	}
	times++;
}

function fontsizedown(homepage) {
	if (homepage) {
		setChangeFont("box_about","-",perc,false);
		setChangeFont("rightmain","-",perc,false);
	}
	else {
		setChangeFont("textinside","-",perc,false);
	}
	times--;
}

function getStyle(obj, cAttribute) {
    if (obj.currentStyle) {
        this.getstyle = function (obj, cAttribute) {return obj.currentStyle[cAttribute];};
    } else {
        this.getstyle = function (obj, cAttribute) {return document.defaultView.getComputedStyle(obj, null)[cAttribute];};
    }
    return getstyle(obj, cAttribute);
}


function setChangeFont(parent,sign,num,initial){
	if ((times==-max_down && sign=='-') || (times==max_up && sign=='+'))
	{
		return false;
	}


	var page=document.getElementById(parent);
	var allEls = page.getElementsByTagName('*');
	
	for (j=0; j<allEls.length; j++)
	{
		//alert(j);
		//alert(allEls[j].nodeName+' , '+getStyle(allEls[j],'lineHeight'));
		//alert(allEls[j].style['fontSize']);
		if (getStyle(allEls[j],'fontSize'))
		{
			var cur_size = parseFloat(getStyle(allEls[j],'fontSize'));
			if (l_sign!="" && l_sign!=sign){
				var new_size = (sign=="+") ? cur_size/(1-(num/100)) : cur_size/(1+(num/100));
			}
			else {
				var increment = (cur_size/100) * num;
				var new_size = (sign=='+') ? cur_size + increment : cur_size - increment;
			}

			allEls[j].style.fontSize = Math.round(new_size) < 0 ? "1px" : Math.round(new_size)+"px";

		}
		
		if (getStyle(allEls[j],'lineHeight'))
		{
			var cur_size = parseFloat(getStyle(allEls[j],'lineHeight'));
			if (l_sign!="" && l_sign!=sign){
				var new_size = (sign=="+") ? cur_size/(1-(num/100)) : cur_size/(1+(num/100));
			}
			else {
				var increment = (cur_size/100) * num;
				var new_size = (sign=='+') ? cur_size + increment : cur_size - increment;
			}

			allEls[j].style.lineHeight = Math.round(new_size) < 0 ? "1px" : Math.round(new_size)+"px";

		}


		if (allEls[j].nodeName=='FONT')
		{
			if (!isNaN(allEls[j].size)&&allEls[j].size!='')
			{
				var cur_size = parseFloat(allEls[j].size);
				if (l_sign!="" && l_sign!=sign){
					var new_size = (sign=="+") ? Math.ceil(cur_size/(1-(num/100))) : Math.floor(cur_size/(1+(num/100)));
				}
				else {
					var increment = (cur_size/100) * num;
					if (increment<1) { increment = 1; }
					var new_size = (sign=='+') ? cur_size + increment : cur_size - increment;
				}

				allEls[j].size = Math.round(new_size) < 0 ? 1 : Math.round(new_size);

			}
		}
	}
	
	
	//if (sign=='+') { times++; } else { times--; }

	if (!initial)
	{
		tot_sign = times < 0 ? '-' : '+';
		l_sign = times == 0 ? "" : tot_sign;
		cook_data = tot_sign+"|"+Math.abs(times);
	}

}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
}

window.onunload = function(e) {
	tot_sign = times < 0 ? '-' : '+';
	cook_data = tot_sign+"|"+Math.abs(times);
	createCookie("style", cook_data, 365);
}
