/**
* Purpose:              Font sizer class, handles increasing and decreasing font size of a page.
*                       It increases the font in 10% increments. By getting the level / 10 + 1.
*                       i.e. level 2 is .2 + 1 so 1.2 or 120%.
*
* Requires:             JQuery and the JQuery cookies plugin.
*
* Use:                  Setup the fontsizer $.FontSizer.Init(options); the two options are
*                       min and max, for the min level and max level.
*                       Defaults are min: -3 and max: 5.
*
* Previous Author/s:    Stefan Sedich (stefan.sedich@gmail.com)
* Current Author:       Jason Fowler (jason@sixthdaydesign.com)
*/

function debug(aMsg) {
	setTimeout(function() { throw new Error("[debug] " + aMsg); }, 0);
}
$.FontSizer = {

        level: 0,

        options : {            
                min: 0,
                max: 5
        },

        Init : function(options) {
	        if(options)
		    $.FontSizer.options = $.extend($.FontSizer.options, options);
                var level = ($.cookie('font_level') != null) ? $.cookie('font_level') : 0;                      
                $.FontSizer.SetSize(0);

        },

        IncreaseSize : function() {

                if(($.FontSizer.level) + 1 <= $.FontSizer.options.max) {            
                        //If we have not exceded the max level,
                        //Get the next level and the set the size to this level.
                        var next = (parseInt($.FontSizer.level) + 1);
                        $.FontSizer.SetSize(next);  
                }

        },

        DecreaseSize : function() {
                if(($.FontSizer.level - 1) >= $.FontSizer.options.min) {
                        //If we have not exceded the min level,
                        //Get the next level and the set the size to this level.
                        var next = (parseInt($.FontSizer.level) - 1);
                        $.FontSizer.SetSize(next);  
                }      
        },      

        SetSize: function(level) {

                //Set the current level in the member variable and the cookie.
                $.FontSizer.level = level;      
                $.cookie('font_level', level);

                //Work out the new em value and set it.
                var base = level / 10;
                var base2 = level / 10;
                var base3 = level / 10;
                var header = (base * 2) + 1.6;
                var level = (level / 10) + .6;
                var extra = (base2) + .9;
                var extra2 = (base3) + .9;
                $("td").css("fontSize", header+"em").end();
                $("td").children("ul").children("li").css("fontSize", level+"em").end();    
                $("td").children("ol").children("li").css("fontSize", level+"em").end();
                $("td").children("ol").children("li").children("ul").children("li").css("fontSize", extra+"em").end();
                $("td").children("p").css("fontSize", level+"em").end();
                $(".testblock").children("p").css("fontSize", extra2+"em").end();
        				$(".textblock").children("a").css("fontSize", level+"em").end();
         				$(".titleblock").css("fontSize", level+"em").end();
                console.log(extra2 + " and " + level);

        },

        Reset: function() {
            
            //Reset the level back to 0
            $.FontSizer.SetSize(0);
        
        }

}; 