﻿/*	------------------------------------------------------------------
	Plugin/Cookie
	http://www.stilbuero.de/2006/09/17/cookie-plugin-for-jquery/
	------------------------------------------------------------------ */	
	jQuery.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			// CAUTION: Needed to parenthesize options.path and options.domain
			// in the following expressions, otherwise they evaluate to undefined
			// in the packed version for some reason...
			var path = options.path ? '; path=' + (options.path) : '';
			var domain = options.domain ? '; domain=' + (options.domain) : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	};
	
/*	------------------------------------------------------------------
	Plugin/Ability
	http://code.google.com/p/ability/
	------------------------------------------------------------------ */	
	(function($) {
		function switchTextSize(size, settings) {
			
			if(size != ''){
				$('#content-container').removeClass().addClass(size);
						
				if (settings.saveCookie == true){
					$.cookie('textsize', size, { expires: 365, path: '/'  });
				}
			}
		}
	
		$.fn.extend({
			switchSize: function(settings) {
				var version = "0.11";
				/* Default Settings*/	
				settings = $.extend({
					saveCookie: true
				},settings);
			
				return this.each(function(){
					controlbox = this;
					
					var output = '';
					var curtextsize = $.cookie('textsize');
					
					if (curtextsize) { $('#content-container').removeClass().addClass(curtextsize); }
					output = '<div id="fontnav"><a href="#" id="b_font_small" title="Small">Small</a><a href="#" id="b_font_medium" title="Medium">Medium</a><a href="#" id="b_font_large" title="Large">Large</a></div>';
					
					$(controlbox).prepend(output);
												
					$('#fontnav a', controlbox).bind('click', function(){
						
						switchTextSize( $(this).attr("id").split("_")[2], settings);	
											
						return false;
					});
				});
			}
		});
	})(jQuery);
