
(function($){
	$.cookie = function(key, value, options) {
		if(arguments.length > 1) {
			var o = $.extend({}, $.cookieOptions, options);
	        if (value === null || value === undefined) {
	            value = '';
	            o.expires = -1;
	        }
	        if (o.expires.constructor != Date) {
				var today = new Date();
				today.setDate(today.getDate() + o.expires);
				o.expires = today;
			}
			// Create the cookie string
			document.cookie = 
				key + '=' + value +
				'; expires=' + o.expires.toUTCString() +
				(o.path? '; path=' + (o.path) : '') +
				(o.domain? '; domain=' + (o.domain) : '') +
				(o.secure? '; secure' : '');
		} else {
			if(result = new RegExp(key+"=(.*?)(?:;|$)").exec(document.cookie))
				return decodeURIComponent(result[1]);
			return false;
		}
	};
	$.cookieOptions = {
		expires: 365,
		path: '/'
	}
})(jQuery);

var sitefunctions =
{
	textresize : function()
	{
		var cookie_name = "abschiedsvorstellung-fontsize";
		var originalFontSize = jQuery("html").css("font-size");
		
		jQuery("#fontsizeswitcher").show();
		
		// if exists load saved value, otherwise store it
		if(jQuery.cookie(cookie_name))
		{
			var getSize = jQuery.cookie(cookie_name);
			//jQuery("html").css({fontSize : getSize + (getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
		}
		else
		{
			jQuery.cookie(cookie_name, originalFontSize);
		}
		// reset link
		jQuery("#fontsize_reset").bind("click", function()
		{
			jQuery("html").css("font-size", originalFontSize);
			jQuery.cookie(cookie_name, originalFontSize);
		});
		
		// text "+" link
		jQuery("#fontsize_inc").bind("click", function()
		{
			var currentFontSize = jQuery("html").css("font-size");
			var currentFontSizeNum = parseFloat(currentFontSize);
			var newFontSize = currentFontSizeNum*1.2;
			
			jQuery("html").css("font-size", newFontSize);
			jQuery.cookie(cookie_name, newFontSize);
			
			return false;
		});
		
		// text "-" link
		jQuery("#fontsize_dec").bind("click", function()
		{
			var currentFontSize = jQuery("html").css("font-size");
			var currentFontSizeNum = parseFloat(currentFontSize);
			var newFontSize = currentFontSizeNum*0.8;
			
			jQuery("html").css("font-size", newFontSize);
			jQuery.cookie(cookie_name, newFontSize);
			
			return false;
		});
	}
};

jQuery( document ).ready( function(){
	sitefunctions.textresize();	
});
