/*
 * jQuery WG TextResize plug-in 1.0
 * Copyright (c) 2008 Roberto Lee (webgenerator.nl)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 2009-11-02
 * Rev: 1
 */
 (function($){
     $.fn.extend({
         WG_TextResize: function(options) {
	        var defaults = {
	        	original_elem_font_css:'',//the html element using the start font size
	        	apply_css_to_elem:'',//the html element using the start font size
				originalsize: 0, //overwrite original size
				newsize_in_px: 0, //the new size to use, this will be used before percentage
				newsize_in_percent: 0, //the new size to use (increasing percentage of original size)
				cb: function(){}
	        };
	        var options = $.extend(defaults, options);

            return $(this).each(function(idx) {// Don't break the chain
				if($(this).is('*'))
				{
					$(this).click(function(){
						options.originalsize = options.originalsize > 0 ? options.originalsize : $(options.original_elem_font_css).css('font-size');
						options.originalsize = parseFloat(options.originalsize);

						var newsize = 0;
						if((options.newsize_in_percent != 0) && (options.newsize_in_px == 0))
						{
							options.newsize_in_px = options.originalsize * ((100 + options.newsize_in_percent)/100);
						}

						$.WG_ApplyTextCSS(options);

						//Cookie the choice
						//$.cookie("textresize_applied_options", options.toSource());
						$.cookie("textresize_applied_options", $.toJSON(options), { path: '/' });

						options.cb.call();
					});
				}
            });

		}
    });
})(jQuery);


(function($) {
   jQuery.WG_ApplyTextCSS = function(options) {
		var newCss = {
			'font-size': options.newsize_in_px + 'px',
			'line-height': (options.newsize_in_px + 2) + 'px'
		}
		$(options.apply_css_to_elem).css(newCss);
   }
})(jQuery);

(function($) {

   $.fn.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
      return this;
   }
})(jQuery);

jQuery.log = function(msg) {
      if (typeof (console) == "undefined") {
         console = { log: function() { } };
      }
      if (console) {
         console.log("%s: %o", msg, this);
      }
};
