// --------------------------------------------------------------
function Cookie(name) {
    this.name = name;
    this.value = loadCookieData(name);
    this.expires = new Date().getTime();
    this.domain = null;
    this.path = null;
}
// Setzen des Verfallsdatums
Cookie.prototype.setExpires = function(timestamp) {
    this.expires = timestamp;
}

// Setzen des Pfades
Cookie.prototype.setPath = function(path) {
    this.path = path;
}

// Setzen der Domain
Cookie.prototype.setDomain = function(domain) {
    this.domain = domain;
}

// Auslesen des Wertes
Cookie.prototype.getValue = function() {
    return this.value;
}

// Liefert die Wertezeichenkette des Cookies
Cookie.prototype.getParamString = function() {
    return this.paramString;
}

// Die Wertezeichenkette speichern
Cookie.prototype.setValue = function(value) {
    this.value = value;
}

// Cookie entfernen
Cookie.prototype.remove = function() {
    this.expires = new Date().getTime();
    this.data = new CookieData();
    this.send();
}

// Setzen des Cookies im Browser
Cookie.prototype.send = function() {
    document.cookie = this.name + "=" + escape(this.value) + "; expires=" + new Date(this.expires).toGMTString() + (this.path ? "; path=" + this.path : "") + (this.domain ? "; domain=" + this.domain : "");
}

function loadCookieData(cookieName) {
    var a = document.cookie.split("; ");
    for (var i = 0; i < a.length; i++) {
        var kv = a[i].split('=');
        if (kv[0] == cookieName) {
            return unescape(kv[1]);
        }
    }
    return null;
}


var eonStyle = new Cookie("eonStyle");
var ergFontClass = "sizesmall";
var eonUpshrink = new Cookie("eonUpshrink")
var ergUpshrink = "open";

function SetFontSize(){
    ergFontClass = eonStyle.getValue();
    var ergFontSize;
    switch (ergFontClass) {
        case "sizesmall":
            ergFontClass = "font_small";
            ergFontSize = '16px';
            break;
        case "sizemedium":
            ergFontClass = "font_medium";
            ergFontSize = '18px';
            break;
        case "sizelarge":
            ergFontClass = "font_big";
            ergFontSize = '20px';
            break;
        default:
            if (ergFontClass == null) {
                ergFontClass = "font_small";
                ergFontSize = '16px';
            } else if (ergFontClass.indexOf("font_medium") >= 0) {
                ergFontClass = "font_medium";
                ergFontSize = '18px';
            } else if (ergFontClass.indexOf("font_big") >= 0) {
                ergFontClass = "font_big";
                ergFontSize = '20px';
            } else {
                ergFontClass = "font_small";
            }
            writeCookie();
            break;
    }
    SetActiveLink(ergFontClass);
    document.body.style.fontSize = ergFontSize;
    document.body.className = ergFontClass;
}

function writeCookie() {
    var lifetime = 1000 * 60 * 60 * 24 * 365;
    var now = new Date();
    eonStyle.setExpires(new Date(now.getTime() + lifetime).toGMTString());
    eonStyle.setPath("/");
    eonStyle.setValue(ergFontClass);
    eonStyle.send();
    eonUpshrink.setExpires(new Date(now.getTime() + lifetime).toGMTString());
    eonUpshrink.setPath("/");
    eonUpshrink.setValue(ergUpshrink)
    eonUpshrink.send();
}

function SwitchFontSize(fontSize, fontClass) {
    return SetFontClass(fontClass);
}

function SetFontClass(fontClass){
	if (i_Global_fontsize == fontClass){
		return;
	}
    var ergFontSize;
    switch (fontClass) {
        case "font_small":
            ergFontClass = "font_small";
            //ergFontSize = '16px';
			ergFontSize = '1em';
            break;
        case "font_medium":
            ergFontClass = "font_medium";
            //ergFontSize = '18px';
			ergFontSize = '1.125em';
            break;
        case "font_big":
            ergFontClass = "font_big";
            //ergFontSize = '20px';
			ergFontSize = '1.25em';
            break;
        default:
            ergFontClass = "font_small";
            //ergFontSize = '16px';
			ergFontSize = '1em';
            break;
    }
	$('a').each(
		function(){
			var aa = $(this);
			if (aa.attr('label_a') == 'no'){
			} else {
				if ( aa.attr('href') )
					aa.attr('href',aa.attr('href').replace('?fontsize='+i_Global_fontsize,'?fontsize='+fontClass));
			}
		}
	);
	i_Global_fontsize = fontClass;
	$('#font_span').find('img').each(
		function(){
			var img = $(this);
			if (img.attr('id') == i_Global_fontsize){
				img.attr('src',img.attr('src').replace('.','_act.'));
			} else {
				img.attr('src',img.attr('src').replace('_act.','.'));
			}
		}
	);	
    document.body.style.fontSize = ergFontSize;
    document.body.className = ergFontClass;
}

function SetActiveLink(ergFontClass) {
    $('#font_span').find('img').each(
		function(){
			var img = $(this);
			if (img.attr('id') == ergFontClass){
				img.attr('src',img.attr('src').replace('.','_act.'));
			} else {
				img.attr('src',img.attr('src').replace('_act.','.'));
			}
		}
	);
}