/**
 * jquery.scaleFont2.js 0.1 フォントサイズ操作
 *
 * SYNOPSIS
 *
 * var instance = $('#target').scaleFont();
 * instance.scale(22); // 22em
 * instance.unscale();
 *
 * history
 * : 2010-12-04 ver0.1 - Initial release
 *
 * Copyright (c) 2010 Cutout Inc.
 */
;(function($) {

    /**
     * プラグインの名称
     */
    var plugname = 'scaleFont';

    /**
     * 全プラグイン共通のインナークラスコンストラクタ
     */
    var Class = function(elem, params){
        this.elem = elem;
        this.elem.data(plugname, this);
        this.params = params;
    };

    /**
     * メソッドを定義
     */
	Class.prototype.scale = function(em) {
		this.elem.each(function(){
			if (! $(this).data('org.scaleFont')) {
				var fontSizeOrg = $(this).css("fontSize");
				if (! fontSizeOrg.match('px')) {
					// for ie issue
					$(this).css("fontSize", '1em');
					fontSizeOrg = $(this).css("fontSize");
				}
				var fontSizeOrg = fontSizeOrg.replace(/px/,"");
				$(this).data('org.scaleFont', fontSizeOrg);
			}
			var newSize = $(this).data('org.scaleFont') * em;
			$(this).css("fontSize", newSize + "px");
		});
		return this;
	};
	
	Class.prototype.unscale = function() {
		this.elem.each(function(){
			if ($(this).data('org.scaleFont')) {
				var newSize = $(this).data('org.scaleFont');
				$(this).css("fontSize", newSize + "px");
			}
		});
		return this;
	};

    /**
     * デフォルトパラメータ
     */
    var default_params = {
		className : 'scaleFont'
    };

    /**
     * 全プラグイン共通
     */
    $.fn[plugname] = function(params){
        return new Class(this, $.extend(default_params, params, {}));
    }
})(jQuery);

