﻿/* switch textsize-stylesheets */

(function($){ 
     $.fn.extend({  
         sizeswitch: function(options) {       
            $.fn.sizeswitch.defaults = {
					switch_link_selector: '.sizeswitch',
					cookie_name: 'fontsize',
					cookie_expires: 10
			};
			
			// build main options before element iteration
			var opts = $.extend({}, $.fn.sizeswitch.defaults, options);
			
			return this.each(function() {
			
				var $this = $(this);
			
				sizeInit();	
	
				$this.find(opts.switch_link_selector).click(function(e){	

					$(opts.switch_link_selector).removeClass('active-util');					
					var size = this.getAttribute('rel');					
					switchSize(size);
					$(this).addClass('active-util');
					
					return false;
				});
				
				function sizeInit() {			
					var c = $.cookie(opts.cookie_name);					
					if (c) {						
						switchSize(c);						
						$(opts.switch_link_selector).removeClass('active-util');	
						$(opts.switch_link_selector).each(
							function() {
								if(this.getAttribute('rel') == c)
									$(this).addClass('active-util');								
							}
						);						
					}
					
				}
				
				function switchSize(size){
					$('link[@rel*=style][title]').each(
						function(i) 
						{
							this.disabled = true;
							if (this.getAttribute('title') == size) {							
								this.disabled = false;							
							}
						}
					);
					$.cookie(opts.cookie_name, size, { expires: opts.cookie_expires });
				}	
				
            });
        } 
    }); 
})(jQuery);





















