/*------------------------------------------------------------------
[ Evident jQuery Library ]

Plug-in name:	fontSizer
Purpose:		Resize page font
Usage:   
Version:		1.0
Last change:	11/02/09 (mb)
Assigned to:	Marc Bruisten (mb)
--------------------------------------------------------------------*/

(function($) {
    $.fn.fontSizer = function(step1, step2, step3) {
        var fontSizerId = ['fs_normal', 'fs_medium', 'fs_large', 'fs_decrease', 'fs_increase']
        var fontSizerTitle = ['normaal', 'middel-groot', 'extra-groot']
        var interval = [step1, step2, step3]

        var fontSizeLinks = $(document.createElement('li'))
			.attr('id', 'ctrlPanelFontSize')
			.append($(document.createTextNode('Tekstgrootte:')))
			.append(
				newfontSizer(0),
				newfontSizer(1),
				newfontSizer(2)
			);
        $(this).prepend(fontSizeLinks);

        function newfontSizer(i) {
            return $(document.createElement('a'))
				.attr('href', 'javascript:void(0)')
				.addClass('fontsizer')
				.attr('id', fontSizerId[i])
				.attr('title', fontSizerTitle[i])
				.append($(document.createTextNode('A')))
					.bind("click", function(e) {
					    changeFontSize(i);
					});
        }

        function changeFontSize(i) {
            i = i * 1;
            $(document.body).css('font-size', interval[i] + '%');
            $(fontSizeLinks).contents('a').removeClass("selected");
            var target = $(fontSizeLinks).contents('a')[i];
            $(target).addClass("selected");
            createCookie('fontsize', (i));
        }

        var cookievalue = readCookie('fontsize')
        if (cookievalue != 'undefined') {
            changeFontSize(cookievalue * 1);
        }

        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 var 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);
            }
            return null;
        }

        function eraseCookie(name) {
            createCookie(name, "", -1);
        }

    };
})(jQuery);

