///////////////////////////////////////////////////////////////////////////////
//	ZoomString.class.js
//		文字サイズ変更処理クラス
//			Copyright (c) 2009 mochiZ.
//
//	author: mochiZ.
//	create: 2009/03/09
///////////////////////////////////////////////////////////////////////////////


//=============================================================================
// class ZoomString
//=============================================================================

//*****************************************************
// コンストラクタ
//		id  : ベースとなるタグのID名
//		step: 拡大率(%)
//		min : 倍率最小(%)[option]
//		max : 倍率最大(%)[option]
//*****************************************************
function ZoomString(id, step, min, max)
{
	this.id = id;
	this.step = step;
	this.min = min;
	this.max = max;
	
	this.obj = this.getObj(id);		// エレメントのオブジェクト
	this.mag;						// 現在の倍率(%)

	if(!this.obj){
		alert("ZoomString :: Not found : " + id);
		return;
	}
	
	// ID名をプレフィックスにクッキーから読み込む
	m = parseInt(this.getCookie(id + "_mag"));
//	alert("m : " + m);
	this.mag = m ? m : 100;
	this.zoom();
}

//*****************************************************
// 標準
//*****************************************************
ZoomString.prototype.normal = function()
{
	this.mag = 100;

	this.zoom();
}

//*****************************************************
// 拡大
//*****************************************************
ZoomString.prototype.zoomIn = function()
{
	this.mag += this.step;
	
	if(this.max && this.mag > this.max) this.mag -= this.step;
	
	this.zoom();
}

//*****************************************************
// 縮小
//*****************************************************
ZoomString.prototype.zoomOut = function()
{
	this.mag -= this.step;
	
	if(this.min && this.mag < this.mim) this.mag += this.step;
	else if(this.mag < this.step) this.mag = this.step;
	
	this.zoom();
}

//*****************************************************
// 表示処理
//*****************************************************
/*private*/
ZoomString.prototype.zoom = function()
{
	// ID名をプレフィックスにクッキーに書き込む
	this.setCookie(this.id + "_mag", this.mag);
	this.obj.style.fontSize = this.mag + "%";
}

//*****************************************************
// オブジェクト取得
//*****************************************************
/*private*/
ZoomString.prototype.getObj = function(name)
{
	if(document.getElementById){
		return document.getElementById(name);
	}else if(document.all){
		return document.all(name);
	}else if(document.layers){
		return document.layers[layName];
	}
	return null;
}

//*************************
// クッキー設定
//*************************
/*private*/
ZoomString.prototype.setCookie = function(name, val, yy, mm, dd)
{
	// デフォルトは3000年1月1日
	yy = (yy) ? yy : 3000;
	mm = (mm) ? mm - 1 : 1;
	dd = (dd) ? dd : 1;
	var exp = new Date(yy, mm, dd);
	document.cookie = name + "=" + escape(val) + "; path=/; expires=" + exp.toGMTString();
}

//*************************
// クッキー取得
//*************************
/*private*/
ZoomString.prototype.getCookie = function(name)
{
	var search = name + "=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if(offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if(end == -1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return "";
}



//*************************
// HTMLエレメント作成
//*************************
/*static*/
ZoomString.makeHTML = function(id, inst)
{
	
}
