﻿/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 ************************************************************************************************
 *
 *	Copyright (c) 2009, Arno Dudek (http://www.adgrafik.at, office@adgrafik.at)
 *
 *	@copyright	Copyright (c) 2009, Arno Dudek
 *
 ************************************************************************************************
 ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


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 + '=' + escape(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 unescape(c.substring(nameEQ.length,c.length));
        }
    }
    return null;
};

var FontSizer = {
	fontSize: 100,

	initialize: function () {
		var style = readCookie('FontSizer');
		this.setStyleSheet({title: style}, true);
	},

	setStyleSheet: function(target, nocookie) {
		if (!this.checkCompatibility()) return false;
		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') == target.title) {
					a.disabled = false;
				}
			}
		}
		if (!nocookie) {
			createCookie('FontSizer', target.title)
		}
	},

	checkCompatibility: function () {
		return (!(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1) && document.getElementsByTagName && document.createElement);
	}
};

var old = window.onload; window.onload = function() { if (old) old(); FontSizer.initialize(); } 

