$(document).ready(function() {
	
	var options = { min: -2, max: 15};
	var c = readCookie('style');
	$.FontSizer.Init(options);
	if (c) switchStylestyle(c);
	
	$("#styleSwitcher").css("display","block");
	
	//$("#close").click(function(){$("#styleSwitcher").animate({right: -250});});
	
	$("#fontInc").click(function(){$.FontSizer.IncreaseSize();return false;});
	$("#fontRes").click(function(){$.FontSizer.Reset();return false;});
	$("#fontDec").click(function(){$.FontSizer.DecreaseSize();return false;});
	
	$('.style').click(function() { switchStylestyle(this.getAttribute("rel")); return false; });
	
	
	
});
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);
}
function switchStylestyle(styleName) {
        $('link[@rel*=style][@title]').each(function(i) {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });
        createCookie('style', styleName, 365);
}
/**
* Purpose:              Font sizer class, handles increasing and decreasing font size of a page.
* Author:               Stefan Sedich (stefan.sedich@gmail.com
*/
$.FontSizer = {
        level: 0,
        options : {            
                min: -3,
                max: 5
        },
        Init : function(options) {
                if(options)
		    $.FontSizer.options = $.extend($.FontSizer.options, options);
                var level = (readCookie('fontLevel') != null) ? readCookie('fontLevel') : 0;                      
                $.FontSizer.SetSize(level);
        },
        IncreaseSize : function() {
                if(($.FontSizer.level) + 1 <= $.FontSizer.options.max) {            
                        var next = (parseInt($.FontSizer.level) + 1);
                        $.FontSizer.SetSize(next);  
                }
        },
        DecreaseSize : function() {
                if(($.FontSizer.level - 1) >= $.FontSizer.options.min) {
                        var next = (parseInt($.FontSizer.level) - 1);
                        $.FontSizer.SetSize(next);  
                }      
        },      
        SetSize: function(level) {
                $.FontSizer.level = level;      
                createCookie('fontLevel', level, 365);
                var level = (level / 10) + 1;
                $("#wrapper").css("fontSize", level+"em");    
        },
        Reset: function() {
            $.FontSizer.SetSize(0);
        }
}; 